sql: Stop loading SQL if an error occurs

Otherwise we may go ahead and create DBIx classes for a half-loaded schema.
This commit is contained in:
Graham Christensen 2021-01-25 14:37:32 -05:00
parent d0b3f2dac4
commit dc5a0d59c5
No known key found for this signature in database
GPG key ID: FE918C3A98C1030F

View file

@ -1,24 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eux
readonly scratch=$(mktemp -d -t tmp.XXXXXXXXXX) readonly scratch=$(mktemp -d -t tmp.XXXXXXXXXX)
readonly socket=$scratch/socket readonly socket=$scratch/socket
readonly data=$scratch/data readonly data=$scratch/data
readonly dbname=hydra-update-dbix readonly dbname=hydra-update-dbix
function finish { function finish() {
set +e set +e
pg_ctl -D "$data" \ pg_ctl -D "$data" \
-o "-F -h '' -k \"$socket\"" \ -o "-F -h '' -k \"$socket\"" \
-w stop -m immediate -w stop -m immediate
if [ -f "$data/postmaster.pid" ]; then if [ -f "$data/postmaster.pid" ]; then
pg_ctl -D "$data" \ pg_ctl -D "$data" \
-o "-F -h '' -k \"$socket\"" \ -o "-F -h '' -k \"$socket\"" \
-w kill TERM "$(cat "$data/postmaster.pid")" -w kill TERM "$(cat "$data/postmaster.pid")"
fi fi
rm -rf "$scratch" rm -rf "$scratch"
} }
trap finish EXIT trap finish EXIT
@ -33,8 +35,11 @@ pg_ctl -D "$data" \
createdb -h "$socket" "$dbname" 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 \ perl -I ../lib \
-MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:../lib \ -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:../lib \
update-dbix.pl "dbi:Pg:dbname=$dbname;host=$socket" update-dbix.pl "dbi:Pg:dbname=$dbname;host=$socket"