dataflow/setup.sh

70 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
#
# Dataflow Setup Script
# Quick setup for development
#
set -e
echo "🚀 Dataflow Setup"
echo "================="
echo ""
# Check if .env exists
if [ ! -f .env ]; then
echo "📝 Creating .env from template..."
cp .env.example .env
echo "⚠️ Please edit .env with your database credentials"
echo ""
read -p "Press enter to continue after editing .env..."
fi
# Load .env
export $(cat .env | grep -v '^#' | xargs)
# Install dependencies
echo "📦 Installing Node.js dependencies..."
npm install
echo ""
# Test database connection
echo "🔍 Testing database connection..."
if psql -U "$DB_USER" -h "$DB_HOST" -p "$DB_PORT" -d postgres -c '\q' 2>/dev/null; then
echo "✓ PostgreSQL connection successful"
else
echo "✗ Cannot connect to PostgreSQL"
echo " Please check your database credentials in .env"
exit 1
fi
# Create database if it doesn't exist
echo ""
echo "🗄️ Checking database..."
if psql -U "$DB_USER" -h "$DB_HOST" -p "$DB_PORT" -lqt | cut -d \| -f 1 | grep -qw "$DB_NAME"; then
echo "✓ Database '$DB_NAME' exists"
else
echo "Creating database '$DB_NAME'..."
psql -U "$DB_USER" -h "$DB_HOST" -p "$DB_PORT" -d postgres -c "CREATE DATABASE $DB_NAME;"
echo "✓ Database created"
fi
# Deploy schema
echo ""
echo "📋 Deploying database schema..."
psql -U "$DB_USER" -h "$DB_HOST" -p "$DB_PORT" -d "$DB_NAME" -f database/schema.sql
echo "✓ Schema deployed"
echo ""
echo "⚙️ Deploying database functions..."
psql -U "$DB_USER" -h "$DB_HOST" -p "$DB_PORT" -d "$DB_NAME" -f database/functions.sql
echo "✓ Functions deployed"
echo ""
echo "✅ Setup complete!"
echo ""
echo "Next steps:"
echo " 1. Start the server: npm start"
echo " 2. Test the API: curl http://localhost:$API_PORT/health"
echo " 3. Follow the guide: examples/GETTING_STARTED.md"
echo ""