feat: add updated_at postgres fn + trigger

* closes #66
This commit is contained in:
Mohamed Sohail 2023-03-16 11:12:06 +00:00
parent 144d5018ea
commit 9d95f2e8f8
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
2 changed files with 34 additions and 1 deletions

View File

@ -25,4 +25,4 @@ $$ language plpgsql;
create trigger insert_gas_quota
after insert on keystore
for each row
execute procedure insert_gas_quota()
execute procedure insert_gas_quota();

View File

@ -0,0 +1,33 @@
ALTER TABLE keystore
ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE otx_dispatch
ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE gas_quota
ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- updated_at function
create function update_timestamp()
returns trigger
as $$
begin
new.updated_at = current_timestamp;
return new;
end;
$$ language plpgsql;
create trigger update_keystore_timestamp
before update on keystore
for each row
execute procedure update_timestamp();
create trigger update_otx_dispatch_timestamp
before update on otx_dispatch
for each row
execute procedure update_timestamp();
create trigger update_gas_quota_timestamp
before update on gas_quota
for each row
execute procedure update_timestamp();