ea6c466c6c
- Add init_database() with alembic programmatic API and retry logic - Add connection retry with exponential backoff (5 attempts) - Improve error messages for connection/auth failures - Add table existence check before seeding data - Update startup event to run migrations before seeding - Add wait-for-db.sh script for Docker containers - Update Docker and docker-compose configurations Quality gates: ruff ✓, mypy ✓, unit tests (8 passed)
26 lines
669 B
Bash
Executable File
26 lines
669 B
Bash
Executable File
#!/bin/sh
|
|
# wait-for-db.sh - Wait for PostgreSQL to be ready
|
|
|
|
set -e
|
|
|
|
host="${POSTGRES_HOST:-postgres}"
|
|
port="${POSTGRES_PORT:-5432}"
|
|
max_attempts="${DB_MAX_ATTEMPTS:-30}"
|
|
wait_seconds="${DB_WAIT_SECONDS:-2}"
|
|
|
|
echo "Waiting for database at ${host}:${port}..."
|
|
|
|
attempt=1
|
|
while ! nc -z "${host}" "${port}"; do
|
|
if [ "${attempt}" -ge "${max_attempts}" ]; then
|
|
echo "ERROR: Database not available after ${max_attempts} attempts. Exiting."
|
|
exit 1
|
|
fi
|
|
echo " Attempt ${attempt}/${max_attempts}: Database not ready yet, waiting ${wait_seconds}s..."
|
|
sleep "${wait_seconds}"
|
|
attempt=$((attempt + 1))
|
|
done
|
|
|
|
echo "Database is ready!"
|
|
exec "$@"
|