Jobsets: add a SERIAL, unique, non-null id column
A postgresql column which is non-null and unique is treated with the same optimisations as a primary key, so we have no need to try and recreate the `id` as the primary key. No read paths are impacted by this change, and the database will automatically create an ID for each insert. Thus, no code needs to change.
This commit is contained in:
parent
4a05bb36ac
commit
e00030563b
|
@ -40,6 +40,13 @@ __PACKAGE__->table("jobsets");
|
|||
data_type: 'text'
|
||||
is_nullable: 0
|
||||
|
||||
=head2 id
|
||||
|
||||
data_type: 'integer'
|
||||
is_auto_increment: 1
|
||||
is_nullable: 0
|
||||
sequence: 'jobsets_id_seq'
|
||||
|
||||
=head2 project
|
||||
|
||||
data_type: 'text'
|
||||
|
@ -153,6 +160,13 @@ __PACKAGE__->table("jobsets");
|
|||
__PACKAGE__->add_columns(
|
||||
"name",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"id",
|
||||
{
|
||||
data_type => "integer",
|
||||
is_auto_increment => 1,
|
||||
is_nullable => 0,
|
||||
sequence => "jobsets_id_seq",
|
||||
},
|
||||
"project",
|
||||
{ data_type => "text", is_foreign_key => 1, is_nullable => 0 },
|
||||
"description",
|
||||
|
@ -209,6 +223,20 @@ __PACKAGE__->add_columns(
|
|||
|
||||
__PACKAGE__->set_primary_key("project", "name");
|
||||
|
||||
=head1 UNIQUE CONSTRAINTS
|
||||
|
||||
=head2 C<jobsets_id_unique>
|
||||
|
||||
=over 4
|
||||
|
||||
=item * L</id>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->add_unique_constraint("jobsets_id_unique", ["id"]);
|
||||
|
||||
=head1 RELATIONS
|
||||
|
||||
=head2 buildmetrics
|
||||
|
@ -350,8 +378,12 @@ __PACKAGE__->has_many(
|
|||
);
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-02-09 15:21:11
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:FVP1/AWjdKTlY6djrG592A
|
||||
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-02-09 15:25:17
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1CMOaLf9fYRdJBlYiivmxA
|
||||
|
||||
__PACKAGE__->add_column(
|
||||
"+id" => { retrieve_on_insert => 1 }
|
||||
);
|
||||
|
||||
my %hint = (
|
||||
columns => [
|
||||
|
|
|
@ -52,6 +52,7 @@ create table ProjectMembers (
|
|||
-- describing build jobs.
|
||||
create table Jobsets (
|
||||
name text not null,
|
||||
id serial not null,
|
||||
project text not null,
|
||||
description text,
|
||||
nixExprInput text, -- name of the jobsetInput containing the Nix or Guix expression
|
||||
|
@ -76,7 +77,8 @@ create table Jobsets (
|
|||
check ((type = 0) = (nixExprInput is not null and nixExprPath is not null)),
|
||||
check ((type = 1) = (flake is not null)),
|
||||
primary key (project, name),
|
||||
foreign key (project) references Projects(name) on delete cascade on update cascade
|
||||
foreign key (project) references Projects(name) on delete cascade on update cascade,
|
||||
constraint Jobsets_id_unique UNIQUE(id)
|
||||
#ifdef SQLITE
|
||||
,
|
||||
foreign key (project, name, nixExprInput) references JobsetInputs(project, jobset, name)
|
||||
|
|
4
src/sql/upgrade-59.sql
Normal file
4
src/sql/upgrade-59.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
-- will automatically add unique IDs to Jobsets.
|
||||
ALTER TABLE Jobsets
|
||||
ADD COLUMN id SERIAL NOT NULL,
|
||||
ADD CONSTRAINT Jobsets_id_unique UNIQUE (id);
|
Loading…
Reference in a new issue