../../DOCS/database/operations-and-maintenance.md
Source Summary title: Database Operations and Maintenance description: Operational procedures for Neon persistence, migrations, verification, and rollback st...
Source Summary
--- title: Database Operations and Maintenance description: Operational procedures for Neon persistence, migrations, verification, and rollback status: evolving lastUpdated: 2026-05-08 owner: Engineering --- # Database Operations and Maintenance ## Purpose This runbook defines how database-backed admin persistence and canonical knowledge-backbone storage are
Imported Context
title: Database Operations and Maintenance description: Operational procedures for Neon persistence, migrations, verification, and rollback status: evolving lastUpdated: 2026-05-08 owner: Engineering
Database Operations and Maintenance
Purpose
This runbook defines how database-backed admin persistence and canonical knowledge-backbone storage are operated and maintained in this repository.
Scope
- Admin persistence backend: Neon/Postgres
- Canonical public knowledge backbone (Neon/Postgres)
- Tables:
admin_content_stateadmin_historyadmin_migrationskb_entitieskb_entity_tagskb_edgeskb_media_objectskb_media_derivativeskb_workflowskb_workflow_stepskb_provenance_runskb_entity_sources
- One-off operational data migrations (for example Blob -> Neon)
Source of Truth Policy
- Production canonical backend is
neon(ADMIN_STORAGE_BACKEND=neon). fileandblobare fallback or migration-source backends, not primary production write targets.- All migration execution metadata must be persisted in
admin_migrations. - Production knowledge-backbone data is canonical for public content review unless an active project explicitly approves otherwise.
- Local knowledge-backbone data is a review/development mirror by default. Production-to-local refreshes must export both environments before mutating local, verify expected production markers, and avoid production writes unless separately approved.
- Intake-output repair work must use isolated fixtures or explicitly approved non-production targets until its data contract is revalidated.
Ownership and Change Control
- Owner: Engineering
- Every database-affecting change must include:
- migration script (or explicit statement that no migration is needed)
- docs update in
DOCS/database/and/orDOCS/development/migrations.md - changelog entry
- project checkpoint update in active project doc
Migration Storage and Naming
- Script folder:
scripts/migrations/ - Naming format:
YYYYMMDD_<project-number>_<source>_to_<target>_<short-purpose>.mjs
- Current reference:
scripts/migrations/20260211_1002_blob_to_neon_admin_state.mjs
Operations Scripts
- Script details:
scripts/ops/README.md - Post-deploy parity check:
npm run ops:parity:postdeploy- required env:
ADMIN_PASSWORD
- Neon backup/restore drill:
npm run ops:neon:backup-restore-drill- required env:
DATABASE_URL(orPOSTGRES_URL) - optional env:
BACKUP_OUTPUT_PATH
- Blob fallback verification:
npm run ops:blob:fallback-verify- required env:
BLOB_READ_WRITE_TOKEN - optional env:
ADMIN_BLOB_PREFIX,DATABASE_URLfor Neon parity check
- Knowledge drift verification:
npm run ops:knowledge:drift- required env:
DATABASE_URL(orPOSTGRES_URL) - compares legacy constellation payload versus DB-backed
kb_*graph parity
- Release-gated checks:
npm run ops:release-gate- default: parity check enabled, drill/fallback/knowledge drift opt-in
- optional env:
RUN_OPS_PARITY=falseRUN_OPS_NEON_DRILL=trueRUN_OPS_BLOB_FALLBACK=trueRUN_OPS_KNOWLEDGE_DRIFT=true
Required Migration Safeguards
Each migration script must implement:
- Dry-run by default.
- Explicit apply flag (
--apply) for writes. - Idempotency guard (no silent re-runs).
- Precondition checks on target state.
- Transactional writes where possible.
- Migration ledger write to
admin_migrations. - Structured summary output (counts, hash, mode).
Standard Procedure: Run a Migration
1) Preflight
- Confirm project is linked to correct Vercel project:
cat .vercel/project.json
- Pull target environment variables:
npx vercel env pull /tmp/hyphenomenon.env --environment production
- Confirm required vars:
DATABASE_URLorPOSTGRES_URL- source backend credentials (for Blob migrations:
BLOB_READ_WRITE_TOKEN)
2) Dry-run
- Export required env vars into shell.
- Run dry-run command:
npm run migrate:blob-to-neon:dry-run
- Verify:
- source counts are expected
- target pre-migration counts are expected
- payload hash is present
For knowledge backbone rollout:
npm run migrate:kb-schema:dry-runnpm run migrate:kb-backfill:dry-run
3) Apply
- Execute:
npm run migrate:blob-to-neon:apply
- Confirm output:
- post-migration counts
- migration timestamp
For knowledge backbone rollout:
npm run migrate:kb-schema:applynpm run migrate:kb-backfill:apply
4) Verify
- Verify Neon tables:
admin_content_staterow countadmin_historyrow count
- Verify migration ledger:
- migration name exists in
admin_migrations - payload hash recorded
- migration name exists in
- Verify live API behavior:
GET /api/constellationresponse shape and expected metadata (for example domains)
Drift Detection and Health Checks
Per Deployment
- Verify Vercel env values by target:
ADMIN_STORAGE_BACKEND=neonDATABASE_URLpresent
- Verify production deployment is ready (
npx vercel ls/npx vercel inspect <deployment>).
Weekly or After Material Admin Edits
- Query Neon row counts for:
admin_content_stateadmin_historyadmin_migrations
- Spot check
/api/constellationand admin overview counts for expected parity.
Rollback and Recovery Procedure
If Neon behavior regresses or migration output is incorrect:
- Stabilize writes:
- switch
ADMIN_STORAGE_BACKENDto known-good fallback (blob) in target environments. - redeploy so environment snapshot is applied.
- switch
- Recover state:
- restore from known source via migration script (force mode only with explicit intent).
- Audit:
- record rollback details in project checkpoint and changelog.
- Return to Neon:
- verify corrected state, then switch backend back to
neonand redeploy.
- verify corrected state, then switch backend back to
Documentation Maintenance
- Keep this runbook aligned with actual scripts in
scripts/migrations/. - Add each new migration to:
DOCS/database/index.md- changelog
- project checkpoint log
Latest Verified Drill Record
- Verification window: 2026-02-11 14:38-14:40 ET (America/New_York)
- Post-deploy parity check:
- status: pass
- key checks: nodes/edges counts aligned, domains aligned, build/notes node counts aligned, edge endpoint integrity valid
- Neon backup/restore drill:
- status: pass
- source/restored rows:
admin_content_state=1,admin_history=1 - canonical hash match:
01bf99456bd9b848826c54a401015b8d6285277c45f4bbe89be89bad4017db6a
- Blob fallback verification:
- status: pass
- canonical parity hash match:
- blob:
a4c7da177d89d5094e8f7c950ee5578f97a422a4645ce4ca591c87b015f28668 - neon:
a4c7da177d89d5094e8f7c950ee5578f97a422a4645ce4ca591c87b015f28668
- blob:
Provenance
- Source file:
../../DOCS/database/operations-and-maintenance.md - Source URL: https://github.com/maggielerman/hyphenomenon/blob/main/DOCS/database/operations-and-maintenance.md