Skip to content
Documentation

Migrate and roll back the combined capability release

Apply the search, usage, add-on, integration, and MCP migrations in dependency order, verify degraded states, and reverse them safely.

  • 5 min read
  • Updated

Upgrading a v0.1.2 installation to v0.2.1? Use the upgrade guide, not this page. The pnpm commands below need a source checkout, which installer directories do not have. On a release image, the migrate service applies every pending migration. A source build must also complete the staged scheduler migration before it starts BullMQ 6, and going back to v0.1.2 means restoring the pre-upgrade backup.

This runbook records the dependency order and verification boundaries for the capability set merged through MCP commit 9fb787ef438ecee0b65da9c785ab42dd3f2bdc1c, for operators who run a reviewed source build. A merged branch is not a released container.

Record the current image tag and digest, application commit, environment file revision, and database migration status. Stop nonessential writes, then capture Postgres and object storage from one recovery point. If ClickHouse is enabled, capture its schema version and the retention/export evidence required by your policy. Test the restore in an isolated environment before changing production.

Keep MCP disabled and search in shadow or legacy during the database change. Do not enable integrations, add-ons, or usage consumers merely because the tables exist. Unknown provider health or usage coverage remains unknown, not zero and not successful.

Install the exact application revision and generate the Prisma client before typechecking or starting services. The normal deployment command applies pending Postgres migrations in filename order. For the v0.2.0 release baseline, a v0.1.2 database had eight pending migrations: first 20260823120000_add_git_file_ownership and 20260823143000_native_better_auth_admin, then these five capability migrations, and last 20261030120000_invitation_created_at:

  1. 20260823180000_search_configuration_diagnostics
  2. 20260823210000_usage_metering
  3. 20260823220000_project_addons
  4. 20260823230000_add_project_integrations
  5. 20260823240000_mcp_control_plane

The integrations migration owns nullable ApiKey.expiresAt as a shared authentication prerequisite. The MCP migration depends on it and must run after it. Do not copy that column into the MCP migration or remove it while MCP or another consumer still depends on it.

bash
pnpm install --frozen-lockfile
pnpm db:generate
pnpm db:deploy
pnpm --filter @nibleaf/database exec prisma migrate status

When ClickHouse-backed analytics and usage are enabled, apply their forward-only migrations with a time-limited operator identity after the compatible application packages are installed:

bash
pnpm analytics:migrate

The usage UI and API must report unavailable or partial state until coverage and reconciliation are complete. Do not infer a completed backfill from successful table creation.

Start API, app, and worker processes with MCP disabled. Confirm health, sign-in, one project read, and one publish. Then verify each boundary before enabling the next one:

  1. Search settings update only the target project's search configuration; diagnostics expose bounded metadata without content or vectors. Keep hybrid retrieval in shadow until project/language/version evidence supports cutover.
  2. Usage totals distinguish complete, partial, and unavailable coverage; entitlements are advisory and no payment provider is enabled.
  3. Existing projects have durable add-on rows, preserved recognized consent, and an initial audit trail. Test one signed-out accept and decline flow.
  4. Integration secrets encrypt and decrypt with the dedicated key. Verify one non-production connection without placing credentials in logs or screenshots.
  5. Issue a new project-bound MCP key with mcp:connect and one exact read scope. Confirm capabilities, then revoke it and confirm access stops.

Run the migration smoke commands before treating the schema as ready:

bash
pnpm --filter @nibleaf/database smoke:addons-migration
pnpm --filter @nibleaf/database smoke:integrations-migration
pnpm --filter @nibleaf/database smoke:mcp-migration

Search, usage, add-ons, integrations, and MCP have separate operator guides. Keep the links in the August 2026 source capability notes with the durable upgrade record.

This section is for backing out one capability while you stay on the same build. It does not take you back to v0.1.2: migrations are forward-only, so returning to v0.1.2 means restoring the pre-upgrade backup.

Prefer runtime rollback over destructive schema reversal. Disable MCP and stop its clients first. Return search to SEARCH_RUNTIME=legacy, disable optional ClickHouse reads, deactivate affected plans or add-ons, and stop integration mutations.

If a schema rollback is still required, deploy code that no longer reads the affected schema, preserve required audit/export evidence, stop all writers, and reverse dependencies in this order:

  1. MCP control-plane tables and MCP-owned API-key provenance columns.
  2. Integration tables and encrypted credentials. Remove shared ApiKey.expiresAt only after MCP is gone and no remaining consumer needs it.
  3. Add-on state and audit history.
  4. Usage consumers, Postgres usage state, then ClickHouse usage structures.
  5. Search diagnostics state. The application can normally leave this additive table in place while using the legacy runtime.

Prisma does not automatically execute the repository's rollback.sql files. For a successfully applied migration, ship reviewed down statements as a new, later forward migration. Use prisma migrate resolve --rolled-back only for a failed migration after partial statements have been safely reversed, never to rewrite the history of a successful production migration. Follow the detailed destructive boundaries in usage metering, integrations, MCP, add-ons, and search.

Keep the exact image or commit, migration output, feature flags, provider health, smoke results, and restore evidence in the private operational system. Do not place customer data, credentials, internal hosts, usage exports, or private provider responses in this public repository.

The eight-migration inventory above belongs to the v0.2.0 baseline. Current source adds 20261106090000_mcp_write_audit_idempotency, 20261106120000_mcp_oauth, 20261106130000_mcp_audit_actor_index, and 20261106130100_mcp_audit_oauth_grant_index. pnpm db:deploy applies every pending migration in the installed revision, not just the historical list. Keep MCP disabled until they finish; the two audit indexes use concurrent DDL and need failed-index inspection if interrupted. See the MCP migration guide.

Current ClickHouse migrations also include 2026110601 through 2026110608, including insights, AI conversations and utility-model usage. Run the migration CLI with POSTGRES_URL, ClickHouse writer settings and the intended retention settings exported in its process environment. It does not load the root .env automatically. A migration success is schema evidence, not provider or restore acceptance. Preserve existing salts and encryption keys.

After upgrading, rotate your Git push webhook secret in Settings → Git and paste the new value into the repository's webhook settings.

Was this page helpful?