From efa1f1d4fbdc468c61f7403e8709d0295e052c7f Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 5 Feb 2020 17:10:50 -0500 Subject: [PATCH] Jobs: add a nullable jobset_id foreign key to Jobsets. Also, adds an explicitly named "jobs" accessor to the Jobsets Schema object, which uses the project/jobset name. --- src/lib/Hydra/Schema/Jobs.pm | 32 +++++++++++++++++++++++-- src/lib/Hydra/Schema/Jobsets.pm | 41 +++++++++++++++++++++++++++++---- src/sql/hydra.sql | 2 ++ src/sql/upgrade-60.sql | 10 ++++++++ 4 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 src/sql/upgrade-60.sql diff --git a/src/lib/Hydra/Schema/Jobs.pm b/src/lib/Hydra/Schema/Jobs.pm index bdecef3a..d4126e32 100644 --- a/src/lib/Hydra/Schema/Jobs.pm +++ b/src/lib/Hydra/Schema/Jobs.pm @@ -47,6 +47,12 @@ __PACKAGE__->table("jobs"); is_foreign_key: 1 is_nullable: 0 +=head2 jobset_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + =head2 name data_type: 'text' @@ -59,6 +65,8 @@ __PACKAGE__->add_columns( { data_type => "text", is_foreign_key => 1, is_nullable => 0 }, "jobset", { data_type => "text", is_foreign_key => 1, is_nullable => 0 }, + "jobset_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "name", { data_type => "text", is_nullable => 0 }, ); @@ -130,6 +138,26 @@ Related object: L __PACKAGE__->belongs_to( "jobset", "Hydra::Schema::Jobsets", + { id => "jobset_id" }, + { + is_deferrable => 0, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "NO ACTION", + }, +); + +=head2 jobset_project_jobset + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "jobset_project_jobset", + "Hydra::Schema::Jobsets", { name => "jobset", project => "project" }, { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" }, ); @@ -169,7 +197,7 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-02-06 12:22:36 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sYa6dZNK+stMAnTH0Tmn8A +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-02-06 12:30:58 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dFusVjxb423gIEoadAw9sw 1; diff --git a/src/lib/Hydra/Schema/Jobsets.pm b/src/lib/Hydra/Schema/Jobsets.pm index 2615ef87..60efa962 100644 --- a/src/lib/Hydra/Schema/Jobsets.pm +++ b/src/lib/Hydra/Schema/Jobsets.pm @@ -275,7 +275,7 @@ __PACKAGE__->has_many( undef, ); -=head2 jobs +=head2 jobs_jobset_ids Type: has_many @@ -284,7 +284,22 @@ Related object: L =cut __PACKAGE__->has_many( - "jobs", + "jobs_jobset_ids", + "Hydra::Schema::Jobs", + { "foreign.jobset_id" => "self.id" }, + undef, +); + +=head2 jobs_project_jobsets + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "jobs_project_jobsets", "Hydra::Schema::Jobs", { "foreign.jobset" => "self.name", @@ -378,8 +393,26 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-02-09 15:25:17 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1CMOaLf9fYRdJBlYiivmxA +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-02-09 15:26:15 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:DH1jX0smo2rFvyr4V+qJcw + +=head2 jobs + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "jobs", + "Hydra::Schema::Jobs", + { + "foreign.jobset" => "self.name", + "foreign.project" => "self.project", + }, + undef, +); __PACKAGE__->add_column( "+id" => { retrieve_on_insert => 1 } diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 6b22121c..77b5822a 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -146,9 +146,11 @@ create table JobsetInputAlts ( create table Jobs ( project text not null, jobset text not null, + jobset_id integer null, name text not null, primary key (project, jobset, name), + foreign key (jobset_id) references Jobsets(id) on delete cascade, foreign key (project) references Projects(name) on delete cascade on update cascade, foreign key (project, jobset) references Jobsets(project, name) on delete cascade on update cascade ); diff --git a/src/sql/upgrade-60.sql b/src/sql/upgrade-60.sql new file mode 100644 index 00000000..3cdb00c3 --- /dev/null +++ b/src/sql/upgrade-60.sql @@ -0,0 +1,10 @@ +-- Add the jobset_id columns to the Jobs table. This will go +-- quickly, since the field is nullable. Note this is just part one of +-- this migration. Future steps involve a piecemeal backfilling, and +-- then making the column non-null. + +ALTER TABLE Jobs + ADD COLUMN jobset_id integer NULL, + ADD FOREIGN KEY (jobset_id) + REFERENCES Jobsets(id) + ON DELETE CASCADE;