Quickback Docs

Schema Baselines

Compact a D1 Drizzle history locally, prove replay parity, and adopt it without recreating existing tables.

quickback migrations baseline replaces a long D1/SQLite schema history with a compact baseline. It uses the project's pinned drizzle-kit@0.31.10 and requires Node.js 22.13 or newer for the isolated SQLite replay. The rest of the CLI retains its existing Node requirement.

quickback migrations baseline --database features         # preview; migration files unchanged
quickback migrations baseline --database features --write # explicit local cutover
quickback migrations baseline --database auth --write     # separate history/database

This first version supports auth and features histories with SQLite v6 Drizzle snapshots and Wrangler's default d1_migrations ledger. It does not support PostgreSQL, tenant Durable Objects, custom/broker-managed migration ledgers, virtual tables, or histories that attach databases/load extensions. It refuses unknown arguments, broken journals, missing SQL, broken snapshot chains and symlinks. No command here connects to a database or invokes Wrangler. Use the standard Wrangler D1 migration runner for adoption; broker-managed deployment ledgers require a separate adoption protocol and are not supported.

What is compacted

The command replays the SQL history in an isolated in-memory SQLite process, validates the final snapshot through Drizzle, and checks its table, column, foreign-key and index contracts. It exports the final tables, indexes, views, triggers, migration seed rows (including blobs and large integers), and AUTOINCREMENT sequences. Seed expressions such as random ids or timestamps are materialized at preparation time; the SQL filename addresses those actual bytes. Replaying the proposed baseline must reproduce that state exactly and pass foreign-key checks.

The result is one 0000_quickback_baseline_<digest>.sql and a rooted snapshot and journal. A compiler-owned trigger document, when present, remains as a second SQL migration under its content hash. This preserves trigger deduplication and later trigger removal; concatenating old SQL would not do that. Custom triggers remain in the schema baseline, after the seed inserts.

--write uses the same project migration lock as builds, rechecks the source inventory, stages the complete tree, and keeps the original tree byte-for-byte under quickback/.archives/migration-baselines/<database>/<digest>/. It writes reviewable manifest.json and adopt.sql under quickback/baselines/<database>/<digest>/. Commit the baseline and review artifacts. Keep the archive until every deployed database has crossed over; standard Quickback ignores .archives/. An ordinary write failure restores the original tree. If the process or machine dies during the rename cutover, recover the original tree from that archive before another build or deploy.

This is an explicit replacement path. Normal quickback build remains additive and never rewrites applied migrations. meta/_baseline.json retains retired ledger names so a later rebaseline can recognize previously adopted databases.

Fresh versus existing databases

Fresh databases: apply the compact SQL files normally with Wrangler. Each migration is applied in a transaction; the schema baseline defers foreign keys while inserting its seed rows. A baseline is a schema bootstrap, not an export of production rows or encrypted integration secrets.

Existing databases: do not run the baseline's CREATE statements against them.

  1. Back up each target and stop deployment jobs that could apply migrations.
  2. Using the original history, apply every pending migration up to the cutoff.
  3. Prepare and review the baseline locally. Rebuild the project and inspect the next Drizzle migration; an unchanged schema should produce none.
  4. Test adopt.sql against a populated local copy or disposable staging target.
  5. Execute the reviewed adopt.sql on each matching existing D1 database before running normal migration application with the compacted files.
  6. Apply subsequent migrations and test the application. Repeat independently for auth/features and every environment.

The adoption SQL performs a single atomic INSERT into d1_migrations. It requires every source migration name, permits only known retired/baseline names, and checks the exact schema catalog, including triggers and indexes. A mismatch raises a malformed-JSON error and records no baseline names. Equivalent schemas with different SQL text are deliberately refused; investigate instead of bypassing the guard. A repeat adoption inserts no duplicate names. Old ledger rows are retained, and application tables/rows are never changed by adoption. The generated statement is limited to a conservative 64 KiB; larger statements refuse preparation rather than produce an unchecked cutover.

Do not edit the manifest or adoption guard to silence a mismatch. Missing history must be recovered from a trusted archive or deployment artifact, not invented. A new baseline changes which migration filenames are pending on an existing DB, so deploying compacted files without the adoption step will attempt to recreate tables.

On this page