refactor(database): improve database initialization and backup handling
- Rename init script from init.sh to 00_init.sh for better ordering - Rewrite database initialization script to support backup restoration - Add proper migration handling with schema_migrations table - Fix indentation and quoting issues in docker-compose.yml - Remove old 00-init-db.sh script as it's replaced by new implementation
This commit is contained in:
@@ -101,7 +101,7 @@ services:
|
||||
target: /docker-entrypoint-initdb.d/migrations
|
||||
consistency: cached
|
||||
- type: bind
|
||||
source: ./worklenz-backend/database/init.sh
|
||||
source: ./worklenz-backend/database/00_init.sh
|
||||
target: /docker-entrypoint-initdb.d/00_init.sh
|
||||
consistency: cached
|
||||
- type: bind
|
||||
@@ -114,12 +114,14 @@ services:
|
||||
elif command -v apk >/dev/null 2>&1; then
|
||||
apk add --no-cache dos2unix
|
||||
fi
|
||||
find /docker-entrypoint-initdb.d -type f -name "*.sh" -exec sh -c "
|
||||
|
||||
find /docker-entrypoint-initdb.d -type f -name "*.sh" -exec sh -c '"'"'
|
||||
for f; do
|
||||
dos2unix \"\$f\" 2>/dev/null || true
|
||||
chmod +x \"\$f\"
|
||||
dos2unix "$f" 2>/dev/null || true
|
||||
chmod +x "$f"
|
||||
done
|
||||
" sh {} +
|
||||
'"'"' sh {} +
|
||||
|
||||
exec docker-entrypoint.sh postgres
|
||||
'
|
||||
db-backup:
|
||||
@@ -136,12 +138,12 @@ services:
|
||||
- ./pg_backups:/pg_backups #host dir for backups files
|
||||
#setup bassh loop to backup data evey 24h
|
||||
command: >
|
||||
bash -c "while true; do
|
||||
sleep 86400;
|
||||
PGPASSWORD=$$POSTGRES_PASSWORD pg_dump -h worklenz_db -U $$POSTGRES_USER -d $$POSTGRES_DB \
|
||||
> /pg_backups/worklenz_db_$(date +%Y-%m-%d_%H-%M-%S).sql;
|
||||
find /pg_backups -type f -name '*.sql' -mtime +30 -delete;
|
||||
done"
|
||||
bash -c "while true; do
|
||||
sleep 86400;
|
||||
PGPASSWORD=$$POSTGRES_PASSWORD pg_dump -h worklenz_db -U $$POSTGRES_USER -d $$POSTGRES_DB \
|
||||
> /pg_backups/worklenz_db_\$(date +%Y-%m-%d_%H-%M-%S).sql;
|
||||
find /pg_backups -type f -name '*.sql' -mtime +30 -delete;
|
||||
done"
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- worklenz
|
||||
|
||||
Reference in New Issue
Block a user