8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c54be39 commit fe5711dCopy full SHA for fe5711d
test/postgres/mnt/00-init.sql
@@ -32,3 +32,26 @@ CREATE FUNCTION add(integer, integer) RETURNS integer
32
LANGUAGE SQL
33
IMMUTABLE
34
RETURNS NULL ON NULL INPUT;
35
+
36
+create table public.users_audit (
37
+ id BIGINT generated by DEFAULT as identity,
38
+ created_at timestamptz DEFAULT now(),
39
+ user_id bigint,
40
+ previous_value jsonb
41
+);
42
43
+create function public.audit_action()
44
+returns trigger as $$
45
+begin
46
+ insert into public.users_audit (user_id, previous_value)
47
+ values (old.id, row_to_json(old));
48
49
+ return new;
50
+end;
51
+$$ language plpgsql;
52
53
54
+CREATE TRIGGER check_update
55
+BEFORE UPDATE ON users
56
+FOR EACH ROW
57
+EXECUTE FUNCTION public.audit_action();
0 commit comments