From 686b6271d2d29338c378dd4a726284b62887757b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 21 Oct 2009 12:25:43 +0000 Subject: [PATCH] * Cleaned up the foreign key constraints. * Generate SQLite and PostgreSQL schemas from hydra.sql. --- doc/dev-notes.txt | 5 +- release.nix | 2 + src/lib/Hydra/Schema.pm | 4 +- src/lib/Hydra/Schema/BuildInputs.pm | 4 +- src/lib/Hydra/Schema/BuildProducts.pm | 4 +- src/lib/Hydra/Schema/BuildResultInfo.pm | 4 +- src/lib/Hydra/Schema/BuildSchedulingInfo.pm | 4 +- src/lib/Hydra/Schema/BuildSteps.pm | 4 +- src/lib/Hydra/Schema/Builds.pm | 4 +- src/lib/Hydra/Schema/CachedPathInputs.pm | 4 +- .../Hydra/Schema/CachedSubversionInputs.pm | 4 +- src/lib/Hydra/Schema/Jobs.pm | 16 +- src/lib/Hydra/Schema/JobsetInputAlts.pm | 4 +- src/lib/Hydra/Schema/JobsetInputs.pm | 4 +- src/lib/Hydra/Schema/Jobsets.pm | 20 +- src/lib/Hydra/Schema/Projects.pm | 14 +- src/lib/Hydra/Schema/SystemTypes.pm | 4 +- src/lib/Hydra/Schema/UserRoles.pm | 4 +- src/lib/Hydra/Schema/Users.pm | 14 +- src/lib/Hydra/Schema/ViewJobs.pm | 4 +- src/lib/Hydra/Schema/Views.pm | 4 +- src/sql/Makefile | 12 + src/sql/hydra.sql | 373 ++++++++++-------- src/sql/sqlite.sql | 0 24 files changed, 276 insertions(+), 240 deletions(-) create mode 100644 src/sql/Makefile create mode 100644 src/sql/sqlite.sql diff --git a/doc/dev-notes.txt b/doc/dev-notes.txt index 6dd51cbe..0136082b 100644 --- a/doc/dev-notes.txt +++ b/doc/dev-notes.txt @@ -1,9 +1,6 @@ * Recreating the schema bindings: - $ rm tmp.sqlite - $ sqlite3 tmp.sqlite < sql/hydra.sql - # $ ~/bin/genfkey tmp.sqlite > sql/fk-triggers.sql - $ perl -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:./lib -e 'make_schema_at("Hydra::Schema", { relationships => 1, moniker_map => sub {return $_;} }, ["dbi:SQLite:tmp.sqlite"])' + $ make -C src/sql update-dbix * Running the test server: diff --git a/release.nix b/release.nix index 3c9e58c6..77a0b152 100644 --- a/release.nix +++ b/release.nix @@ -35,6 +35,8 @@ let cp $jquery src/root/static/js/jquery-pack.js rm -rf src/root/static/js/tablesorter unzip -d src/root/static/js $tablesorter + + make -C src/sql releaseName=hydra-0.1$VERSION_SUFFIX; ensureDir $out/tarballs diff --git a/src/lib/Hydra/Schema.pm b/src/lib/Hydra/Schema.pm index f3e50c22..1cd3bc72 100644 --- a/src/lib/Hydra/Schema.pm +++ b/src/lib/Hydra/Schema.pm @@ -8,8 +8,8 @@ use base 'DBIx::Class::Schema'; __PACKAGE__->load_classes; -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ODLRc6VfDQpb8MyXPKmqtg +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Fs+amiko3zHOhK97IatSgQ # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/BuildInputs.pm b/src/lib/Hydra/Schema/BuildInputs.pm index f0767f74..396b47f9 100644 --- a/src/lib/Hydra/Schema/BuildInputs.pm +++ b/src/lib/Hydra/Schema/BuildInputs.pm @@ -103,8 +103,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gtA3wQA2CLsXs4X95PfX9A +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7blxTiVkvfdukDiXCoD+Lw use Hydra::Helper::Nix; diff --git a/src/lib/Hydra/Schema/BuildProducts.pm b/src/lib/Hydra/Schema/BuildProducts.pm index d9579ef9..f68d6513 100644 --- a/src/lib/Hydra/Schema/BuildProducts.pm +++ b/src/lib/Hydra/Schema/BuildProducts.pm @@ -91,8 +91,8 @@ __PACKAGE__->set_primary_key("build", "productnr"); __PACKAGE__->belongs_to("build", "Hydra::Schema::Builds", { id => "build" }); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ii6N3v4M1fX1tQ3YmJNFWw +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:8wtm75jCRmcyWInKMO826g # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/BuildResultInfo.pm b/src/lib/Hydra/Schema/BuildResultInfo.pm index 84357722..8ac1697a 100644 --- a/src/lib/Hydra/Schema/BuildResultInfo.pm +++ b/src/lib/Hydra/Schema/BuildResultInfo.pm @@ -86,8 +86,8 @@ __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to("id", "Hydra::Schema::Builds", { id => "id" }); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EMvF2g+MDIE84yjnJOs7og +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3P0UuNHhdA8VfALMfwssTA __PACKAGE__->belongs_to( "failedDep", diff --git a/src/lib/Hydra/Schema/BuildSchedulingInfo.pm b/src/lib/Hydra/Schema/BuildSchedulingInfo.pm index 8ec329c4..23a04aa9 100644 --- a/src/lib/Hydra/Schema/BuildSchedulingInfo.pm +++ b/src/lib/Hydra/Schema/BuildSchedulingInfo.pm @@ -43,8 +43,8 @@ __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to("id", "Hydra::Schema::Builds", { id => "id" }); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RcdX5dHefBQnxQYbMxNF/w +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:e4O2JqrJN8coHmRdjbbxHg # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/BuildSteps.pm b/src/lib/Hydra/Schema/BuildSteps.pm index e3bcf63e..51e6ba33 100644 --- a/src/lib/Hydra/Schema/BuildSteps.pm +++ b/src/lib/Hydra/Schema/BuildSteps.pm @@ -91,7 +91,7 @@ __PACKAGE__->set_primary_key("build", "stepnr"); __PACKAGE__->belongs_to("build", "Hydra::Schema::Builds", { id => "build" }); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1AQCHpuv8Lqk/FYdU8JYFA +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/Qdb8Y3Tqw7AOM5ique5Nw 1; diff --git a/src/lib/Hydra/Schema/Builds.pm b/src/lib/Hydra/Schema/Builds.pm index dd1c0299..84fe35f0 100644 --- a/src/lib/Hydra/Schema/Builds.pm +++ b/src/lib/Hydra/Schema/Builds.pm @@ -163,8 +163,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CcYlMej7OPRUJn6375Qlqw +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:eJS7WCbSjwylQuAbQtB24w use Hydra::Helper::Nix; diff --git a/src/lib/Hydra/Schema/CachedPathInputs.pm b/src/lib/Hydra/Schema/CachedPathInputs.pm index d3b71bcd..ff659a46 100644 --- a/src/lib/Hydra/Schema/CachedPathInputs.pm +++ b/src/lib/Hydra/Schema/CachedPathInputs.pm @@ -47,8 +47,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("srcpath", "sha256hash"); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:mYBdemei1tFuK8Ll6eMLfQ +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:FcLeNgdEr13JAYZLxF4/tw # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/CachedSubversionInputs.pm b/src/lib/Hydra/Schema/CachedSubversionInputs.pm index 85e0f3a6..49e19bc3 100644 --- a/src/lib/Hydra/Schema/CachedSubversionInputs.pm +++ b/src/lib/Hydra/Schema/CachedSubversionInputs.pm @@ -40,8 +40,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("uri", "revision"); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bE+w54cACUS2L0PJ9gPjtw +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:y14yX+UAP03N7VGrgehcLw # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/Jobs.pm b/src/lib/Hydra/Schema/Jobs.pm index fe899dba..2888124f 100644 --- a/src/lib/Hydra/Schema/Jobs.pm +++ b/src/lib/Hydra/Schema/Jobs.pm @@ -58,6 +58,12 @@ __PACKAGE__->add_columns( { data_type => "integer", default_value => 0, is_nullable => 0, size => undef }, ); __PACKAGE__->set_primary_key("project", "jobset", "name"); +__PACKAGE__->belongs_to("project", "Hydra::Schema::Projects", { name => "project" }); +__PACKAGE__->belongs_to( + "jobset", + "Hydra::Schema::Jobsets", + { name => "jobset", project => "project" }, +); __PACKAGE__->has_many( "builds", "Hydra::Schema::Builds", @@ -67,16 +73,10 @@ __PACKAGE__->has_many( "foreign.project" => "self.project", }, ); -__PACKAGE__->belongs_to("project", "Hydra::Schema::Projects", { name => "project" }); -__PACKAGE__->belongs_to( - "jobset", - "Hydra::Schema::Jobsets", - { name => "jobset", project => "project" }, -); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:c0OEe2zPd/E4vh0PRXm4Ag +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:AjrYM1rAdgYy3j0+IFFUEw # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/JobsetInputAlts.pm b/src/lib/Hydra/Schema/JobsetInputAlts.pm index 8ad27cfc..3adbdaf8 100644 --- a/src/lib/Hydra/Schema/JobsetInputAlts.pm +++ b/src/lib/Hydra/Schema/JobsetInputAlts.pm @@ -69,8 +69,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jS8pitmHFnplE8WcK0OyMQ +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:o5NC1PPpGrzOZZcumFoudg # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/JobsetInputs.pm b/src/lib/Hydra/Schema/JobsetInputs.pm index e6b5f58d..fa2d240f 100644 --- a/src/lib/Hydra/Schema/JobsetInputs.pm +++ b/src/lib/Hydra/Schema/JobsetInputs.pm @@ -65,8 +65,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:W0rhMTOzLBZNsVShQHg5+A +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7A5UkNWAqy0XuhlKvOgr6Q # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/Jobsets.pm b/src/lib/Hydra/Schema/Jobsets.pm index 5d9bad3c..14ff3d13 100644 --- a/src/lib/Hydra/Schema/Jobsets.pm +++ b/src/lib/Hydra/Schema/Jobsets.pm @@ -71,14 +71,6 @@ __PACKAGE__->add_columns( { data_type => "integer", default_value => 1, is_nullable => 0, size => undef }, ); __PACKAGE__->set_primary_key("project", "name"); -__PACKAGE__->has_many( - "builds", - "Hydra::Schema::Builds", - { - "foreign.jobset" => "self.name", - "foreign.project" => "self.project", - }, -); __PACKAGE__->belongs_to("project", "Hydra::Schema::Projects", { name => "project" }); __PACKAGE__->belongs_to( "jobsetinput", @@ -101,10 +93,18 @@ __PACKAGE__->has_many( "foreign.project" => "self.project", }, ); +__PACKAGE__->has_many( + "builds", + "Hydra::Schema::Builds", + { + "foreign.jobset" => "self.name", + "foreign.project" => "self.project", + }, +); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CB5lPsrozpvO8gLXHTyMrQ +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vaCDa6WBFdcLMG23Nlr27g # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/Projects.pm b/src/lib/Hydra/Schema/Projects.pm index c85ab2b2..92fd2e54 100644 --- a/src/lib/Hydra/Schema/Projects.pm +++ b/src/lib/Hydra/Schema/Projects.pm @@ -48,11 +48,6 @@ __PACKAGE__->add_columns( }, ); __PACKAGE__->set_primary_key("name"); -__PACKAGE__->has_many( - "builds", - "Hydra::Schema::Builds", - { "foreign.project" => "self.name" }, -); __PACKAGE__->belongs_to("owner", "Hydra::Schema::Users", { username => "owner" }); __PACKAGE__->has_many( "jobsets", @@ -64,6 +59,11 @@ __PACKAGE__->has_many( "Hydra::Schema::Jobs", { "foreign.project" => "self.name" }, ); +__PACKAGE__->has_many( + "builds", + "Hydra::Schema::Builds", + { "foreign.project" => "self.name" }, +); __PACKAGE__->has_many( "views", "Hydra::Schema::Views", @@ -76,8 +76,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:N6NPLJfc1gKM4zz6dS5PJw +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:XcrLhOH+WuO24UFulGft1w # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/SystemTypes.pm b/src/lib/Hydra/Schema/SystemTypes.pm index 93312a75..c60f5d23 100644 --- a/src/lib/Hydra/Schema/SystemTypes.pm +++ b/src/lib/Hydra/Schema/SystemTypes.pm @@ -21,8 +21,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("system"); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EkpopxgwlZf8Du3EmWzTKQ +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:X1voxjTNUQrn04o0zyVZ+w # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/UserRoles.pm b/src/lib/Hydra/Schema/UserRoles.pm index c01878dc..da77d5fc 100644 --- a/src/lib/Hydra/Schema/UserRoles.pm +++ b/src/lib/Hydra/Schema/UserRoles.pm @@ -28,8 +28,8 @@ __PACKAGE__->set_primary_key("username", "role"); __PACKAGE__->belongs_to("username", "Hydra::Schema::Users", { username => "username" }); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:W2Q6219GlZl2IqQkBoFmFA +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hbm45HCbdLU4emCiCC5gyA # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/Users.pm b/src/lib/Hydra/Schema/Users.pm index 4ad1f94d..44d964c9 100644 --- a/src/lib/Hydra/Schema/Users.pm +++ b/src/lib/Hydra/Schema/Users.pm @@ -38,20 +38,20 @@ __PACKAGE__->add_columns( }, ); __PACKAGE__->set_primary_key("username"); -__PACKAGE__->has_many( - "projects", - "Hydra::Schema::Projects", - { "foreign.owner" => "self.username" }, -); __PACKAGE__->has_many( "userroles", "Hydra::Schema::UserRoles", { "foreign.username" => "self.username" }, ); +__PACKAGE__->has_many( + "projects", + "Hydra::Schema::Projects", + { "foreign.owner" => "self.username" }, +); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qH+qBI3xxQgTNf3v7E3sDw +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:4Lj9iNcQhOG5VzUXkQFzkg # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/ViewJobs.pm b/src/lib/Hydra/Schema/ViewJobs.pm index 3dc22793..40e2d07f 100644 --- a/src/lib/Hydra/Schema/ViewJobs.pm +++ b/src/lib/Hydra/Schema/ViewJobs.pm @@ -66,8 +66,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LkiGAkZOiLNJk6oDY0+zNw +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:63nUKTtC6XdTSawDvU+oFg # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/lib/Hydra/Schema/Views.pm b/src/lib/Hydra/Schema/Views.pm index 78eee999..ea2d56ac 100644 --- a/src/lib/Hydra/Schema/Views.pm +++ b/src/lib/Hydra/Schema/Views.pm @@ -42,8 +42,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-15 23:14:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hV+xzi564rgcYeDvz75zCA +# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 14:17:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+x+gzFpHSZzVMlsjMn47UA # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/src/sql/Makefile b/src/sql/Makefile new file mode 100644 index 00000000..10bf1686 --- /dev/null +++ b/src/sql/Makefile @@ -0,0 +1,12 @@ +all: hydra-postgresql.sql hydra-sqlite.sql + +hydra-postgresql.sql: hydra.sql + cpp -P -E -traditional-cpp -DPOSTGRESQL hydra.sql > $@ || rm -f $@ + +hydra-sqlite.sql: hydra.sql + cpp -P -E -traditional-cpp -DSQLITE hydra.sql > $@ || rm -f $@ + +update-dbix: hydra-sqlite.sql + rm -f tmp.sqlite + sqlite3 tmp.sqlite < hydra-sqlite.sql + perl -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:../lib -e 'make_schema_at("Hydra::Schema", { relationships => 1, moniker_map => sub {return $$_;} }, ["dbi:SQLite:tmp.sqlite"])' diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 21f8c82e..7d4b963a 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -1,10 +1,116 @@ +create table Users ( + userName text primary key not null, + fullName text, + emailAddress text not null, + password text not null -- sha256 hash +); + + +create table UserRoles ( + userName text not null, + role text not null, + primary key (userName, role), + foreign key (userName) references Users(userName) on delete cascade on update cascade +); + + +create table Projects ( + name text primary key not null, -- project id, lowercase (e.g. "patchelf") + displayName text not null, -- display name (e.g. "PatchELF") + description text, + enabled integer not null default 1, + owner text not null, + homepage text, -- URL for the project + foreign key (owner) references Users(userName) on update cascade +); + + +-- A jobset consists of a set of inputs (e.g. SVN repositories), one +-- of which contains a Nix expression containing an attribute set +-- describing build jobs. +create table Jobsets ( + name text not null, + project text not null, + description text, + nixExprInput text not null, -- name of the jobsetInput containing the Nix expression + nixExprPath text not null, -- relative path of the Nix expression + errorMsg text, -- used to signal the last evaluation error etc. for this jobset + errorTime integer, -- timestamp associated with errorMsg + lastCheckedTime integer, -- last time the scheduler looked at this jobset + enabled integer not null default 1, + primary key (project, name), + foreign key (project) references Projects(name) on delete cascade on update cascade +#ifdef SQLITE + , + foreign key (project, name, nixExprInput) references JobsetInputs(project, jobset, name) +#endif +); + + +create table JobsetInputs ( + project text not null, + jobset text not null, + name text not null, + type text not null, -- "svn", "cvs", "path", "uri", "string", "boolean" + primary key (project, jobset, name), + foreign key (project, jobset) references Jobsets(project, name) on delete cascade on update cascade +); + + +#ifdef POSTGRESQL +alter table Jobsets + add foreign key (project, name, nixExprInput) + references JobsetInputs(project, jobset, name); +#endif + + +create table JobsetInputAlts ( + project text not null, + jobset text not null, + input text not null, + altnr integer not null, + + -- urgh + value text, -- for most types, a URI; for 'path', an absolute path; for 'string', an arbitrary value + revision integer, -- for type == 'svn' + tag text, -- for type == 'cvs' + + primary key (project, jobset, input, altnr), + foreign key (project, jobset, input) references JobsetInputs(project, jobset, name) on delete cascade on update cascade +); + + +create table Jobs ( + project text not null, + jobset text not null, + name text not null, + + active integer not null default 1, -- !!! obsolete, remove + + errorMsg text, -- evalution error for this job + + firstEvalTime integer, -- first time the scheduler saw this job + lastEvalTime integer, -- last time the scheduler saw this job + + disabled integer not null default 0, -- !!! not currently used + + primary key (project, jobset, name), + 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 +); + + -- This table contains all builds, either scheduled or finished. For -- scheduled builds, additional info (such as the priority) can be -- found in the BuildSchedulingInfo table. For finished builds, -- additional info (such as the logs, build products, etc.) can be -- found in several tables, such as BuildResultInfo and BuildProducts. create table Builds ( +#ifdef POSTGRESQL + id serial primary key not null, +#else id integer primary key autoincrement not null, +#endif finished integer not null, -- 0 = scheduled, 1 = finished @@ -29,9 +135,9 @@ create table Builds ( isCurrent integer default 0, - foreign key (project) references Projects(name), -- ignored by sqlite - foreign key (project, jobset) references Jobsets(project, name), -- ignored by sqlite - foreign key (project, jobset, job) references Jobs(project, jobset, name) -- ignored by sqlite + foreign key (project) references Projects(name) on update cascade, + foreign key (project, jobset) references Jobsets(project, name) on update cascade, + foreign key (project, jobset, job) references Jobs(project, jobset, name) on update cascade ); @@ -50,7 +156,7 @@ create table BuildSchedulingInfo ( startTime integer, -- if busy, time we started - foreign key (id) references Builds(id) on delete cascade -- ignored by sqlite + foreign key (id) references Builds(id) on delete cascade ); @@ -83,7 +189,7 @@ create table BuildResultInfo ( failedDepBuild integer, -- obsolete failedDepStepNr integer, -- obsolete - foreign key (id) references Builds(id) on delete cascade -- ignored by sqlite + foreign key (id) references Builds(id) on delete cascade ); @@ -108,13 +214,17 @@ create table BuildSteps ( stopTime integer, primary key (build, stepnr), - foreign key (build) references Builds(id) on delete cascade -- ignored by sqlite + foreign key (build) references Builds(id) on delete cascade ); -- Inputs of builds. -create table BuildInputs ( +create table BuildInputs ( +#ifdef POSTGRESQL + id serial primary key not null, +#else id integer primary key autoincrement not null, +#endif -- Which build this input belongs to. build integer, @@ -132,8 +242,8 @@ create table BuildInputs ( sha256hash text, - foreign key (build) references Builds(id) on delete cascade, -- ignored by sqlite - foreign key (dependency) references Builds(id) -- ignored by sqlite + foreign key (build) references Builds(id) on delete cascade, + foreign key (dependency) references Builds(id) ); @@ -150,130 +260,7 @@ create table BuildProducts ( description text, -- optionally, some description of this file/directory defaultPath text, -- if `path' is a directory, the default file relative to `path' to be served primary key (build, productnr), - foreign key (build) references Builds(id) on delete cascade -- ignored by sqlite -); - - --- Emulate "on delete cascade" foreign key constraints. -create trigger cascadeBuildDeletion - before delete on Builds - for each row begin - delete from BuildSchedulingInfo where id = old.id; - delete from BuildResultInfo where id = old.id; - delete from BuildInputs where build = old.id; - delete from BuildProducts where build = old.id; - delete from BuildSteps where build = old.id; - end; - - -create table Projects ( - name text primary key not null, -- project id, lowercase (e.g. "patchelf") - displayName text not null, -- display name (e.g. "PatchELF") - description text, - enabled integer not null default 1, - owner text not null, - homepage text, -- URL for the project - foreign key (owner) references Users(userName) -- ignored by sqlite -); - - -create trigger cascadeProjectUpdate - update of name on Projects - for each row begin - update Jobsets set project = new.name where project = old.name; - update JobsetInputs set project = new.name where project = old.name; - update JobsetInputAlts set project = new.name where project = old.name; - update Builds set project = new.name where project = old.name; - update Views set project = new.name where project = old.name; - update ViewJobs set project = new.name where project = old.name; - end; - - --- A jobset consists of a set of inputs (e.g. SVN repositories), one --- of which contains a Nix expression containing an attribute set --- describing build jobs. -create table Jobsets ( - name text not null, - project text not null, - description text, - nixExprInput text not null, -- name of the jobsetInput containing the Nix expression - nixExprPath text not null, -- relative path of the Nix expression - errorMsg text, -- used to signal the last evaluation error etc. for this jobset - errorTime integer, -- timestamp associated with errorMsg - lastCheckedTime integer, -- last time the scheduler looked at this jobset - enabled integer not null default 1, - primary key (project, name), - foreign key (project) references Projects(name) on delete cascade, -- ignored by sqlite - foreign key (project, name, nixExprInput) references JobsetInputs(project, jobset, name) -); - - -create trigger cascadeJobsetUpdate - update of name on Jobsets - for each row begin - update JobsetInputs set jobset = new.name where project = old.project and jobset = old.name; - update JobsetInputAlts set jobset = new.name where project = old.project and jobset = old.name; - update Builds set jobset = new.name where project = old.project and jobset = old.name; - end; - - -create table JobsetInputs ( - project text not null, - jobset text not null, - name text not null, - type text not null, -- "svn", "cvs", "path", "uri", "string", "boolean" - primary key (project, jobset, name), - foreign key (project, jobset) references Jobsets(project, name) on delete cascade -- ignored by sqlite -); - - -create trigger cascadeJobsetInputUpdate - update of name on JobsetInputs - for each row begin - update JobsetInputAlts set input = new.name where project = old.project and jobset = old.jobset and input = old.name; - end; - - -create trigger cascadeJobsetInputDelete - before delete on JobsetInputs - for each row begin - delete from JobsetInputAlts where project = old.project and jobset = old.jobset and input = old.name; - end; - - -create table JobsetInputAlts ( - project text not null, - jobset text not null, - input text not null, - altnr integer not null, - - -- urgh - value text, -- for most types, a URI; for 'path', an absolute path; for 'string', an arbitrary value - revision integer, -- for type == 'svn' - tag text, -- for type == 'cvs' - - primary key (project, jobset, input, altnr), - foreign key (project, jobset, input) references JobsetInputs(project, jobset, name) on delete cascade -- ignored by sqlite -); - - -create table Jobs ( - project text not null, - jobset text not null, - name text not null, - - active integer not null default 1, -- !!! obsolete, remove - - errorMsg text, -- evalution error for this job - - firstEvalTime integer, -- first time the scheduler saw this job - lastEvalTime integer, -- last time the scheduler saw this job - - disabled integer not null default 0, -- !!! not currently used - - primary key (project, jobset, name), - foreign key (project) references Projects(name) on delete cascade, -- ignored by sqlite - foreign key (project, jobset) references Jobsets(project, name) on delete cascade -- ignored by sqlite + foreign key (build) references Builds(id) on delete cascade ); @@ -306,29 +293,6 @@ create table SystemTypes ( ); -create table Users ( - userName text primary key not null, - fullName text, - emailAddress text not null, - password text not null -- sha256 hash -); - - -create table UserRoles ( - userName text not null, - role text not null, - primary key (userName, role), - foreign key (userName) references Users(userName) -- ignored by sqlite -); - - -create trigger cascadeUserDelete - before delete on Users - for each row begin - delete from UserRoles where userName = old.userName; - end; - - -- Views are a mechanism to automatically group related builds -- together. A view definition consists of a build of some "primary" -- job, plus all builds of the other jobs named in ViewJobs that have @@ -345,24 +309,10 @@ create table Views ( keep integer not null default 0, primary key (project, name), - foreign key (project) references Projects(name) on delete cascade -- ignored by sqlite + foreign key (project) references Projects(name) on delete cascade on update cascade ); -create trigger cascadeViewDelete - before delete on Views - for each row begin - delete from ViewJobs where project = old.project and view_ = old.name; - end; - - -create trigger cascadeViewUpdate - update of name on Views - for each row begin - update ViewJobs set view_ = new.name where project = old.project and view_ = old.name; - end; - - create table ViewJobs ( project text not null, view_ text not null, @@ -389,9 +339,8 @@ create table ViewJobs ( autoRelease integer not null default 0, primary key (project, view_, job, attrs), - foreign key (project) references Projects(name) on delete cascade, -- ignored by sqlite - foreign key (project, view_) references Views(project, name) on delete cascade -- ignored by sqlite - foreign key (project, jobset) references Jobsets(project, name) on delete restrict -- ignored by sqlite + foreign key (project) references Projects(name) on delete cascade on update cascade, + foreign key (project, view_) references Views(project, name) on delete cascade on update cascade ); @@ -404,3 +353,79 @@ create index IndexBuildsByIsCurrent on Builds(isCurrent); create index IndexBuildResultInfo on BuildResultInfo(id); -- primary key index, not created automatically by PostgreSQL create index IndexBuild on BuildProducts(build); create index IndexBuildType on BuildProducts(build, type); + + +#ifdef SQLITE + +-- Emulate some "on delete/update cascade" foreign key constraints, +-- which SQLite doesn't support yet. + + +create trigger cascadeBuildDeletion + before delete on Builds + for each row begin + delete from BuildSchedulingInfo where id = old.id; + delete from BuildResultInfo where id = old.id; + delete from BuildInputs where build = old.id; + delete from BuildProducts where build = old.id; + delete from BuildSteps where build = old.id; + end; + + +create trigger cascadeProjectUpdate + update of name on Projects + for each row begin + update Jobsets set project = new.name where project = old.name; + update JobsetInputs set project = new.name where project = old.name; + update JobsetInputAlts set project = new.name where project = old.name; + update Builds set project = new.name where project = old.name; + update Views set project = new.name where project = old.name; + update ViewJobs set project = new.name where project = old.name; + end; + + +create trigger cascadeJobsetUpdate + update of name on Jobsets + for each row begin + update JobsetInputs set jobset = new.name where project = old.project and jobset = old.name; + update JobsetInputAlts set jobset = new.name where project = old.project and jobset = old.name; + update Builds set jobset = new.name where project = old.project and jobset = old.name; + end; + + +create trigger cascadeJobsetInputUpdate + update of name on JobsetInputs + for each row begin + update JobsetInputAlts set input = new.name where project = old.project and jobset = old.jobset and input = old.name; + end; + + +create trigger cascadeJobsetInputDelete + before delete on JobsetInputs + for each row begin + delete from JobsetInputAlts where project = old.project and jobset = old.jobset and input = old.name; + end; + + +create trigger cascadeUserDelete + before delete on Users + for each row begin + delete from UserRoles where userName = old.userName; + end; + + +create trigger cascadeViewDelete + before delete on Views + for each row begin + delete from ViewJobs where project = old.project and view_ = old.name; + end; + + +create trigger cascadeViewUpdate + update of name on Views + for each row begin + update ViewJobs set view_ = new.name where project = old.project and view_ = old.name; + end; + + +#endif diff --git a/src/sql/sqlite.sql b/src/sql/sqlite.sql new file mode 100644 index 00000000..e69de29b