LifeMate — Personal, Family & Learning Companion
docs: add Cloudflare Neon migration runbook
davoodmehraban89 committed
Oct 7, 2026 at 09:04 UTC
7a83ca86e72ef8f2c022188c860f9add4dc595c9
1 file changed
+48
docs/operations/CLOUDFLARE_NEON_MIGRATION.md
new
+48
@@ -0,0 +1,48 @@
1
+# Cloudflare Workers + Neon PostgreSQL migration
2
+
3
+## Target
4
+Life Guide clients -> Cloudflare Workers API -> Neon PostgreSQL. Railway remains rollback-only until the new path passes staging verification.
5
+
6
+## Required secrets
7
+Configure these as Cloudflare Worker secrets, never client variables:
8
+- NEON_DATABASE_URL: pooled Neon PostgreSQL connection string with TLS.
9
+- JWT_SECRET: existing production JWT signing secret, minimum 32 characters.
10
+- RESEND_API_KEY when transactional email is enabled.
11
+
12
+Configure CORS_ORIGINS, PUBLIC_APP_URL and EMAIL_FROM as environment variables appropriate to the deployed application.
13
+
14
+## Database migration
15
+1. Freeze schema-changing deployments during cutover.
16
+2. Create a Neon project/database and obtain the pooled PostgreSQL connection string.
17
+3. Take a fresh Railway PostgreSQL backup with pg_dump in custom format.
18
+4. Restore into Neon with pg_restore.
19
+5. Run the repository migrations against Neon and verify all migrations are applied.
20
+6. Compare critical row counts and constraints for identity, profiles, families, memberships, guardians, sessions, planner, school, learning and wellbeing data.
21
+7. Keep the Railway database intact and read-only/rollback-capable until acceptance checks pass.
22
+
23
+Example operator commands (credentials supplied securely by the operator):
24
+
25
+ pg_dump --format=custom --no-owner --no-acl "$RAILWAY_DATABASE_URL" > lifeguide-cutover.dump
26
+ pg_restore --clean --if-exists --no-owner --no-acl --dbname "$NEON_DATABASE_URL" lifeguide-cutover.dump
27
+ DATABASE_URL="$NEON_DATABASE_URL" npm run migrate
28
+
29
+## Cloudflare Workers deployment
30
+The Worker entrypoint is backend/src/worker.js and deployment configuration is backend/wrangler.jsonc. It reuses the existing Express API through Cloudflare's Node HTTP server adapter. PostgreSQL remains behind the server API; no database credentials are exposed to Flutter or the PWA.
31
+
32
+Before deployment set Worker secrets NEON_DATABASE_URL and JWT_SECRET. Use the existing JWT secret during migration so valid sessions are not invalidated solely by infrastructure cutover.
33
+
34
+## Acceptance checks
35
+- /live returns 200.
36
+- /ready returns 200 and database=ready.
37
+- /health returns 200 against Neon.
38
+- Authentication registration/verification/login/refresh/recovery tests pass.
39
+- Family create/invite/guardian authorization tests pass.
40
+- Planner, school, learning, wellbeing and privacy-boundary tests pass.
41
+- PWA and Android staging clients use the Cloudflare API endpoint successfully.
42
+- CORS permits only approved origins.
43
+- Logs contain no database URLs, tokens, passwords or minor-sensitive content.
44
+
45
+## Cutover and rollback
46
+Do not delete Railway before acceptance. Point staging clients to Cloudflare first. After successful end-to-end verification, change production API routing to Cloudflare. Keep Railway available for a defined rollback window. If critical API/database verification fails, restore the previous client/API route to Railway and investigate without modifying the Neon copy destructively.
47
+
48
+Railway removal is the final cleanup step only after the Cloudflare Workers + Neon PostgreSQL path is verified and explicit production cutover approval has been given.