Skip to content

Commit 5d80d9b

Browse files
committed
docs(#226): document the D1 referenced-table rebuild refusal
1 parent 7b439fa commit 5d80d9b

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ here. The format follows [Keep a Changelog](https://keepachangelog.com/), and
55
this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
66
(pre-1.0; MINOR bumps may introduce breaking changes with notice).
77

8+
## [Unreleased]
9+
10+
### Fixed — `meta migrate --dialect d1` no longer emits an un-appliable rebuild of a foreign-key-referenced table (#226)
11+
12+
npm-only (`migrate-ts` — D1 is a TS-only dialect). On remote Cloudflare D1 a migration
13+
runs inside D1's implicit transaction, where `PRAGMA foreign_keys = OFF` is a no-op — so
14+
the SQLite table-rebuild recipe failed to drop a foreign-key-referenced table, aborting
15+
the migration with `FOREIGN KEY constraint failed`. The failure was silent until a table
16+
held rows, so it first surfaced against populated production databases. `meta migrate
17+
--dialect d1` now **refuses at generation time** with a clear, actionable error when a
18+
change would rebuild a table that another table's foreign key references (self-references
19+
included), instead of emitting SQL that fails at apply time. Migrations that do not
20+
rebuild a referenced table are byte-identical. Auto-generating the rebuild cascade is
21+
tracked as a follow-up (#241).
22+
823
## [0.20.6] — 2026-07-26
924

1025
**Coordinated PATCH** — npm `0.20.6` · PyPI `0.19.8` · Maven Central `7.11.6` · NuGet

‎docs/features/migrations-and-drift.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ meta migrate --dialect d1 # Cloudflare D1 dialect (TS-only)
5555
Dialects: `postgres` (default), `sqlite`, `d1`. Output lands under the path
5656
configured in `metaobjects.config.ts` (typically `./migrations/<timestamp>__<slug>.sql`).
5757

58+
#### D1 limitation: rebuilding a foreign-key-referenced table
59+
60+
Cloudflare D1 applies each migration inside its own implicit transaction, and SQLite
61+
ignores `PRAGMA foreign_keys` while a transaction is open. The SQLite table-rebuild
62+
recipe (used for a `CHECK`, column type/nullability/default, foreign-key, or
63+
`field.enum` values change) relies on `PRAGMA foreign_keys = OFF` taking effect before
64+
it drops and recreates the table — which does not happen on remote D1.
65+
66+
To avoid emitting a migration that would fail against a populated production database
67+
with `FOREIGN KEY constraint failed`, `meta migrate --dialect d1` **refuses at
68+
generation time** when a change would rebuild a table that another table's foreign key
69+
references. Apply such a change by hand-writing the migration: rebuild the referencing
70+
table to temporarily drop its foreign key, rebuild the referenced table, then restore
71+
the foreign key — or make the change on an unreferenced table. (Auto-generating this
72+
cascade is tracked as a follow-up.)
73+
5874
### Java
5975

6076
Schema migrations for Java projects are owned by the **TypeScript toolchain**

0 commit comments

Comments
 (0)