Skip to content

Commit

Permalink
disable logical subscription before deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Nov 21, 2024
1 parent 0d1940d commit 3007617
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion model/lantern/lantern_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,18 @@ def create_and_enable_subscription
end

def delete_logical_subscription(name)
representative_server.run_query_all("DROP SUBSCRIPTION IF EXISTS #{name}")
commands = <<SQL
DO $$
BEGIN
IF EXISTS (SELECT FROM pg_subscription WHERE subname='#{name}') THEN
ALTER SUBSCRIPTION #{name} DISABLE;
ALTER SUBSCRIPTION #{name} SET (slot_name=NONE);
DROP SUBSCRIPTION #{name};
END IF;
END
$$;
SQL
representative_server.run_query_all(commands)
end

def mark_switchover_start
Expand Down
4 changes: 2 additions & 2 deletions spec/model/lantern/lantern_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
it "drops subscription" do
representative_server = instance_double(LanternServer)
expect(lantern_resource).to receive(:representative_server).and_return(representative_server).at_least(:once)
expect(lantern_resource.representative_server).to receive(:run_query_all).with("DROP SUBSCRIPTION IF EXISTS test")
expect(lantern_resource.representative_server).to receive(:run_query_all).with(a_string_matching(/DROP SUBSCRIPTION test/m))
expect { lantern_resource.delete_logical_subscription("test") }.not_to raise_error
end
end
Expand Down Expand Up @@ -286,7 +286,7 @@
logical_replication: true,
lantern_version: representative_server.lantern_version,
extras_version: representative_server.extras_version,
minor_version: representative_server.minor_version,
minor_version: representative_server.minor_version
))
expect { lantern_resource.create_logical_replica }.not_to raise_error
end
Expand Down

0 comments on commit 3007617

Please sign in to comment.