postgres migration
Posted at 2021-10-13

postgres migration


CREATE TABLE ddl_history (
  id serial primary key,
  ddl_date timestamptz,
  ddl_tag text,
  query_text text
);


CREATE OR REPLACE FUNCTION log_ddl()
  RETURNS event_trigger AS $$
BEGIN
    INSERT INTO ddl_history (ddl_date, ddl_tag, query_text) 
    VALUES (statement_timestamp(), tg_tag, current_query());
END;
$$ LANGUAGE plpgsql;

CREATE EVENT TRIGGER log_ddl_info ON ddl_command_end EXECUTE PROCEDURE log_ddl();

Comments 0

Post a Comment