#!/bin/bash # Script to set up the PostgreSQL database for the finance application # Prompt for PostgreSQL user to use read -p "Enter PostgreSQL admin username [postgres]: " PG_USER PG_USER=${PG_USER:-postgres} # Prompt for PostgreSQL password read -s -p "Enter PostgreSQL password for $PG_USER: " PG_PASSWORD echo # Check if database exists echo "Checking if database exists..." if PGPASSWORD="$PG_PASSWORD" psql -U "$PG_USER" -h localhost -lqt | cut -d \| -f 1 | grep -qw finance; then echo "Database 'finance' already exists" else echo "Creating database 'finance'..." PGPASSWORD="$PG_PASSWORD" createdb -U "$PG_USER" -h localhost finance if [ $? -ne 0 ]; then echo "Failed to create database. Please check your credentials." exit 1 fi echo "Database 'finance' created successfully" fi # Create .env file with database connection details echo "Creating .env file with database connection info..." cat > .env <