From cf49a05ff50bffa7d91826b4b9ddb4797335c319 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Mon, 24 Jan 2022 11:37:42 -0500 Subject: [PATCH] RunCommandLogs: add a uuid to each log entry --- src/lib/Hydra/Schema/Result/RunCommandLogs.pm | 26 +++++++++++++++++-- src/sql/hydra.sql | 5 +++- src/sql/upgrade-81.sql | 6 +++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/sql/upgrade-81.sql diff --git a/src/lib/Hydra/Schema/Result/RunCommandLogs.pm b/src/lib/Hydra/Schema/Result/RunCommandLogs.pm index 66fa9c56..0bc144d5 100644 --- a/src/lib/Hydra/Schema/Result/RunCommandLogs.pm +++ b/src/lib/Hydra/Schema/Result/RunCommandLogs.pm @@ -42,6 +42,12 @@ __PACKAGE__->table("runcommandlogs"); is_nullable: 0 sequence: 'runcommandlogs_id_seq' +=head2 uuid + + data_type: 'uuid' + is_nullable: 0 + size: 16 + =head2 job_matcher data_type: 'text' @@ -98,6 +104,8 @@ __PACKAGE__->add_columns( is_nullable => 0, sequence => "runcommandlogs_id_seq", }, + "uuid", + { data_type => "uuid", is_nullable => 0, size => 16 }, "job_matcher", { data_type => "text", is_nullable => 0 }, "build_id", @@ -130,6 +138,20 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); +=head1 UNIQUE CONSTRAINTS + +=head2 C + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("runcommandlogs_uuid_unique", ["uuid"]); + =head1 RELATIONS =head2 build @@ -148,8 +170,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-11-19 15:15:36 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9AIzlQl1RjRXrs9gQCZKVw +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-01-24 10:24:52 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZVpYU6k3d/k/nitjpdgf/A use POSIX qw(WEXITSTATUS WIFEXITED WIFSIGNALED WTERMSIG); use Digest::SHA1 qw(sha1_hex); diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 7762e133..459305df 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -568,6 +568,7 @@ create index IndexTaskRetriesOrdered on TaskRetries(retry_at asc); -- 3. Update the end_time and exit_code when it completes create table RunCommandLogs ( id serial primary key not null, + uuid uuid not null, job_matcher text not null, build_id integer not null, -- TODO: evaluation_id integer not null, @@ -599,7 +600,9 @@ create table RunCommandLogs ( constraint RunCommandLogs_end_time_has_start_time check ( -- If end time is not null, then end_time, exit_code, and core_dumped should not be null (end_time is null) or (start_time is not null) - ) + ), + -- The uuid should be actually unique. + constraint RunCommandLogs_uuid_unique unique(uuid) -- Note: if exit_code is not null then signal and core_dumped must be null. -- Similarly, if signal is not null then exit_code must be null and diff --git a/src/sql/upgrade-81.sql b/src/sql/upgrade-81.sql new file mode 100644 index 00000000..cfbb2239 --- /dev/null +++ b/src/sql/upgrade-81.sql @@ -0,0 +1,6 @@ +alter table runcommandlogs add column uuid uuid; +update runcommandlogs set uuid = gen_random_uuid() where uuid is null; +alter table runcommandlogs alter column uuid set not null; +alter table runcommandlogs add constraint RunCommandLogs_uuid_unique unique(uuid); +# the unique uuid constraint adds a unique, btree index, so we don't need to create out own: +# "runcommandlogs_uuid_unique" UNIQUE CONSTRAINT, btree (uuid)