Skip to main content

ElectricSQL Setup Complete ✅

What’s Running

1. PostgreSQL (port 5432)

  • Configured with logical replication (WAL)
  • Contains operations framework tables:
    • operations - Parent operation tracking
    • operation_actions - Individual action steps
    • operation_action_history - Audit trail
    • operations_with_actions - Real-time view with aggregated data

2. ElectricSQL (port 3000)

  • Streaming changes from PostgreSQL via logical replication
  • HTTP API at: http://localhost:3000/v1/shape
  • Configuration:
    • Insecure mode (for development)
    • Direct writes to PostgreSQL enabled
    • PostgreSQL proxy on port 65432

3. Dashboard HTTP Server (port 8080)

Testing Electric Sync

1. Query Operations via Electric API

# Get all operations
curl "http://localhost:3000/v1/shape?table=operations&offset=-1"

# Get operations_with_actions view (includes action details)
curl "http://localhost:3000/v1/shape?table=operations_with_actions&offset=-1"

# Get operation_actions
curl "http://localhost:3000/v1/shape?table=operation_actions&offset=-1"

2. View Real-time Dashboard

Open in your browser:
http://localhost:8080/electric-operations-dashboard.html
The dashboard automatically subscribes to changes and updates in real-time when:
  • New operations are created
  • Operation status changes
  • Actions are added or updated

3. Test Real-time Updates

In one terminal, watch the dashboard. In another terminal:
# Create a test operation
PGPASSWORD=postgres psql -h localhost -U postgres -d activation_api -c "
INSERT INTO operations (
  id, type, status, customer_id, brand_agent_id,
  resource_type, resource_id, instruction, initiated_by, target_state
) VALUES (
  'op_test_electric_' || gen_random_uuid()::text,
  'create',
  'pending',
  123,
  456,
  'media_buy',
  'buy_test_' || gen_random_uuid()::text,
  'Testing Electric real-time sync',
  'manual-test',
  '{\"status\": \"active\"}'
) RETURNING id, status, created_at;
"
You should see the operation appear in the dashboard immediately!

What’s Working

✅ ElectricSQL service running and healthy ✅ PostgreSQL logical replication configured ✅ Operations tables accessible via Electric API ✅ Real-time dashboard subscribing to changes ✅ HTTP server serving dashboard ✅ 30+ existing operations from webhook tests visible

Current Data

Electric is currently syncing 30+ operations from your webhook testing:
  • Mix of creative sync and media buy creation operations
  • All from customer_id=123, brand_agent_id=456
  • Most are in “pending” status
  • Some completed operations visible

Known Issues

Webhook Flow Still Broken

The operations in Electric are from webhook tests that didn’t complete because: Root Cause: Sales agent’s create_media_buy doesn’t insert into object_workflow_mapping table Impact:
  • Media buys created ✅
  • Webhooks registered ✅
  • Workflow steps completed ✅
  • But: No webhook POSTs sent because mapping table is empty ❌
Status: This is a sales agent bug that needs fixing (documented in WEBHOOK_BUG_REPORT.md)

Next Steps

For Dashboard Development

  1. Open dashboard: http://localhost:8080/electric-operations-dashboard.html
  2. Test real-time updates: Create operations via psql and watch them appear
  3. Customize UI: Edit examples/electric-operations-dashboard.html
  4. Add filtering: Dashboard supports customer/status filters

For Production Use

  1. Set ELECTRIC_SECRET: Replace insecure mode with proper JWT authentication
  2. Use PostgreSQL proxy: Connect writes via port 65432 for Electric awareness
  3. Add indexes: Create indexes for common query patterns
  4. Configure TTLs: Set up shape cleanup for old data
  5. Deploy Electric: Run Electric as separate service in production

For Webhook Integration

Once sales agent bug is fixed:
  1. Run npm run test:webhook to create media buys
  2. Watch operations appear in dashboard
  3. See actions update as webhooks arrive
  4. Monitor completion rates in real-time

Files Created

  • docker-compose.yml - Added Electric service with logical replication config
  • scripts/electric-migrations/01_enable_electric_operations.sql - Database migration
  • examples/electric-operations-dashboard.html - Real-time dashboard UI
  • ELECTRIC_SETUP.md - Detailed setup documentation
  • ELECTRIC_READY.md - This file (quick start guide)

Resources

  • Electric API docs: https://electric-sql.com/docs
  • Dashboard code: examples/electric-operations-dashboard.html
  • Setup guide: ELECTRIC_SETUP.md
  • Webhook bug report: WEBHOOK_BUG_REPORT.md

Quick Commands

# Start services
docker-compose up -d

# Check Electric logs
docker logs activation-api-electric -f

# Query operations via Electric
curl "http://localhost:3000/v1/shape?table=operations&offset=-1" | jq

# View dashboard
open http://localhost:8080/electric-operations-dashboard.html

Status: ✅ ElectricSQL is fully operational and ready for real-time operations monitoring!
I