From 6b8e468073c84a3327744a040a6661afa698fc53 Mon Sep 17 00:00:00 2001 From: Houmgaor Date: Fri, 30 Jan 2026 00:24:39 +0100 Subject: [PATCH] chore(docker): improve init script robustness and ignore db-data - Add file existence checks before iterating schema directories - Add proper quoting for file paths - Add completion message - Ignore docker/db-data/ (PostgreSQL runtime data) --- .gitignore | 5 ++++- docker/init/setup.sh | 30 +++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index ed232319b..b12ad35e9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,7 @@ config.json # Logs logs/ -.env \ No newline at end of file +.env + +# Docker +docker/db-data/ \ No newline at end of file diff --git a/docker/init/setup.sh b/docker/init/setup.sh index ac75dd23f..6fedaa77f 100755 --- a/docker/init/setup.sh +++ b/docker/init/setup.sh @@ -3,20 +3,24 @@ set -e echo "INIT!" pg_restore --username="$POSTGRES_USER" --dbname="$POSTGRES_DB" --verbose /schemas/init.sql - - echo "Updating!" - -for file in /schemas/update-schema/* -do - psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file -done - - +if ls /schemas/update-schema/*.sql 1> /dev/null 2>&1; then + for file in /schemas/update-schema/*.sql + do + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f "$file" + done +else + echo "No update schemas found" +fi echo "Patching!" +if ls /schemas/patch-schema/*.sql 1> /dev/null 2>&1; then + for file in /schemas/patch-schema/*.sql + do + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f "$file" + done +else + echo "No patch schemas found" +fi -for file in /schemas/patch-schema/* -do - psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file -done +echo "Database initialization complete!"