Skip to content

feat(cms): database export/import for non-production environments#517

Open
Kneesal wants to merge 1 commit intomainfrom
feat/cms-database-export-import
Open

feat(cms): database export/import for non-production environments#517
Kneesal wants to merge 1 commit intomainfrom
feat/cms-database-export-import

Conversation

@Kneesal
Copy link
Member

@Kneesal Kneesal commented Mar 23, 2026

Summary

  • Adds a nightly GitHub Actions cron workflow that pg_dumps the production CMS database (excluding admin, auth, upload, and migration tables), gzips the output, and uploads to Railway S3
  • Adds a pnpm data-import script in apps/cms that downloads the backup, decompresses, preprocesses SQL, and restores into a target PostgreSQL database via psql
  • Replaces the gateway GraphQL sync for dev/staging environments — production continues using the existing gateway sync

Key design decisions

  • Atomic restore: DROP SCHEMA + restore SQL are both inside --single-transaction — if restore fails, the DROP rolls back
  • Production safeguard: Import script refuses to run when NODE_ENV=production
  • Railway S3: Uses the existing S3 bucket and RAILWAY_S3_* env var pattern (same as apps/manager)
  • GitHub Actions cron: Runs at 04:00 UTC daily + manual workflow_dispatch trigger
  • Pure logic extracted: data-import-utils.ts for testability, 31 unit tests

Required GitHub Secrets

Before this workflow can run, add these secrets in the repo settings:

  • CMS_DATABASE_URL — production PostgreSQL connection string
  • RAILWAY_S3_ENDPOINT, RAILWAY_S3_REGION, RAILWAY_S3_BUCKET
  • RAILWAY_S3_ACCESS_KEY_ID, RAILWAY_S3_SECRET_ACCESS_KEY

Test plan

  • pnpm test passes in apps/cms (31/31 tests)
  • tsc --noEmit passes (0 errors)
  • Pre-commit hooks (prettier) pass
  • Add GitHub secrets to repo settings
  • Manually trigger workflow via gh workflow run cms-db-export.yml
  • Verify backup appears in S3 at backups/cms-backup.sql.gz
  • Run pnpm data-import against a dev/staging database
  • Verify content data is present after import

🤖 Generated with Claude Code

…ironments

Replace the gateway GraphQL sync for dev/staging with a pg_dump/restore
pipeline. A nightly GitHub Actions cron exports the production CMS database
(excluding admin, auth, upload, and migration tables) to Railway S3. A new
`pnpm data-import` script downloads, decompresses, preprocesses, and restores
the backup into the target database inside a single atomic transaction.

Includes production safeguard (refuses NODE_ENV=production), 31 unit tests
for pure utility functions, and compound engineering solution documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@railway-app
Copy link

railway-app bot commented Mar 23, 2026

🚅 Deployed to the forge-pr-517 environment in forge

Service Status Web Updated (UTC)
@forge/cms ✅ Success (View Logs) Web Mar 23, 2026 at 10:33 pm
2 services not affected by this PR
  • @forge/web
  • @forge/manager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant