From 882d1315d6b74a4232da77e3c222b1e1f51b723a Mon Sep 17 00:00:00 2001 From: Theresa Kamerman Date: Mon, 22 Jan 2024 13:12:32 -0800 Subject: [PATCH] Add Updated_At column to Merge Requests This will enable us to see when the status of a merge request last changed. --- .../AerieMerlin/36_metadata_updated_at/down.sql | 5 +++++ .../AerieMerlin/36_metadata_updated_at/up.sql | 17 +++++++++++++++++ merlin-server/sql/merlin/applied_migrations.sql | 1 + .../sql/merlin/tables/merge_request.sql | 14 ++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 deployment/hasura/migrations/AerieMerlin/36_metadata_updated_at/down.sql create mode 100644 deployment/hasura/migrations/AerieMerlin/36_metadata_updated_at/up.sql diff --git a/deployment/hasura/migrations/AerieMerlin/36_metadata_updated_at/down.sql b/deployment/hasura/migrations/AerieMerlin/36_metadata_updated_at/down.sql new file mode 100644 index 0000000000..c316c5c7f0 --- /dev/null +++ b/deployment/hasura/migrations/AerieMerlin/36_metadata_updated_at/down.sql @@ -0,0 +1,5 @@ +drop trigger set_timestamp on merge_request; +drop function merge_request_set_updated_at(); +alter table merge_request drop column updated_at; + +call migrations.mark_migration_rolled_back('36'); diff --git a/deployment/hasura/migrations/AerieMerlin/36_metadata_updated_at/up.sql b/deployment/hasura/migrations/AerieMerlin/36_metadata_updated_at/up.sql new file mode 100644 index 0000000000..841731f870 --- /dev/null +++ b/deployment/hasura/migrations/AerieMerlin/36_metadata_updated_at/up.sql @@ -0,0 +1,17 @@ +alter table merge_request add column updated_at timestamptz not null default now(); + +create function merge_request_set_updated_at() +returns trigger +security definer +language plpgsql as $$begin + new.updated_at = now(); + return new; +end$$; + +create trigger set_timestamp + before update or insert on merge_request + for each row +execute function merge_request_set_updated_at(); + +call migrations.mark_migration_applied('36'); + diff --git a/merlin-server/sql/merlin/applied_migrations.sql b/merlin-server/sql/merlin/applied_migrations.sql index 0d4d1d7177..d3096db0e8 100644 --- a/merlin-server/sql/merlin/applied_migrations.sql +++ b/merlin-server/sql/merlin/applied_migrations.sql @@ -38,3 +38,4 @@ call migrations.mark_migration_applied('32'); call migrations.mark_migration_applied('33'); call migrations.mark_migration_applied('34'); call migrations.mark_migration_applied('35'); +call migrations.mark_migration_applied('36'); diff --git a/merlin-server/sql/merlin/tables/merge_request.sql b/merlin-server/sql/merlin/tables/merge_request.sql index b92758b0e1..6049c2d5dd 100644 --- a/merlin-server/sql/merlin/tables/merge_request.sql +++ b/merlin-server/sql/merlin/tables/merge_request.sql @@ -7,6 +7,7 @@ create table merge_request( status merge_request_status default 'pending', requester_username text, reviewer_username text, + updated_at timestamptz not null default now(), constraint merge_request_requester_exists foreign key (requester_username) references metadata.users @@ -39,3 +40,16 @@ comment on column merge_request.requester_username is e'' 'The user who created this merge request.'; comment on column merge_request.reviewer_username is e'' 'The user who reviews this merge request. Is empty until the request enters review.'; + +create function merge_request_set_updated_at() +returns trigger +security definer +language plpgsql as $$begin + new.updated_at = now(); + return new; +end$$; + +create trigger set_timestamp + before update or insert on merge_request + for each row +execute function merge_request_set_updated_at();