Skip to content

Commit 8250767

Browse files
feat: introduce updated_at column (#9)
Co-authored-by: Thomas <31189692+ecktoteckto@users.noreply.github.com>
1 parent 7451489 commit 8250767

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

db/migrations/0003_updated_at.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
create
2+
or replace function orb.set_updated_at () returns trigger language plpgsql as $$
3+
begin
4+
new.updated_at = now();
5+
return NEW;
6+
end;
7+
$$;
8+
9+
alter function orb.set_updated_at () owner to postgres;
10+
11+
alter table orb.subscriptions
12+
add updated_at timestamptz default timezone ('utc'::text, now()) not null;
13+
14+
create trigger handle_updated_at before
15+
update on orb.subscriptions for each row
16+
execute function orb.set_updated_at ();
17+
18+
alter table orb.customers
19+
add updated_at timestamptz default timezone ('utc'::text, now()) not null;
20+
21+
create trigger handle_updated_at before
22+
update on orb.customers for each row
23+
execute function orb.set_updated_at ();
24+
25+
alter table orb.invoices
26+
add updated_at timestamptz default timezone ('utc'::text, now()) not null;
27+
28+
create trigger handle_updated_at before
29+
update on orb.invoices for each row
30+
execute function orb.set_updated_at ();
31+
32+
alter table orb.credit_notes
33+
add updated_at timestamptz default timezone ('utc'::text, now()) not null;
34+
35+
create trigger handle_updated_at before
36+
update on orb.credit_notes for each row
37+
execute function orb.set_updated_at ();

0 commit comments

Comments
 (0)