36 lines
929 B
Bash
Executable File
36 lines
929 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Setup Virtual Banker Database
|
|
# This script runs all database migrations
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
DB_DIR="$PROJECT_ROOT/database/migrations"
|
|
|
|
# Load environment variables
|
|
if [ -f "$PROJECT_ROOT/.env" ]; then
|
|
export $(cat "$PROJECT_ROOT/.env" | grep -v '^#' | xargs)
|
|
fi
|
|
|
|
# Set defaults
|
|
export PGHOST="${PGHOST:-localhost}"
|
|
export PGPORT="${PGPORT:-5432}"
|
|
export PGUSER="${PGUSER:-explorer}"
|
|
export PGPASSWORD="${PGPASSWORD:-changeme}"
|
|
export PGDATABASE="${PGDATABASE:-explorer}"
|
|
|
|
echo "Running database migrations..."
|
|
|
|
# Run migrations in order
|
|
for migration in "$DB_DIR"/*.up.sql; do
|
|
if [ -f "$migration" ]; then
|
|
echo "Running $(basename $migration)..."
|
|
PGPASSWORD="$PGPASSWORD" psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDATABASE" -f "$migration"
|
|
fi
|
|
done
|
|
|
|
echo "Database setup complete!"
|
|
|