For schema upgrades, hydra-init executes the files src/sql/upgrade-<N>.sql, each of which upgrades the schema from version N-1 to N. The upgrades are wrapped in a transaction.
AMFMXR52JXHUOWWG4VZ5DHQGLF4F7H7XSJRLX5XNEXOCCWYLDQOAC
AIEKRM6TQFURIZESUF57IQYO5RXFRBL7SOFSCX72CVKUN3UKK3DAC
CFZ6WDUZK3WTKJJLLXVS5MATNP7WCMKHAXKBCTO6OM6CDTQBKBTQC
TH674WKJECNZ4K22DZ2N4SF53UGKG2BQRGBSNESRPDRSRND6TZHAC
46Z25UHSGPWEF7QSXODHKNGRHWEYX5JOCCZYI67S2NJTWY5JDN4AC
DXBTGOA4JXRSEZBDKGVJ4QDXCSQZWI5DHTSULWG4APNPOSLF3CDAC
7DWCXNC72OO3M4YGNVV4KM775CUSPBHEFFNMRIA2XAZTQCXYHBRQC
SB2V735VJ2CDHGCXRUA5FOYHDRXQFVOZ3KXC3YKXWRNW6DIX7RXQC
GYPHTT4MZS75JYMQES2DZPV2D47EJW5HTQWYWDYXE7YJ6FFHPAYAC
SAFVRDTKKD25U6VW5IVNUILLLXNQXFU72XARYC6NRVXU6MJEW2WAC
DO432JDJH2NWZC6AMN7PG6WYD2Y26U6O54GDMBEVBQTZEVNKBN5QC
BQYE6R7YVBXS72FXT4WJFXJ2KARTW2V65TVSTFGCE5TK2BL3ZQVAC
HSVVEKTY2U5XJ4ZDHF43YEQXRPRWNZLZDDD4W7JFJ55UWD7CEFBQC
OG7BEM57MXPCG56IT5GODPFG77KZXWPXZ7OVZPWQQ56CRJ7KUE2QC
QUTWJR7PQZ3DBPC4G2AFXOKPPGFZQLE5RLXHAOFTLMXIT2QPF4TQC
CXRCPDSQEWHSZNCJIORUAINH5I2FFFQ7AVUQOB62REGROLROPE7QC
YFPZ46YK4BOI6VH2H3F757UEGEYONURUAEDAYEIBLRY33PLSSO4AC
BKOIYITRBRVU4D7XFAZPV5QHAPCBMIO3SBNHYJ6TVT43WR32CTHQC
6XJH4OFLFN6PC5FXKMHS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ie
perlPackages.CatalystPluginAccessLog
perlPackages.CatalystAuthenticationStoreDBIxClass
perlPackages.CatalystViewTT
perlPackages.DataDump
perlPackages.JSONXS
perlPackages.DateTime
perlPackages.DigestSHA1
perlPackages.CryptRandPasswd
perlPackages.TestMore
perlPackages.SysHostnameLong
perlPackages.CatalystDevel
perlPackages.Readonly
perlPackages.SQLSplitStatement
createdb hydra
echo "CREATE USER hydra WITH PASSWORD '<your-password>' ;" | psql hydra
cat $prefix/share/hydra/sql/hydra-postgresql.sql | psql hydra
echo "GRANT ALL ON DATABASE hydra TO hydra;" | psql hydra</screen>
createuser -S -D -R -P hydra
createdb -O hydra hydra</screen>
For SQLite, the following command is all it takes to create the
database:
Hydra uses an environment variable to know which database should
be used, and a variable which point to a location that holds
some state. To set these variables for a PostgreSQL database,
add the following to the file <filename>~/.profile</filename> of
the user running the Hydra services.
cat $prefix/share/hydra/sql/hydra-sqlite.sql | sqlite3 /path/to/hydra.sqlite</screen>
export HYDRA_DBI="dbi:Pg:dbname=hydra;host=dbserver.example.org;user=hydra;"
export HYDRA_DATA=/var/lib/hydra</screen>
You can provide the username and password in the file
<filename>~/.pgpass</filename>, e.g.
<screen>
dbserver.example.org:*:hydra:hydra:password</screen>
Make sure that the <emphasis>HYDRA_DATA</emphasis> directory
exists and is writable for the user which will run the Hydra
services. For a SQLite database, the
<varname>HYDRA_DBI</varname> should be set to something like
<literal>dbi:SQLite:/path/to/hydra.sqlite</literal>
<para>
Hydra uses an environment variable to know which database should
be used, and a variable which point to a location that holds
some state. To set these variables for a PostgreSQL database,
add the following to the <filename>.profile</filename> of the
user running the Hydra services.
</section>
<section>
<title>Upgrading</title>
Make sure that the <emphasis>HYDRA_DATA</emphasis> directory
exists and is writable for the user which will run the Hydra
services. For a SQLite database, the
<varname>HYDRA_DBI</varname> should be set to something like
<literal>dbi:SQLite:/path/to/hydra.sqlite</literal>
</para>
#! /var/run/current-system/sw/bin/perl -w
use strict;
use Hydra::Schema;
use Hydra::Helper::Nix;
use File::Slurp;
use SQL::SplitStatement;
use List::Util qw(max);
my $db = openHydraDB;
my $dbh = $db->storage->dbh;
$dbh->{RaiseError} = 1;
my $home = getHydraHome;
my $sql_splitter = SQL::SplitStatement->new;
# Figure out the target schema version.
my $maxSchemaVersion = max (map { /.*\/upgrade-(\d.*)\.sql/; $1 } (glob "$home/sql/upgrade-[0-9]*.sql")) || 1;
# Check whether the database has been initialised. If not, load the
# schema.
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");
my @statements = $sql_splitter->split($schema);
eval {
$dbh->begin_work;
$dbh->do($_) foreach @statements;
$db->resultset('SchemaVersion')->create({version => $maxSchemaVersion});
$dbh->commit;
};
die "schema initialisation failed: $@\n" if $@;
exit 0;
}
# Get the current schema version.
my @versions = $db->resultset('SchemaVersion')->all;
die "couldn't get Hydra schema version!" if scalar @versions != 1;
my $schemaVersion = $versions[0]->version;
for (my $n = $schemaVersion; $n < $maxSchemaVersion; $n++) {
my $m = $n + 1;
print STDERR "upgrading Hydra schema from version $n to $m\n";
my $schema = read_file("$home/sql/upgrade-$m.sql");
my @statements = $sql_splitter->split($schema);
eval {
$dbh->begin_work;
$dbh->do($_) foreach @statements;
$db->resultset('SchemaVersion')->update({version => $m});
$dbh->commit;
};
die "schema upgrade failed: $@\n" if $@;
}