fix the modified_by and modified_at columns

As all changes are already written into history, why not enforce the
proper changing of modified_at and modified_by columns?

This way we can be sure these are properly changed and don't have to
take care of that in the SQL statements anymore.
master
Gibheer 2 years ago
parent 25e2046e78
commit 9de4163d22
  1. 7
      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'),

Loading…
Cancel
Save