Postgres cutover

How production moves from MongoDB to Postgres (the Phase 1 storage move, design note §9), how it is checked at every step, and how it is undone if it has to be. The move is storage only: no behavior changes, and every audit chain and anchor must read the same before and after, except for what the release step writes at the web deploy (see The release step).

Two people run it: the operator, who types every command, and the witness, who reads each result back aloud, checks it against this page and keeps the log. Adam is the accountable owner and the approver: he approves the window, decides every question this page sends to the approver, and is reachable for the whole of it. Nothing below is run alone, and nothing is skipped because the rehearsal passed.

Window: completed 2026-11-17, 14:05 to 14:27 PT (see the record of the run). It was planned for Wednesday 2026-11-25. Adam, as approver, overrode three of the window rules to run it earlier: an Executive Vote within 48 hours, a release the same day, and no two-day booking. The page stays as the procedure for the rollback and for any later move of the same kind.

Preconditions

All of these are true before a window is booked. All were met for the 2026-11-17 run; where a date is recorded with one, that is when it was checked.

Before taking any evidence for them, the witness runs railway deployment list for the web service and the Step Runner: Railway redeploys without announcement, and evidence taken from a deployment that has since been replaced proves nothing about the running one.

  • Postgres is provisioned. The Railway service Postgres (project soter-os, environment production, Postgres 18) exists with daily backups and point-in-time recovery (PITR) explicitly enabled. PITR is not on by default; it was enabled on this service on 2026-11-09. Railway keeps daily backups for 6 days, weekly backups for 27 days and monthly backups for 89 days; that retention was accepted by Adam on 2026-11-17 in place of the 7 days this page used to ask for. The witness confirms both on the day the window is booked: railway postgres pitr status (with the Postgres service linked) reports PITR enabled with its retention, and the service's backup settings in the dashboard show the daily backups. The witness also writes down the "restorable up to" time PITR reports; on 2026-11-17 it trailed the last WAL by about 22 hours, which is a question for Railway, not a stop.
  • The schema is migrated, by a person. npm run db:migrate was run against the production DATABASE_URL of the Postgres service (from a Railway shell on the process-platform service, or locally with the variable exported for that one command) and printed applied 1 engine migration(s); a second run prints the engine schema is up to date. Nothing migrates at startup, and the services refuse to start on a database that is behind, ahead of or different from their build. Met on 2026-11-17. The project has a second Postgres, ontology-postgres, which belongs to the ontology service and is migrated by that service's own pre-deploy command: it is never the target of db:migrate or of the copy (see the service table).
  • The Postgres build is deployed dark. The two services that open a store, the web service process-platform and the Step Runner, run the build that contains the Postgres stores, storage:copy and storage:verify, with STORAGE_DRIVER=mongo still set. The web service's deployment log shows Storage driver: mongo. The Step Runner prints no such line, so for it the witness checks that its deployment is from the same commit as the web service's and that its STORAGE_DRIVER variable is mongo.
  • The web service has run the release step on this build, on Mongo. The web deploy at the window runs the release step against Postgres (see The release step). If the same build has already been deployed on Mongo, everything that step would create already exists and is copied, so the expected delta is zero processes. The current build (#333) was deployed to the web service on 2026-11-17. If the build changes before the window, either it is deployed on Mongo again before the window, or the delta it produces is taken from rehearsal #2 and written down in the booking. Met on 2026-11-17.
  • Two rehearsals passed on fresh production copies, each a complete round trip: a local copy of production Mongo (see The operator service for how to take one: data:pull cannot reach the production database), storage:copy to an empty local Postgres, storage:verify PASS, the app booted on the copy with STORAGE_DRIVER=postgres (no integration credentials, no protected-store keys, so nothing reaches the outside world), a known process read, npm run audit:verify all verified, npm run templates:status and npm run migrations:status equal to their output on the Mongo copy, then the reverse copy into a fresh Mongo database and storage:verify PASS again. The copy and verify times were noted: they size the window. The release step's output on the Postgres copy is noted too: the number of processes it created is the delta used at the window. Met: rehearsal #2 ran on 2026-11-17.
  • The rehearsal surfaced every non-JSON value, and they are gone. The copy refuses any value that is not JSON (a BSON Date, ObjectId, Decimal128, Binary, a regex) with the collection, id and path (BsonValueError). Production can hold such values: the retired remap-automation-actor script carried BSON Dates through unchanged (design note §5), and any other direct mongosh fix may have too. A refusal in rehearsal is the expected way to find them, and it is handled before the window, never in it: the value is corrected on the Mongo side (in production, as a recorded data fix: the equivalent JSON value, usually the ISO string the application itself writes) and, where it sits inside an aggregate whose state the chain covers, followed by npm run audit:correct -- --id <processId> --reason "<why>" --yes --as <you>; then a fresh copy is taken and the rehearsal is run again from the start until the copy refuses nothing. A non-JSON value inside integrity itself (the chain, its events or head) is never patched: it is escalated to Adam, because changing a chain record is exactly what the chain exists to make visible, and the cutover waits for the decision.
  • Daily anchors are landing on the audit-anchors branch. No production service has a write-once anchor store configured (PROCESS_AUDIT_ANCHOR_STORE is unset), so the Step Runner's start log reads [audit-anchor] OFF: …; that line is expected and is not a stop. Anchors are taken instead by a daily job that runs audit:anchor --daily inside the web container with a file store under /tmp/pp-anchors and commits the anchor to the audit-anchors branch of this repository (anchors/daily/<date>.json). The precondition is that the branch holds a daily anchor from each of the last three days. (If a store that writes to the branch directly, such as a github store, is added later, the Step Runner's log then names it, and this page's anchor steps are simplified to audit:anchor with that store.) Met on 2026-11-17.
  • The application has its own Mongo user, and its writes can be revoked and restored. The web service and the Step Runner used to connect as the database's single root user, which cannot be made read-only. They now connect as processos_app, created in admin (its authSource) with readWrite on the process-platform database. Its URL is the MongoDB service's variable PROCESSOS_APP_MONGO_URL, and the two services' MONGO_URL is the reference ${{MongoDB.PROCESSOS_APP_MONGO_URL}}. Revoking writes means changing that user's role to read; restoring them is the reverse (the commands are under Revoke Mongo writes). Both were tested in rehearsal. Spell Risk and Risk Assessment do not move to the new user: nothing in them reads MONGO_URL, and they lose it during the window. The Mongo service stays provisioned and untouched for 7 days after the cutover. Met on 2026-11-17.
  • The root URL is kept where the window can reach it. The MongoDB service's own MONGOUSER and MONGO_INITDB_ROOT_* variables are stale: authentication with them fails. The working root URL is kept as the MongoDB service variable MONGO_ROOT_URL, which the freeze dump and the role changes use. Spell Risk and Risk Assessment held the last other copy of it in their MONGO_URL: it is saved to MONGO_ROOT_URL before MONGO_URL is removed from them. Met on 2026-11-17.
  • main is frozen from the booking until the window closes. The Step Runner and Transaction Studio deploy automatically from main, so a merge during the window would start a new Step Runner deployment with a different build. Spell Risk and the web service do not deploy automatically. No pull request is merged to main from the booking until the announcement that closes the window. Met on 2026-11-17.
  • The operator service exists (see The operator service), with its two variables set, and railway ssh --service cutover-operator reaches it. Met on 2026-11-17.
  • Roles are named in the window booking: operator, witness, approver. Met on 2026-11-17.

Choosing the window

The window is booked at least two working days ahead and meets all of these:

  • A weekday, during hours when both people are at their desks for its whole length plus two hours.
  • At least 48 hours from an Executive Vote in either direction: no spell is in its final review or just executed, so no one is waiting on the app and nothing in it is mid-flight on a deadline.
  • Outside the month-end payment batch: not on the last two or the first three business days of a month.
  • Not during an active cBEAM ramp, when rate changes are being prepared and checked in the app daily.
  • No release is planned for the same day; the build that is deployed dark stays exactly as it is.

If the window is lost (a late Executive Vote, an incident), it is rebooked, not shortened.

The operator service

The copy, verify and rollback commands run on Railway, not on a laptop: the production MongoDB service has no public TCP proxy, so its URL resolves only on the project's private network. That is also why data:pull (and any other laptop command given the production Mongo URL) cannot reach production.

Before the window, the operator creates a temporary service cutover-operator in project soter-os, environment production:

  • built like the Step Runner: source soterlabs/process-platform, the same commit as the dark build, build command npm run build:packages, and no automatic deploys;
  • start command sleep infinity, so it runs nothing on its own and only waits for a shell;
  • exactly two variables: SOURCE_MONGO_URL, the application user's private Mongo URL, and TARGET_DATABASE_URL, a reference to the Postgres service's DATABASE_URL. It has no MONGO_URL, no DATABASE_URL and no other secret, so it cannot start the app or reach anything else.

Commands run on it over railway ssh, through the repository's command runner (the same one npm start uses), for example:

railway ssh --service cutover-operator -- node scripts/run-main.mjs storage:copy --from mongo --to postgres --dry-run

Reports are written in the container's working directory and read back with railway ssh --service cutover-operator -- cat copy.json. The service is deleted after the window. For a rollback it is created again with SOURCE_DATABASE_URL and TARGET_MONGO_URL instead.

The Mongo checks, the role changes and the dump run on the MongoDB service itself, as root, which has mongosh and mongodump: railway ssh --service MongoDB, then mongosh "$MONGO_ROOT_URL". They cannot go through the web container: during the freeze it is down. The same route takes a rehearsal copy and the freeze dump:

railway ssh --service MongoDB -- sh -c 'mongodump --uri "$MONGO_ROOT_URL" --db=process-platform --archive --gzip --quiet' < /dev/null > /absolute/path/prod-<date>.archive.gz
gzip -t /absolute/path/prod-<date>.archive.gz

The output path is absolute: a helper script that changes directory first (such as the operator's dump-prod.sh) otherwise writes the dump somewhere else. The copy is restored into the local Mongo with mongorestore --archive=prod-<date>.archive.gz --gzip --drop.

Taking an anchor

Every anchor on this page is taken the way the daily job takes its own, without --daily, in the web container (the only running container in production that holds both the access policy and the store's URL; the operator service cannot run audit:anchor with its two variables):

railway ssh --service process-platform -- sh -c 'export PROCESS_AUDIT_ANCHOR_STORE=file PROCESS_AUDIT_ANCHOR_DIR=/tmp/pp-anchors; mkdir -p /tmp/pp-anchors && cd /app && node scripts/run-main.mjs audit:anchor'

It prints Anchored N processes: anchors/on-demand/<time>.json, root <root>. The operator prints that file (cat /tmp/pp-anchors/anchors/on-demand/<time>.json in the same container), saves it under the same path in a checkout of the audit-anchors branch, commits it (Cutover anchor A: N processes, root <first 8>) and pushes. The witness reads the key, count and root back from the committed file. The branch is never rewritten.

Stopping and starting a service

A service is stopped by removing its running deployment, and started by deploying it again from source:

railway down -y -s "Step Runner"                         # stop
railway redeploy --from-source -y -s "Step Runner"       # start

railway scale <service> <region>=0 does not stop a service: it redeploys it, and the new deployment keeps running with one instance. On 2026-11-17 both the web service and the Step Runner kept running after it (a shell still reached them and their Mongo connections stayed open). It is not used.

A stopped service has no deployment, so it stays down while its variables change. A variable change does not reliably start a stopped service either, so starting it is always the explicit railway redeploy --from-source. Variables changed during the window are changed with --skip-deploys.

A stop is confirmed, not assumed: the service's deployments list shows nothing running, for the web service its public health URL no longer answers 200 (on 2026-11-17 it answered 404), and Mongo shows no connection for the application user (the writer check below).

Freeze

The aim is a database with no writers, proven, before anything is copied.

  1. Read today's daily anchor. The witness fetches the audit-anchors branch and reads anchors/daily/<today>.json: its count and root are noted. It must exist before the freeze starts.

  2. Announce the freeze in the team channel: start time, expected length, and that the app will be unavailable rather than read-only (there is no maintenance mode; a stopped service is the freeze).

  3. Snapshot the status commands while the app is still on Mongo, in the web container (railway ssh --service process-platform, then from /app): node scripts/run-main.mjs audit:verify, node scripts/run-main.mjs templates:status and node scripts/run-main.mjs migrations:status. The witness keeps all three outputs; audit:verify's N processes: N verified, 0 not chained yet, 0 FAILED is the N the smoke checks compare with, and the same three commands are run on Postgres after the switch.

  4. Stop the Step Runner (the worker) as above: railway down -y -s "Step Runner". Its deployments list shows nothing running. It stays down, with no deployment, until the step that starts it below.

  5. Take anchor A as above, with the web service still up. Its count is the N from the snapshot. This is the state the copy must reproduce.

  6. Stop the web service the same way: railway down -y -s process-platform. Its health URL no longer answers 200. Spell Risk and Risk Assessment may stay up: they proxy to the stopped backend and will show its errors, which is the intended signal.

  7. Confirm Mongo has no writers. From mongosh "$MONGO_ROOT_URL" on the MongoDB service, the application user has no connection at all, idle ones included:

    db.getSiblingDB('admin').aggregate([
      { $currentOp: { allUsers: true, idleConnections: true } },
      { $match: { 'effectiveUsers.user': 'processos_app' } },
    ]).toArray()
    

    returns []. Wait a minute and check again.

  8. Dump Mongo in the MongoDB container as root, over the route under The operator service, to an absolute local path: a size check, gzip -t, and a restore into a throwaway container that counts processes-v2-* documents (the pattern remap-automation-actor.sh used before it was retired). This dump is the rollback of last resort and stays with the operator for 7 days.

Between anchor A and the stop of the web service, a user could still write. If one does, the copy's root will not equal anchor A's (see below). The fix is to start again from step 5: empty the Postgres schema (DROP SCHEMA engine CASCADE; DROP SCHEMA drizzle CASCADE; and db:migrate), start the web service again (railway redeploy --from-source -y -s process-platform, still on Mongo), take anchor A again, stop it again, and repeat the writer check and the dump.

Copy and verify

All three commands run on the operator service, which has only the two dedicated variables. They never read MONGO_URL or DATABASE_URL, never print a connection string, and --confirm-target must be typed as the target's host, so a wrong target is refused before anything is read.

railway ssh --service cutover-operator -- node scripts/run-main.mjs storage:copy   --from mongo --to postgres --dry-run
railway ssh --service cutover-operator -- node scripts/run-main.mjs storage:copy   --from mongo --to postgres --confirm-target <postgres host:port> --report copy.json
railway ssh --service cutover-operator -- node scripts/run-main.mjs storage:verify --from mongo --to postgres --report verify.json

--confirm-target is the host:port of the target URL. When the target is a multi-host mongodb:// URL (a replica set spelled host1:port,host2:port,…, as in the rollback), it is that comma-separated list exactly as the URL spells it; the command prints the host it parsed when it refuses, so a typo is visible.

What each one must show:

  • The dry run lists every collection the production database holds with its count and would copy N, and no note: … is not in the inventory line except the v1 processes and templates collections (legacy). Any other note (an unknown or unnamespaced collection with documents) stops here: find out what it is before going on. The copy refuses to proceed past it without --skip-unknown, which is not used in production without the approver's explicit yes. A source with no collection of the inventory, or none with a record, is refused outright (EmptySourceError): that is a wrong server or database name, and the witness checks the variables before anything else is tried.
  • The copy prints the same counts as copied, then copied N record(s) in M collection(s). It refuses a target that holds any row, a schema that is not this build's, and any value that is not JSON (BsonValueError naming the collection, id and path). A refusal writes nothing (the copy is one transaction). A BsonValueError here means a value the rehearsal did not see: the window is over (the record is fixed as the preconditions describe, and the cutover is rebooked), never worked around in the copy.
  • Verify prints storage:verify mongo-to-postgres: PASS, every collection ok, the audit line ok audit chains … root matches, and the templates line. The witness compares audit[0].sourceRoot in verify.json with the root of anchor A as committed on the branch: they are the same string. (The root is the anchor root over every (processId, head, events); equality proves the whole set of chains carried over.) A different root means a write landed after anchor A: go back to the Freeze as it describes. A FAIL stops the cutover; the report names every differing id. Verify also fails, by design, when it compared no record, when the source holds no process, or when Mongo holds an unknown or unnamespaced collection with documents (data the target does not carry); a legacy v1 collection is only a note.

Expected timing: on the rehearsal copy the production-sized database copies in seconds and verifies in under a minute; budget ten minutes for the three commands and the comparison.

Revoke Mongo writes

Before any service starts on Postgres, Mongo must be unable to take a write, so that nothing can ever be written to both stores and the frozen database stays exactly the state anchor A and the copy describe.

  1. Revoke write access for the application user: from mongosh "$MONGO_ROOT_URL" on the MongoDB service,

    db.getSiblingDB('admin').updateUser('processos_app', { roles: [{ role: 'read', db: 'process-platform' }] })
    

    It takes effect at once, on open connections too. Mongo itself stays running, untouched, for 7 days.

  2. Prove it: connected as the application user (mongosh "$PROCESSOS_APP_MONGO_URL" on the same service), an insertOne into a scratch probe collection is refused (not authorized), a find on processes-v2-* still works, and afterwards the probe collection does not exist (db.getCollectionNames() does not list it).

Restoring writes is the same command with role: 'readWrite'.

Undoing this step (the readWrite role back) is the whole of the rollback until the first process write to Postgres by a user or the worker; see Rollback.

Switch the services

The rule for which services change is mechanical, and the operator proves it during the window rather than trusting this page: a Railway service moves to Postgres when its start command runs this repository's npm start (with or without npm run release && in front) or npm run job:step. Those are the web service and the Step Runner; no other service opens a store. The operator lists every service in project soter-os, environment production (railway service list, or the project canvas), reads each one's start command (service settings; a service with the default command runs npm start when built from this repository), and ticks it off against the table below. A service not in the table whose start command matches is added to the moving rows before anything is changed. As of 2026-11-17 the list is (save MONGO_ROOT_URL first: see the preconditions):

ServiceStart commandChange
process-platform (web)npm run release && npm startSet STORAGE_DRIVER=postgres; set DATABASE_URL to a reference to the Postgres service's DATABASE_URL; remove MONGO_URL.
Step Runner (worker)npm run job:stepThe same three changes.
Spell Risk, Risk Assessmenttheir own (a frontend)Nothing to add. These frontends only proxy to the backend (PROCESS_BACKEND_ORIGIN) and never open a store, so they get no DATABASE_URL. They currently carry MONGO_URL with STORAGE_DRIVER unset, which nothing in them reads: remove MONGO_URL from both during the window, so no service keeps a Mongo credential it does not use.
Postgres(the database)Nothing.
ontologyits own (the ontology API)Nothing. Its pre-deploy command migrates ontology-postgres, its own database; nothing in this cutover points at it, and its DATABASE_URL is never used for db:migrate or the copy.
ontology-postgres(the database)Nothing.
MongoDB(the database)Nothing beyond the revoked role. It stays provisioned and untouched for 7 days.
cutover-operatorsleep infinityNothing during the window; deleted after it.

Change the variables with --skip-deploys. The worker must not run before the web smoke checks pass. The Step Runner has no deployment since the freeze, so its variable changes cannot start it; the witness confirms in its deployments list that nothing is running before the web service is started. The worker is deployed only at the step that says so below, and each service is started with railway redeploy --from-source, which builds a fresh deployment that reads the new variables.

The selection rule is explicit: postgres is chosen only by STORAGE_DRIVER=postgres and needs DATABASE_URL; an unknown value, or postgres without the URL, ends the process with exit code 1 at startup, as does a database whose schema is not this build's. Both services must point at the same database.

The release step

The web service's start command runs npm run release (templates:publish) before npm start, so the web deploy in the window makes the first writes to Postgres before any check runs. Those writes are not only template registrations and version records: after the publications, the release step builds the batch record of every cycle that does not have one yet, reconciles Prime spell batch sharing, closes withdrawn items and finishes past vote records. Batches are processes with their own audit chains, so the release step can create processes and append audit events.

On a build that has already run its release step on Mongo (the precondition), everything it would create is already in the copy, and the expected delta is zero processes. The heads are the same too, with one allowed exception found in rehearsal #2: open vote batches to which the release step appends events that set v00_vote.publicView, each event in a processos:release:* session. Their number is the release log's public view count. When the build has not run on Mongo, the delta is the number of processes rehearsal #2's release step created on the Postgres copy, as written in the booking. The smoke checks and anchor B below use that delta.

Start and smoke-check

  1. Start the web service: railway redeploy --from-source -y -s process-platform. Its log reads in this order: the release step's output first (publications, then the batch records line with how many it created and how many were already there, then the sharing and public view lines), then Next's Ready line, then Storage driver: postgres on <postgres host> and the env check with DATABASE_URL: set and MONGO_URL: MISSING. The witness reads three numbers from the release log: N created (it equals the expected delta, zero on a build already released on Mongo), sharing, and public view. The Vote batches: N changed total is not one of them: it also counts finished batches. Startup also publishes any non-versioned template whose digest differs from the stored latest; whatever it and the release step write is written at deploy start. A Storage is not ready line followed by exit code 1 means a wrong variable or an unmigrated schema: fix and deploy again; nothing has been written.

  2. The deployment health check (path /health, the same one Railway polls) answers {"ready":true}. The release step holds it back by about 90 to 100 seconds; Railway's health-check timeout for the service is 600 seconds.

  3. Read a known process in the UI (an item the witness picks before the window and notes the id, step and a field value of): it opens, shows the same step and value, and its record timeline is complete.

  4. Audit integrity: in the web container, node scripts/run-main.mjs audit:verify prints M processes: M verified, 0 not chained yet, 0 FAILED, where M is the freeze snapshot's N plus the expected delta. Events the release step appended to existing batches (the public view events) do not change M.

  5. Status commands: node scripts/run-main.mjs templates:status and node scripts/run-main.mjs migrations:status in the same container read the same as the snapshot taken before the freeze (every template's published latest, version records and instance counts; every lineage's recorded versions), apart from instance counts raised by the delta. This is the check the tool does not make: that the stores answer the application's own queries alike on both sides.

  6. MCP: from Claude (or any MCP client already connected), list tools and read one item through Spell Risk's MCP endpoint. The OAuth grant used was copied with its hashes, so no re-authorization is needed; a 401 here means the tokens did not carry over and is a stop.

  7. Take anchor B as above, now on Postgres, before the worker starts. Its count is anchor A's plus the delta. Its previous is null: the file store lives in the container's /tmp, which the new deploy emptied, so the link from A to B is the branch history and this comparison, not the field. The witness compares the heads of the two committed files:

    diff <(jq -S '.heads' anchors/on-demand/<A>.json) <(jq -S '.heads' anchors/on-demand/<B>.json)
    

    With a delta of zero the diff is empty, or it contains only open vote batches whose new events are all processos:release:* sessions setting v00_vote.publicView, and their number equals the release log's public view count. With a delta, it also shows the batches the release step created (new entries) and any batch whose sharing it reconciled (a later head and more events). Every other entry is identical. Anything else is a stop.

  8. Start the Step Runner: railway redeploy --from-source -y -s "Step Runner". Its log shows the worker initialized and the expected [audit-anchor] OFF: … line; a Worker initialization failed (EngineSchemaError) or (StorageDriverError) line is a wrong variable, and the worker is stopped again (railway down) while it is fixed.

  9. Announce the end of the window, with the two anchor keys in the message, and lift the main freeze.

  10. Next morning, the witness reads the first daily anchor after the cutover on the branch: its previous is anchor B's key (the daily job runs in the same web deployment, whose /tmp now holds B). The web service is not redeployed between the window and that daily anchor.

The first writes to Postgres are made at the start of the web deploy, by the release step and startup (with a zero delta they change no process). The first user or worker write is the first user action after the web service is up, or the first worker tick after step 8. Rollback is simplest before it.

Rollback

Before the first user or worker write to Postgres (a smoke check failed, the worker has not started): restore the application user's write access (the revoke command with role: 'readWrite'), switch the three variables back on both services (STORAGE_DRIVER=mongo, MONGO_URL back to ${{MongoDB.PROCESSOS_APP_MONGO_URL}}, DATABASE_URL removed), start the web service with railway redeploy --from-source, and run the smoke checks against Mongo before starting the worker the same way. Nothing is lost. With a zero delta the release step wrote nothing to Postgres that Mongo lacks. With a delta, the batches it created exist only in Postgres and are discarded with it; the web deploy on Mongo runs the same release step against Mongo and creates them there, so audit:verify on Mongo then prints the freeze N plus the same delta. The Postgres data is discarded: DROP SCHEMA engine CASCADE; DROP SCHEMA drizzle CASCADE; and db:migrate again before any retry, because a later copy needs an empty, current schema.

After the first user or worker write, within the 7 days: the reverse copy. The target is a fresh Mongo database, never the frozen one (that stays untouched as evidence until the window closes). Provision a second Mongo service (or a second database on a new cluster), then:

  1. Freeze exactly as above (stop the worker, take an anchor from Postgres in the web container, stop the web, confirm no Postgres writers with SELECT count(*) FROM pg_stat_activity WHERE application_name = 'processos' being 0).

  2. Create the operator service again with SOURCE_DATABASE_URL (the Postgres service's URL) and TARGET_MONGO_URL (the fresh Mongo's private URL) as its only variables, then:

    railway ssh --service cutover-operator -- node scripts/run-main.mjs storage:copy   --from postgres --to mongo --dry-run
    railway ssh --service cutover-operator -- node scripts/run-main.mjs storage:copy   --from postgres --to mongo --confirm-target <mongo host:port[,host:port…]> --report rollback-copy.json
    railway ssh --service cutover-operator -- node scripts/run-main.mjs storage:verify --from postgres --to mongo --report rollback-verify.json
    

    The reverse copy puts program back inside process and integrity back as a top-level field; the Mongo stores create their indexes on first use. Verify must PASS and its root must equal the anchor just taken.

  3. Switch both services back to STORAGE_DRIVER=mongo with MONGO_URL pointing at the fresh database (replicaSet included: publication needs a replica set, see mongo-replica-set), start the web service with railway redeploy --from-source, smoke-check (including the status commands), start the worker the same way, take an anchor.

After 7 days rollback is no longer supported: Mongo is retired in Phase 7 and the reverse direction of the tool stays only for local work.

Data fixes after cutover

A stored value that must change outside the platform (the kind of repair the retired mongosh scripts did) is made in one transaction and then recorded, so the audit chain shows it in the open:

BEGIN;
SELECT body FROM engine.processes WHERE namespace = $1 AND id = $2 FOR UPDATE;
-- change the aggregate's body (never integrity, integrity_head or integrity_events; never revision)
UPDATE engine.processes SET body = $3::json WHERE namespace = $1 AND id = $2;
COMMIT;

followed by npm run audit:correct -- --id <processId> --reason "<why>" --yes --as <you>, which appends a correction event over the state as now stored. Until the correction is recorded, audit:verify reports the process as STATE … no longer matches the chain, which is the intended signal. The namespace column is the sha256 hex of JSON.stringify([deploymentId, ownerOrganizationId]); npm run data:pull:postgres gives a local copy to try the fix on first.

Who runs what

StepOperatorWitnessApprover (Adam)
Book the window, check the preconditionsproposes; creates the application Mongo user and the operator servicechecks each precondition, PITR status and its restorable-up-to time, the backup settings, the daily anchors on the branch, that the rehearsal refused nothing, and the expected deltaapproves the date; decides on any non-JSON value found inside integrity
Today's daily anchor, status snapshot, freeze, anchor A, dumpruns; stops each service with railway down; commits anchor A to the branchreads the daily anchor, keeps the three status outputs, confirms each stop (nothing running, health URL not 200, no application-user connection), writes down anchor A's key, count and root—
Dry run, copy, verifyrunscompares every count and the root with anchor Ais told PASS or FAIL
Revoke Mongo writesrunsreads back the refused write and the working read—
List the services, switch variables, start webruns; saves MONGO_ROOT_URL firstticks every service off against the rule, confirms the worker is not running, reads the start log, the release log's N created, sharing and public view, and the health check—
Smoke checksrunsconfirms the process, the audit:verify count against N plus the delta, the status outputs and MCP—
Anchor B, start workerruns; commits anchor B to the branchconfirms B's count and that the heads diff is what the delta and the public view count allowcloses the window
Next morning's daily anchor—confirms its previous is anchor B—
Delete the operator servicerunsconfirms it is gone—
Rollback decisionproposesstates which checks faileddecides

Record of the 2026-11-17 cutover

Production moved to Postgres on 2026-11-17, from 14:05 to 14:27 PT, following this page. The approver overrode the window rules for an Executive Vote within 48 hours, a release the same day and a booking less than two working days ahead.

CheckResult
Daily anchor before the freezeanchors/daily/2026-11-17.json: 266 processes, root a1776091…
audit:verify before the freezeN = 268
Anchor Aanchors/on-demand/2026-11-17T22-08-14-328Z.json: 268 processes, root 48141bee…
Copy684 records in 16 collections, in 16 seconds
VerifyPASS; sourceRoot equal to anchor A's root
Release step on Postgres0 created (delta 0)
audit:verify after the switch268 processes: 268 verified, 0 not chained yet, 0 FAILED
templates:status, migrations:statusbyte-identical to the snapshot
Anchor Banchors/on-demand/2026-11-17T22-24-43-009Z.json: heads and root equal to anchor A's
cutover-operatordeleted after the window
Mongofrozen, read-only for the application user; rollback window open until 2026-11-24

What the run changed in this page: services are stopped with railway down and started with railway redeploy --from-source (railway scale to 0 left both services running); the writer check matches the application user's connections, idle ones included; the role changes and the dump run as root in the MongoDB container, from MONGO_ROOT_URL; the release log's public view count bounds the anchor diff; and the health check waits on the release step.