Skip to content

Commit bfe1133

Browse files
sgillespiekderme
authored andcommitted
fix(scripts): Abort snapshot restoration on error
* Add `--exit-on-error` * Add `--schema=public` to skip schema creation
1 parent b400c83 commit bfe1133

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

scripts/postgresql-setup.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,23 @@ function restore_snapshot {
194194
lstate_file=$(basename "${lstate_gz_file}" | sed 's/.gz$//')
195195
gunzip --to-stdout "${lstate_gz_file}" > "$2/${lstate_file}"
196196
drop_db
197-
pg_restore --jobs="${numcores}" --format=directory --dbname="${PGDATABASE}" "${tmp_dir}/db/"
197+
198+
# Important: specify --schema=public below to skip over `create schema public`
199+
# statement generated by pg_dump
200+
pg_restore \
201+
--schema=public \
202+
--jobs="${numcores}" \
203+
--format=directory \
204+
--dbname="${PGDATABASE}" \
205+
--exit-on-error \
206+
"${tmp_dir}/db/"
198207
else
199208
# Old snapshot format produced by this script
200209
db_file=$(find "${tmp_dir}/" -iname "*.sql")
201-
lstate_file=$(find "${tmp_dir}/" -iname "*.lstate")
202-
mv "${lstate_file}" "$2"
203-
psql --dbname="${PGDATABASE}" -f "${db_file}"
204-
fi
210+
lstate_file=$(find "${tmp_dir}/" -iname "*.lstate")
211+
mv "${lstate_file}" "$2"
212+
psql --dbname="${PGDATABASE}" --file="${db_file}"
213+
fi
205214
rm "${recursive}" "${tmp_dir}"
206215
}
207216

0 commit comments

Comments
 (0)