forked from lix-project/hydra
hydra-init: show SQL commands being executed
This commit is contained in:
parent
bf757f687d
commit
80705c8a20
|
@ -25,15 +25,15 @@ my @tables = $dbh->tables;
|
||||||
if (! grep { /SchemaVersion/i } @tables) {
|
if (! grep { /SchemaVersion/i } @tables) {
|
||||||
print STDERR "initialising the Hydra database schema...\n";
|
print STDERR "initialising the Hydra database schema...\n";
|
||||||
my $schema = read_file(
|
my $schema = read_file(
|
||||||
$dbh->{Driver}->{Name} eq 'SQLite' ? "$home/sql/hydra-sqlite.sql" :
|
$dbh->{Driver}->{Name} eq 'SQLite' ? "$home/sql/hydra-sqlite.sql" :
|
||||||
$dbh->{Driver}->{Name} eq 'Pg' ? "$home/sql/hydra-postgresql.sql" :
|
$dbh->{Driver}->{Name} eq 'Pg' ? "$home/sql/hydra-postgresql.sql" :
|
||||||
die "unsupported database type\n");
|
die "unsupported database type\n");
|
||||||
my @statements = $sql_splitter->split($schema);
|
my @statements = $sql_splitter->split($schema);
|
||||||
eval {
|
eval {
|
||||||
$dbh->begin_work;
|
$dbh->begin_work;
|
||||||
$dbh->do($_) foreach @statements;
|
$dbh->do($_) foreach @statements;
|
||||||
$db->resultset('SchemaVersion')->create({version => $maxSchemaVersion});
|
$db->resultset('SchemaVersion')->create({version => $maxSchemaVersion});
|
||||||
$dbh->commit;
|
$dbh->commit;
|
||||||
};
|
};
|
||||||
die "schema initialisation failed: $@\n" if $@;
|
die "schema initialisation failed: $@\n" if $@;
|
||||||
exit 0;
|
exit 0;
|
||||||
|
@ -50,10 +50,15 @@ for (my $n = $schemaVersion; $n < $maxSchemaVersion; $n++) {
|
||||||
my $schema = read_file("$home/sql/upgrade-$m.sql");
|
my $schema = read_file("$home/sql/upgrade-$m.sql");
|
||||||
my @statements = $sql_splitter->split($schema);
|
my @statements = $sql_splitter->split($schema);
|
||||||
eval {
|
eval {
|
||||||
$dbh->begin_work;
|
$dbh->begin_work;
|
||||||
$dbh->do($_) foreach @statements;
|
sub run {
|
||||||
$db->resultset('SchemaVersion')->update({version => $m});
|
my ($stm) = @_;
|
||||||
$dbh->commit;
|
print STDERR "executing SQL statement: $stm\n";
|
||||||
|
$dbh->do($_);
|
||||||
|
}
|
||||||
|
run($_) foreach @statements;
|
||||||
|
$db->resultset('SchemaVersion')->update({version => $m});
|
||||||
|
$dbh->commit;
|
||||||
};
|
};
|
||||||
die "schema upgrade failed: $@\n" if $@;
|
die "schema upgrade failed: $@\n" if $@;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue