Get rid of dependency to SQLite
SQLite isn't properly supported by Hydra for a few years now[1], but
Hydra still depends on it. Apart from a slightly bigger closure this can
cause confusion by users since Hydra picks up SQLite rather than
PostgreSQL by default if HYDRA_DBI isn't configured properly[2]
[1] 78974abb69
[2] https://logs.nix.samueldr.com/nixos-dev/2020-04-10#3297342;
This commit is contained in:
@ -10,11 +10,7 @@ sub getHydraPath {
|
||||
}
|
||||
|
||||
sub getHydraDBPath {
|
||||
my $db = $ENV{"HYDRA_DBI"};
|
||||
return $db if defined $db;
|
||||
my $path = getHydraPath . '/hydra.sqlite';
|
||||
#warn "The Hydra database ($path) does not exist!\n" unless -f $path;
|
||||
return "dbi:SQLite:$path";
|
||||
return $ENV{"HYDRA_DBI"} || "dbi:Pg:dbname=hydra;";
|
||||
}
|
||||
|
||||
__PACKAGE__->config(
|
||||
|
@ -25,9 +25,8 @@ my @tables = $dbh->tables;
|
||||
if (! grep { /SchemaVersion/i } @tables) {
|
||||
print STDERR "initialising the Hydra database schema...\n";
|
||||
my $schema = read_file(
|
||||
$dbh->{Driver}->{Name} eq 'SQLite' ? "$home/sql/hydra-sqlite.sql" :
|
||||
$dbh->{Driver}->{Name} eq 'Pg' ? "$home/sql/hydra-postgresql.sql" :
|
||||
die "unsupported database type\n");
|
||||
die "unsupported database type $dbh->{Driver}->{Name}\n");
|
||||
my @statements = $sql_splitter->split($schema);
|
||||
eval {
|
||||
$dbh->begin_work;
|
||||
|
@ -79,14 +79,8 @@ create table Jobsets (
|
||||
primary key (project, name),
|
||||
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)
|
||||
#endif
|
||||
);
|
||||
|
||||
#ifdef POSTGRESQL
|
||||
|
||||
create function notifyJobsetSharesChanged() returns trigger as 'begin notify jobset_shares_changed; return null; end;' language plpgsql;
|
||||
create trigger JobsetSharesChanged after update on Jobsets for each row
|
||||
when (old.schedulingShares != new.schedulingShares) execute procedure notifyJobsetSharesChanged();
|
||||
@ -104,9 +98,6 @@ create trigger JobsetSchedulingChanged after update on Jobsets for each row
|
||||
or (old.enabled != new.enabled))
|
||||
execute procedure notifyJobsetSchedulingChanged();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
create table JobsetRenames (
|
||||
project text not null,
|
||||
from_ text not null,
|
||||
@ -157,11 +148,7 @@ create table Jobs (
|
||||
|
||||
|
||||
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
|
||||
|
||||
@ -244,8 +231,6 @@ create table Builds (
|
||||
);
|
||||
|
||||
|
||||
#ifdef POSTGRESQL
|
||||
|
||||
create function notifyBuildsDeleted() returns trigger as 'begin notify builds_deleted; return null; end;' language plpgsql;
|
||||
create trigger BuildsDeleted after delete on Builds execute procedure notifyBuildsDeleted();
|
||||
|
||||
@ -261,8 +246,6 @@ create function notifyBuildBumped() returns trigger as 'begin notify builds_bump
|
||||
create trigger BuildBumped after update on Builds for each row
|
||||
when (old.globalPriority != new.globalPriority) execute procedure notifyBuildBumped();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
create table BuildOutputs (
|
||||
build integer not null,
|
||||
@ -332,11 +315,7 @@ create table BuildStepOutputs (
|
||||
|
||||
-- Inputs of builds.
|
||||
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,
|
||||
@ -502,11 +481,7 @@ create table ReleaseMembers (
|
||||
|
||||
|
||||
create table JobsetEvals (
|
||||
#ifdef POSTGRESQL
|
||||
id serial primary key not null,
|
||||
#else
|
||||
id integer primary key autoincrement not null,
|
||||
#endif
|
||||
|
||||
project text not null,
|
||||
jobset text not null,
|
||||
@ -577,11 +552,7 @@ create table UriRevMapper (
|
||||
|
||||
|
||||
create table NewsItems (
|
||||
#ifdef POSTGRESQL
|
||||
id serial primary key not null,
|
||||
#else
|
||||
id integer primary key autoincrement not null,
|
||||
#endif
|
||||
contents text not null,
|
||||
createTime integer not null,
|
||||
author text not null,
|
||||
@ -614,7 +585,6 @@ create table FailedPaths (
|
||||
path text primary key not null
|
||||
);
|
||||
|
||||
#ifdef POSTGRESQL
|
||||
|
||||
-- Needed because Postgres doesn't have "ignore duplicate" or upsert
|
||||
-- yet.
|
||||
@ -622,7 +592,6 @@ create rule IdempotentInsert as on insert to FailedPaths
|
||||
where exists (select 1 from FailedPaths where path = new.path)
|
||||
do instead nothing;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
create table SystemStatus (
|
||||
@ -639,7 +608,6 @@ create table NrBuilds (
|
||||
|
||||
insert into NrBuilds(what, count) values('finished', 0);
|
||||
|
||||
#ifdef POSTGRESQL
|
||||
|
||||
create function modifyNrBuildsFinished() returns trigger as $$
|
||||
begin
|
||||
@ -658,8 +626,6 @@ create trigger NrBuildsFinished after insert or update or delete on Builds
|
||||
for each row
|
||||
execute procedure modifyNrBuildsFinished();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
-- Some indices.
|
||||
|
||||
@ -704,7 +670,6 @@ create index IndexJobsetEvalsOnJobsetId on JobsetEvals(project, jobset, id desc)
|
||||
|
||||
create index IndexBuildsOnNotificationPendingSince on Builds(notificationPendingSince) where notificationPendingSince is not null;
|
||||
|
||||
#ifdef POSTGRESQL
|
||||
-- The pg_trgm extension has to be created by a superuser. The NixOS
|
||||
-- module creates this extension in the systemd prestart script. We
|
||||
-- then ensure the extension has been created before creating the
|
||||
@ -721,4 +686,3 @@ exception when others then
|
||||
raise warning 'HINT: Temporary provide superuser role to your Hydra Postgresql user and run the script src/sql/upgrade-57.sql';
|
||||
raise warning 'The pg_trgm index on builds.drvpath has been skipped (slower complex queries on builds.drvpath)';
|
||||
end$$;
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user