From 9d95f2e8f8401819f11f33c00d4e2e72b67576a6 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Thu, 16 Mar 2023 11:12:06 +0000 Subject: [PATCH] feat: add updated_at postgres fn + trigger * closes #66 --- migrations/003_gas_quota.sql | 2 +- migrations/004_updated_at.sql | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 migrations/004_updated_at.sql diff --git a/migrations/003_gas_quota.sql b/migrations/003_gas_quota.sql index 746bc6c..d8f643e 100644 --- a/migrations/003_gas_quota.sql +++ b/migrations/003_gas_quota.sql @@ -25,4 +25,4 @@ $$ language plpgsql; create trigger insert_gas_quota after insert on keystore for each row -execute procedure insert_gas_quota() \ No newline at end of file +execute procedure insert_gas_quota(); \ No newline at end of file diff --git a/migrations/004_updated_at.sql b/migrations/004_updated_at.sql new file mode 100644 index 0000000..8ab8045 --- /dev/null +++ b/migrations/004_updated_at.sql @@ -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(); \ No newline at end of file