"database" sub-command: Provide an exit status

This commit is contained in:
Daniel Friesel 2019-04-13 17:17:44 +02:00
parent ee53b8f37e
commit 4d413d06a3
2 changed files with 6 additions and 1 deletions

View file

@ -68,7 +68,7 @@ or not.
``` ```
git pull git pull
chmod -R a+rX . # only needed if travelynx is running under a different user chmod -R a+rX . # only needed if travelynx is running under a different user
if perl index.pl database has-current-schema | grep -Fq yes; then if perl index.pl database has-current-schema; then
systemctl reload travelynx systemctl reload travelynx
else else
systemctl stop travelynx systemctl stop travelynx

View file

@ -110,6 +110,7 @@ my @migrations = (
sub run { sub run {
my ( $self, $command ) = @_; my ( $self, $command ) = @_;
my $exit_status = 0;
my $dbh = $self->app->dbh; my $dbh = $self->app->dbh;
@ -120,6 +121,7 @@ sub run {
} }
else { else {
$dbh->rollback; $dbh->rollback;
$exit_status = 1;
} }
} }
elsif ( $command eq 'migrate' ) { elsif ( $command eq 'migrate' ) {
@ -134,6 +136,7 @@ sub run {
if ( not $migrations[$i]($dbh) ) { if ( not $migrations[$i]($dbh) ) {
say "Aborting migration; rollback to v${schema_version}"; say "Aborting migration; rollback to v${schema_version}";
$dbh->rollback; $dbh->rollback;
$exit_status = 1;
last; last;
} }
} }
@ -147,6 +150,7 @@ sub run {
} }
else { else {
say "no"; say "no";
$exit_status = 1;
} }
} }
else { else {
@ -155,6 +159,7 @@ sub run {
$dbh->disconnect; $dbh->disconnect;
exit($exit_status);
} }
1; 1;