mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
pg_restore would fail because the dump contains CREATE DATABASE but POSTGRES_DB already creates it. With set -e this aborted the script before update/patch schemas could run. - Allow pg_restore to continue past non-fatal errors - Add --no-owner --no-acl to avoid permission mismatches - Force LF line endings for .sh files via .gitattributes - Quote file path variables in schema loops
19 lines
642 B
Bash
19 lines
642 B
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
echo "INIT: Restoring database schema..."
|
|
pg_restore --username="$POSTGRES_USER" --dbname="$POSTGRES_DB" --no-owner --no-acl --verbose /schemas/init.sql || {
|
|
echo "WARN: pg_restore exited with errors (this is expected if the database already has objects)"
|
|
}
|
|
|
|
echo "Updating!"
|
|
for file in /schemas/update-schema/*; do
|
|
echo " Applying $file"
|
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f "$file"
|
|
done
|
|
|
|
echo "Patching!"
|
|
for file in /schemas/patch-schema/*; do
|
|
echo " Applying $file"
|
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f "$file"
|
|
done |