diff --git a/schema/01_initial.sql b/schema/01_initial.sql index 7505332..d5b20c8 100644 --- a/schema/01_initial.sql +++ b/schema/01_initial.sql @@ -155,6 +155,13 @@ comment on column history.action is 'The action can be one of insert, update or create or replace function record() returns trigger as $$ begin + if TG_OP = 'UPDATE' or TG_OP = 'INSERT' then + NEW.modified_at = now(); + NEW.modified_by = current_setting('dim.username'); + end if; + if TG_OP = 'INSERT' then + NEW.created_by = current_setting('dim.username'); + end if; insert into history(transaction, created_by, type, action, old_entity, new_entity) values ( current_setting('dim.transaction'),