mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
fix: Docker DB init fails due to pg_restore error on existing database (#129)
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
This commit is contained in:
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,2 +1,5 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
# Auto detect text files and perform LF normalization
|
||||||
* text=auto
|
* text=auto
|
||||||
|
|
||||||
|
# Force LF for shell scripts (prevents CRLF breakage in Docker containers)
|
||||||
|
*.sh text eol=lf
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
echo "INIT!"
|
|
||||||
pg_restore --username="$POSTGRES_USER" --dbname="$POSTGRES_DB" --verbose /schemas/init.sql
|
|
||||||
|
|
||||||
|
|
||||||
|
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!"
|
echo "Updating!"
|
||||||
|
for file in /schemas/update-schema/*; do
|
||||||
for file in /schemas/update-schema/*
|
echo " Applying $file"
|
||||||
do
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f "$file"
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo "Patching!"
|
echo "Patching!"
|
||||||
|
for file in /schemas/patch-schema/*; do
|
||||||
for file in /schemas/patch-schema/*
|
echo " Applying $file"
|
||||||
do
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f "$file"
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file
|
|
||||||
done
|
done
|
||||||
Reference in New Issue
Block a user