#!/bin/sh set -e # Extract host from DATABASE_URL for pg_isready # DATABASE_URL format: postgres://user:pass@host:port/db?params DB_HOST=$(echo "$DATABASE_URL" | sed -n 's/.*@\([^:]*\):.*/\1/p') if [ -z "$DB_HOST" ]; then DB_HOST="postgres" fi # Wait for database to be ready echo "Waiting for database at $DB_HOST..." for i in $(seq 1 30); do if pg_isready -h "$DB_HOST" -U photoplaces -q 2>/dev/null; then echo "Database is ready" break fi if [ $i -eq 30 ]; then echo "Timed out waiting for database" exit 1 fi sleep 2 done # Run migrations echo "Running migrations..." migrate -path /migrations -database "$DATABASE_URL" up # Start application echo "Starting application..." exec /photoplaces-api