Skip to content

Commit

Permalink
fix ddl log trigger to work with replica events
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Jun 21, 2024
1 parent c079729 commit cdf99d4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion model/lantern/lantern_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def create_ddl_log
def listen_ddl_log
commands = <<SQL
DROP EVENT TRIGGER IF EXISTS log_ddl_trigger;
TRUNCATE TABLE ddl_log RESTART IDENTITY;
CREATE OR REPLACE FUNCTION execute_ddl_command()
RETURNS TRIGGER AS $$
BEGIN
Expand All @@ -138,6 +139,7 @@ def listen_ddl_log
AFTER INSERT ON ddl_log
FOR EACH ROW
EXECUTE FUNCTION execute_ddl_command();
ALTER TABLE ddl_log ENABLE REPLICA TRIGGER execute_ddl_after_insert;
SQL
representative_server.run_query_all(commands)
end
Expand All @@ -155,6 +157,7 @@ def create_and_enable_subscription
WITH (
copy_data = false,
create_slot = false,
binary = true,
enabled = true,
synchronous_commit = false,
connect = true,
Expand All @@ -171,8 +174,8 @@ def disable_logical_subscription

def create_logical_replica(lantern_version: nil, extras_version: nil, minor_version: nil)
ubid = LanternResource.generate_ubid
create_publication("pub_#{ubid}")
create_ddl_log
create_publication("pub_#{ubid}")
slot_lsn = create_replication_slot("slot_#{ubid}")
Prog::Lantern::LanternResourceNexus.assemble(
project_id: project_id,
Expand Down

0 comments on commit cdf99d4

Please sign in to comment.