Files
social-media/backend/scripts/start-infrastructure.sh
2025-06-13 02:22:35 -04:00

26 lines
750 B
Bash
Executable File

#!/bin/bash
# Start the container (if not already running)
docker start postgres 2>/dev/null || docker run \
--cap-add SYS_PTRACE \
-e POSTGRES_USER=sa \
-e POSTGRES_PASSWORD='P@ssword123!' \
-p 5432:5432 \
--name postgres \
-d postgres:latest
# Wait until Postgres is ready
echo "Waiting for Postgres to be ready..."
until docker exec postgres pg_isready -U sa > /dev/null 2>&1; do
sleep 1
done
# Create 'hutopy' database if it doesn't exist
echo "Ensuring 'hutopy' database exists..."
docker exec -e PGPASSWORD='P@ssword123!' postgres \
psql -U sa -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='hutopy'" | grep -q 1 || \
docker exec -e PGPASSWORD='P@ssword123!' postgres \
createdb -U sa hutopy
echo "✅ Done."