Skip to content

Commit 559a939

Browse files
authored
Ensure default for recreate_indices_post_copy is always false (match cli default) (#190)
* Ensure default for recreate_indices_post_copy is always false (match cli default) This way we don't attempt to recreate indices post switchover (no-op anyways) * Relax check
1 parent c670410 commit 559a939

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

lib/pg_easy_replicate/group.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def setup
2020
column(:updated_at, Time, default: Sequel::CURRENT_TIMESTAMP)
2121
column(:started_at, Time)
2222
column(:failed_at, Time)
23-
column(:recreate_indices_post_copy, TrueClass, default: true)
23+
column(:recreate_indices_post_copy, TrueClass, default: false)
2424
column(:switchover_completed_at, Time)
2525
end
2626
ensure
@@ -44,6 +44,7 @@ def create(options)
4444
schema_name: options[:schema_name],
4545
started_at: options[:started_at],
4646
failed_at: options[:failed_at],
47+
recreate_indices_post_copy: options[:recreate_indices_post_copy],
4748
)
4849
rescue => e
4950
abort_with("Adding group entry failed: #{e.message}")

spec/pg_easy_replicate/group_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@
118118
schema: PgEasyReplicate.internal_schema_name,
119119
)
120120
expect(r.first[:name]).to eq("test")
121+
expect(r.first[:recreate_indices_post_copy]).to be_nil
122+
end
123+
124+
it "adds a row with recreate_indices_post_copy" do
125+
described_class.create({ name: "test", recreate_indices_post_copy: true })
126+
127+
r =
128+
PgEasyReplicate::Query.run(
129+
query: "select * from groups",
130+
connection_url: connection_url,
131+
schema: PgEasyReplicate.internal_schema_name,
132+
)
133+
expect(r.first[:recreate_indices_post_copy]).to be(true)
121134
end
122135

123136
it "adds a row with table names and schema" do

spec/pg_easy_replicate/orchestrate_spec.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@
276276
described_class.start_sync(
277277
group_name: "cluster1",
278278
schema_name: test_schema,
279-
recreate_indices_post_copy: true,
279+
recreate_indices_post_copy: false,
280280
)
281281

282282
expect(pg_publications(connection_url: connection_url)).to eq(
@@ -304,7 +304,7 @@
304304
updated_at: kind_of(Time),
305305
failed_at: nil,
306306
table_names: "items,sellers",
307-
recreate_indices_post_copy: true,
307+
recreate_indices_post_copy: false,
308308
)
309309
end
310310

@@ -318,7 +318,7 @@
318318
described_class.start_sync(
319319
group_name: "cluster1",
320320
schema_name: test_schema,
321-
recreate_indices_post_copy: true,
321+
recreate_indices_post_copy: false,
322322
)
323323
end.to raise_error(RuntimeError, "Starting sync failed: boo")
324324

@@ -339,7 +339,7 @@
339339
PgEasyReplicate::Orchestrate.start_sync(
340340
group_name: "cluster1",
341341
schema_name: test_schema,
342-
recreate_indices_post_copy: true,
342+
recreate_indices_post_copy: false,
343343
)
344344
end
345345

@@ -426,7 +426,7 @@
426426
described_class.start_sync(
427427
group_name: "cluster1",
428428
schema_name: test_schema,
429-
recreate_indices_post_copy: true,
429+
recreate_indices_post_copy: false,
430430
)
431431

432432
expect(PgEasyReplicate::Group.find("cluster1")).to include(
@@ -439,7 +439,7 @@
439439
updated_at: kind_of(Time),
440440
failed_at: nil,
441441
table_names: "items,sellers",
442-
recreate_indices_post_copy: true,
442+
recreate_indices_post_copy: false,
443443
)
444444

445445
conn1[:items].insert(name: "Foo2")
@@ -559,7 +559,7 @@
559559
described_class.start_sync(
560560
group_name: "cluster1",
561561
schema_name: test_schema,
562-
recreate_indices_post_copy: true,
562+
recreate_indices_post_copy: false,
563563
)
564564

565565
conn1[:items].insert(name: "Foo2")
@@ -609,7 +609,7 @@
609609
group_name: "cluster1",
610610
schema_name: test_schema,
611611
exclude_tables: ["sellers"],
612-
recreate_indices_post_copy: true,
612+
recreate_indices_post_copy: false,
613613
)
614614

615615
expect(PgEasyReplicate::Group.find("cluster1")).to include(
@@ -622,7 +622,7 @@
622622
updated_at: kind_of(Time),
623623
failed_at: nil,
624624
table_names: "items",
625-
recreate_indices_post_copy: true,
625+
recreate_indices_post_copy: false,
626626
)
627627

628628
conn1[:items].insert(name: "Foo2")
@@ -726,7 +726,7 @@
726726
described_class.start_sync(
727727
group_name: "cluster1",
728728
schema_name: test_schema,
729-
recreate_indices_post_copy: true,
729+
recreate_indices_post_copy: false,
730730
)
731731

732732
allow(described_class).to receive(:drop_subscription).and_raise(
@@ -795,7 +795,7 @@
795795
ENV["TARGET_DB_URL"] = target_connection_url
796796
end
797797

798-
it "succesfully raises lack of super user error" do
798+
it "successfully raises lack of super user error" do
799799
conn1 =
800800
PgEasyReplicate::Query.connect(
801801
connection_url: connection_url("james-bond_role_regular"),
@@ -822,9 +822,9 @@
822822
described_class.start_sync(
823823
group_name: "cluster1",
824824
schema_name: test_schema,
825-
recreate_indices_post_copy: true,
825+
recreate_indices_post_copy: false,
826826
)
827-
end.to raise_error(/Starting sync failed: PG::InsufficientPrivilege/)
827+
end.to raise_error(/PG::InsufficientPrivilege/)
828828

829829
# expect(PgEasyReplicate::Group.find("cluster1")).to include(
830830
# switchover_completed_at: nil,
@@ -904,7 +904,7 @@
904904
described_class.start_sync(
905905
group_name: "cluster1",
906906
schema_name: test_schema,
907-
recreate_indices_post_copy: true,
907+
recreate_indices_post_copy: false,
908908
exclude_tables: ["items"],
909909
)
910910

@@ -931,7 +931,7 @@
931931
described_class.start_sync(
932932
group_name: "cluster1",
933933
schema_name: test_schema,
934-
recreate_indices_post_copy: true,
934+
recreate_indices_post_copy: false,
935935
)
936936

937937
expect(PgEasyReplicate::Group.find("cluster1")).to include(

0 commit comments

Comments
 (0)