From dc5a0d59c5220bec686484f54730ce061a7cde2a Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Mon, 25 Jan 2021 14:37:32 -0500 Subject: [PATCH] sql: Stop loading SQL if an error occurs Otherwise we may go ahead and create DBIx classes for a half-loaded schema. --- src/sql/update-dbix-harness.sh | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/sql/update-dbix-harness.sh b/src/sql/update-dbix-harness.sh index 38407f82..7f381e9f 100755 --- a/src/sql/update-dbix-harness.sh +++ b/src/sql/update-dbix-harness.sh @@ -1,24 +1,26 @@ #!/usr/bin/env bash +set -eux + readonly scratch=$(mktemp -d -t tmp.XXXXXXXXXX) readonly socket=$scratch/socket readonly data=$scratch/data readonly dbname=hydra-update-dbix -function finish { - set +e - pg_ctl -D "$data" \ - -o "-F -h '' -k \"$socket\"" \ - -w stop -m immediate +function finish() { + set +e + pg_ctl -D "$data" \ + -o "-F -h '' -k \"$socket\"" \ + -w stop -m immediate - if [ -f "$data/postmaster.pid" ]; then - pg_ctl -D "$data" \ - -o "-F -h '' -k \"$socket\"" \ - -w kill TERM "$(cat "$data/postmaster.pid")" - fi + if [ -f "$data/postmaster.pid" ]; then + pg_ctl -D "$data" \ + -o "-F -h '' -k \"$socket\"" \ + -w kill TERM "$(cat "$data/postmaster.pid")" + fi - rm -rf "$scratch" + rm -rf "$scratch" } trap finish EXIT @@ -33,8 +35,11 @@ pg_ctl -D "$data" \ createdb -h "$socket" "$dbname" -psql -h "$socket" "$dbname" -f ./hydra.sql +psql --host "$socket" \ + --set ON_ERROR_STOP=1 \ + --file ./hydra.sql \ + "$dbname" perl -I ../lib \ - -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:../lib \ - update-dbix.pl "dbi:Pg:dbname=$dbname;host=$socket" + -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:../lib \ + update-dbix.pl "dbi:Pg:dbname=$dbname;host=$socket"