Affinity Design
Agency Guide

Data Migrations & Troubleshooting

Running data migrations, diagnosing issues, and resolving common platform problems

Overview

Platform updates sometimes require data migrations to update existing records, add new fields, or restructure data. This page covers how to run migrations, diagnose common issues, and access support resources.

Running Migrations

Migration Scripts

Migrations are stored in scripts/migrations/ and named by date and feature:

# List available migrations
ls scripts/migrations/

# Run a specific migration
node scripts/migrations/2026-05-02-meta-ads-foundation.js

# Run the billing engine test suite
node scripts/test-billing-engine.mjs

# Run agent phase tests
node scripts/test-agent.js --phase 34   # Google Ads
node scripts/test-agent.js --phase 35   # Meta Ads

Pre-Migration Checklist

  1. Backup the database — always create a snapshot before running migrations
  2. Test in staging — run migrations against a test environment first
  3. Check dependencies — some migrations require specific env vars to be set
  4. Schedule downtime — warn users if the migration causes service interruption
  5. Verify post-migration — run the associated test suite after completion

Never run untested migrations directly against production. Always validate in a staging environment first.

Common Issues

Authentication & Access

IssueResolution
Admin login failsVerify credentials and check that the admin user exists with isActive: true
API returns 403The user's role may not have the required permission — check RBAC settings
OAuth callback failsVerify the redirect URI matches exactly (including protocol and trailing slashes)
Token refresh failsCheck that OAuth client ID and secret match the original app that issued the tokens

Integrations

IssueResolution
GHL sync not workingVerify the OAuth token is valid and the GHL location is connected
Google Ads "DEVELOPER_TOKEN_NOT_APPROVED"Check the token's access level in the API Center
Meta webhook 403Verify token doesn't match META_WEBHOOK_VERIFY_TOKEN
WordPress connection dropsCheck REST API credentials and that the site is accessible

Voice Agents

IssueResolution
Agent not answering callsVerify the phone number is assigned and the agent is active
Calls dropping immediatelyCheck the agent's prompt configuration and provider settings
No recording availableVerify Twilio recording settings and the recording-status webhook
SMS not sendingConfirm SMS capabilities are enabled on the phone number

Billing

IssueResolution
Invoices not generatingVerify Stripe keys are set and the billing scheduler is running
Catalog sync driftUse the Resync action on products showing drift or error status
Ledger totals incorrectRun charge reconciliation to repair mirrors and ledger drift
Webhook not processingCheck Stripe webhook delivery status in the Stripe Dashboard

SEO Agent

IssueResolution
Agent returns noneNo executable action available — check action context via the API
Campaign stuck in runningWorker may have lost the lease — check heartbeat timestamps
Blog drafts not appearingVerify the WordPress connection and website execution are working
Keyword ideas not picked upCheck priority and scheduling metadata — future-dated ideas are held until due

Diagnostic Commands

# Check platform status
GET /status

# Verify a client's integration connections
GET /admin/clients/:clientId

# Check SEO agent runtime state
GET /admin/seo/agents/:agentId/runtime

# Verify Google Ads connection
GET /admin/google-ads/connections/:connectionId

# Test landing page attribution
GET /lp-api/:slug

Getting Support

For issues not covered here:

  1. Check the audit logs for detailed error context
  2. Review the relevant agent or integration documentation
  3. Run the diagnostic commands above and note the output
  4. Contact the platform team with the error details and relevant log entries

Environment Variables Reference

Key environment variables that affect platform behavior:

VariablePurpose
STRIPE_SECRET_KEYStripe API authentication
STRIPE_WEBHOOK_SECRETStripe webhook verification
GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRETGoogle OAuth
GOOGLE_ADS_DEVELOPER_TOKENGoogle Ads API access
META_SYSTEM_USER_TOKENMeta Graph API access
CF_R2_BUCKETClient asset storage
CF_AI_GATEWAY_SLUGAI model routing
REDIRECT_URLShort link base URL

On this page