#!/bin/bash # Setup database for website monitoring frontend echo "Setting up database..." # Start PostgreSQL service if not running if ! pg_isready -h localhost -p 5432 > /dev/null 2>&1; then echo "Starting PostgreSQL service..." devenv up & sleep 5 fi # Create database and user if they don't exist psql -h localhost -U postgres -c "CREATE DATABASE website_monitoring;" 2>/dev/null || echo "Database already exists" psql -h localhost -U postgres -c "CREATE USER website_monitoring WITH PASSWORD 'password';" 2>/dev/null || echo "User already exists" psql -h localhost -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE website_monitoring TO website_monitoring;" 2>/dev/null # Run the schema setup echo "Running database schema setup..." psql -h localhost -U website_monitoring -d website_monitoring -f setup-database.sql # Add missing column if it doesn't exist echo "Adding missing scheduled_at column..." psql -h localhost -U website_monitoring -d website_monitoring -c "ALTER TABLE scans ADD COLUMN IF NOT EXISTS scheduled_at TIMESTAMPTZ;" echo "Database setup complete!"