#!/bin/bash set -e # Database initialization script for PostgreSQL # This script creates the database if it doesn't exist # This runs automatically when PostgreSQL container starts for the first time DB_NAME="${POSTGRES_DB:-financial_data}" DB_USER="${POSTGRES_USER:-postgres}" echo "Initializing database ${DB_NAME}..." # The database is already created by POSTGRES_DB environment variable # We just need to ensure it exists and set up permissions psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL -- Grant all privileges to the postgres user GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER}; -- Connect to the database and set up schema \c ${DB_NAME} -- Create extensions if needed CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; EOSQL echo "Database ${DB_NAME} initialized successfully."