Production Setup Requirements
PostgreSQL Database Required
As of PR #128, the operations framework requires PostgreSQL for tracking operations and actions.Why PostgreSQL?
The operations framework was migrated from BigQuery to PostgreSQL for:- Real-time updates: PostgreSQL enables live operation status tracking
- Electric SQL integration: Supports real-time sync to client applications
- Better performance: Row-level operations vs BigQuery batch queries
- Cost efficiency: No per-query costs for operation tracking
Components Requiring PostgreSQL
-
Operations Framework (
src/services/operations-service.ts
)- Tracks user intent and workflow orchestration
- Manages operation lifecycle and status
-
Actions Framework (
src/services/actions-service.ts
)- Tracks external system API calls
- Handles action status and retries
-
Webhook Receiver (
src/services/webhook-receiver-service.ts
)- Processes inbound webhooks from sales agents
- Updates action status based on external system responses
-
ADCP Orchestrator (
src/services/adcp-orchestrator.ts
)- Orchestrates ADCP protocol interactions
- Creates operations and actions for creative sync
Setting Up PostgreSQL for Cloud Run
Option 1: Cloud SQL PostgreSQL (Recommended)
Advantages:- Fully managed by Google Cloud
- Automatic backups and high availability
- Integrates seamlessly with Cloud Run via Unix sockets
- Scales automatically
- Create Cloud SQL instance:
- Create database:
- Run migrations:
- Update Cloud Run service:
Option 2: Neon Serverless PostgreSQL
Advantages:- Serverless: scales to zero when not in use
- Free tier available (0.5 GB storage, 100 compute hours/month)
- Simple connection string setup
- No infrastructure management
- Create Neon project at https://neon.tech
- Get connection string from dashboard
- Run migrations via Neon SQL Editor
- Update Cloud Run:
Option 3: Supabase PostgreSQL
Advantages:- Free tier with 500 MB database
- Built-in API and real-time features
- Good for development and small production workloads
- Create Supabase project at https://supabase.com
- Get connection string from project settings
- Run migrations via Supabase SQL Editor
- Update Cloud Run:
Database Schema Setup
Run the PostgreSQL schema migrations:Environment Variables
Required:DATABASE_URL
: Full PostgreSQL connection string
POSTGRES_HOST
: Database hostPOSTGRES_PORT
: Database port (default: 5432)POSTGRES_USER
: Database userPOSTGRES_PASSWORD
: Database passwordPOSTGRES_DATABASE
: Database name (default: activation_api)
POSTGRES_POOL_MAX
: Maximum pool size (default: 20)POSTGRES_IDLE_TIMEOUT
: Idle connection timeout in ms (default: 30000)POSTGRES_CONNECT_TIMEOUT
: Connection timeout in ms (default: 10000)
Testing PostgreSQL Connection
Test the setup with the health endpoint:Troubleshooting
Error:connect ECONNREFUSED 127.0.0.1:5432
- PostgreSQL is not configured
- Set DATABASEURL or POSTGRES* environment variables
password authentication failed
- Incorrect credentials in DATABASE_URL
- Check password and username
database "activation_api" does not exist
- Database not created
- Run:
CREATE DATABASE activation_api;
relation "operations" does not exist
- Schema migrations not run
- Execute scripts/create-postgres-tables.sql
Migration from BigQuery
If you need to migrate existing operations data from BigQuery to PostgreSQL:- Export BigQuery tables to CSV
- Import into PostgreSQL using
COPY
command - Update any references to old BigQuery tables
docs/BIGQUERY_TO_POSTGRES_MIGRATION.md
for detailed steps.
Other Production Requirements
Required Environment Variables
NODE_ENV=production
PORT=8080
(set automatically by Cloud Run)WORKOS_AUTHKIT_DOMAIN=https://identity.scope3.com
SCOPE3_API_KEY=<api-key>
(for GraphQL backend)GEMINI_API_KEY
(stored in Secret Manager:gemini-api-key
)DATABASE_URL
(PostgreSQL connection string)
Secret Manager
Secrets are injected via Cloud Run secrets configuration:Service Account
Uses default compute service account:<project-number>-compute@developer.gserviceaccount.com
- BigQuery Data Viewer (for campaigns/creatives data)
- Cloud SQL Client (if using Cloud SQL)
- Secret Manager Secret Accessor