Skip to content

Commit

Permalink
Add Updated_At column to Merge Requests
Browse files Browse the repository at this point in the history
This will enable us to see when the status of a merge request last changed.
  • Loading branch information
Mythicaeda committed Jan 30, 2024
1 parent 7c9ae5f commit 882d131
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
@@ -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');

1 change: 1 addition & 0 deletions merlin-server/sql/merlin/applied_migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');
14 changes: 14 additions & 0 deletions merlin-server/sql/merlin/tables/merge_request.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

0 comments on commit 882d131

Please sign in to comment.