Skip to content

Commit

Permalink
fix permission issues when replicating ddl commands
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Nov 19, 2024
1 parent 99d1bb3 commit c5bc950
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions model/lantern/lantern_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ def create_ddl_log
id SERIAL PRIMARY KEY,
object_tag TEXT,
ddl_command TEXT,
timestamp TIMESTAMP
timestamp TIMESTAMP,
"session_user" TEXT
);
CREATE OR REPLACE FUNCTION log_ddl_changes()
RETURNS event_trigger AS $$
BEGIN
INSERT INTO ddl_log (object_tag, ddl_command, timestamp)
VALUES (tg_tag, current_query(), current_timestamp);
INSERT INTO ddl_log (object_tag, ddl_command, timestamp, "session_user")
VALUES (tg_tag, current_query(), current_timestamp, session_user);
END;
$$ LANGUAGE plpgsql
SECURITY DEFINER;
Expand Down Expand Up @@ -155,7 +156,9 @@ def listen_ddl_log
RETURNS TRIGGER AS $$
BEGIN
SET search_path TO public;
EXECUTE format('SET ROLE %I', NEW.session_user);
EXECUTE NEW.ddl_command;
RESET ROLE;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
Expand Down

0 comments on commit c5bc950

Please sign in to comment.