Skip to content

fix(core): preserve taxonomy + content_taxonomies data on D1 in migration 036 - #1086

Merged
ascorbic merged 2 commits into
mainfrom
fix/1021-d1-taxonomy-cascade
May 18, 2026
Merged

ascorbic merged 2 commits into
mainfrom
fix/1021-d1-taxonomy-cascade

Conversation

@ascorbic

Copy link
Copy Markdown
Member

What does this PR do?

Fixes silent data loss in migration 036 on Cloudflare D1.

D1 ignores PRAGMA foreign_keys = OFF, and its replacement PRAGMA defer_foreign_keys = ON only defers constraint validation — it doesn't suppress CASCADE actions (verified empirically). So when migration 036 ran the i18n rebuild of taxonomies on D1, dropping the old table fired:

  1. The ON DELETE CASCADE on content_taxonomies.taxonomy_id → every post/taxonomy association wiped.
  2. The ON DELETE SET NULL on the new taxonomies_new.parent_id self-FK → every hierarchical taxonomy's parent flattened to NULL.

Both were silent. The reporter (#1021) hit (1) upgrading 0.6.0 → 0.12.0 on a populated WP-imported site. (2) was caught by adversarial review of the initial fix — same bug class, same blast radius.

The migration now physically removes those FK relationships before any drop:

  • content_taxonomies FK: rebuilt as the first step of up(), copying values verbatim. By the time rebuildTaxonomies runs, no FK points at the old taxonomies table.
  • taxonomies self-FK: declared as REFERENCES taxonomies_new(id) during creation. SQLite's ALTER TABLE ... RENAME TO rebinds the FK target to the new name on rename. Confirmed against both better-sqlite3 and the D1-mimicking test harness.

The rollback path is restructured to match. down() now:

  1. Asserts content_taxonomies has no rows pointing at translation_groups with no surviving taxonomies row (previously this would surface mid-rollback, after other tables were already irreversibly stripped — leaving the user unrecoverable).
  2. Remaps content_taxonomies.taxonomy_id back to row ids while the locale/translation_group columns are still readable.
  3. Rebuilds the four widened tables in their pre-036 shape.
  4. Restores the content_taxonomies FK as the final step.

Also restores idx_content_taxonomies_term (from migration 015) after each rebuild — SQLite drops indexes with the table, and neither old nor new code recreated it.

Forward-fix only. Installs that already lost data running 036 will need D1 Time Travel to recover. Noted in the changeset.

Closes #1021

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Implementation notes

  • rebuildContentTaxonomies (the existing helper) is unchanged in shape but moved to run first in up(). The value remap it used to do was load-bearing only after rebuildTaxonomies had seeded translation_group = id, which now happens later. The legacy taxonomy_id values are already row ids that resolve as translation_group references after the migration completes; no remap is needed. The comment in the file flags this coupling explicitly so future changes to the translation_group seed don't silently break things.
  • down() splits the previous rebuildContentTaxonomiesDown into remapContentTaxonomiesDown (just the value UPDATE — runs against the FK-less post-up table) and restoreContentTaxonomiesFk (the FK-re-adding rebuild — runs after taxonomies is back to its pre-036 shape).
  • assertContentTaxonomiesResolve is a new fail-fast check mirroring assertSingleLocale's existing pattern. Surfaces dangling associations up front rather than at the moment the FK is restored.
  • Removed PRAGMA foreign_keys = OFF/ON from both up() and down() (SQLite path). Confirmed by audit that no intermediate operation depends on FK enforcement being disabled: _emdash_menus, _emdash_menu_items, _emdash_taxonomy_defs have no FKs in the pre-036 schema; taxonomies.parent_id self-FK is handled by the temp-name trick above; content_taxonomies FK is removed in step 1.
  • Postgres path (pgWiden, pgRemapContentTaxonomies) is unchanged.

Tests

Three new regression tests run against a Kysely instance backed by better-sqlite3 with PRAGMA foreign_keys = OFF patched to a no-op — mimicking D1's locked-on FK enforcement. They fail against the pre-fix migration and pass against this one:

  • preserves taxonomy parent_id hierarchy on D1 (regression for #1021) — seeds a hierarchical taxonomy, runs up(), verifies parent_id is preserved.
  • preserves content_taxonomies rows on D1 (regression for #1021) — seeds a post→term association, runs up(), verifies the row survives.
  • refuses to rollback when content_taxonomies has dangling rows — verifies the new fail-fast assertion fires before any destructive work.

The createD1LikeDatabase helper is local to this test file. A workspace-wide D1 dialect for describeEachDialect is a separate ambient task; this is the smallest thing that catches the specific bug class on existing infrastructure.

All 33 migration tests pass. 156 broader DB tests pass.

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes (0 diagnostics on changed files)
  • pnpm test passes for the migration test files; broader DB test suite (tests/integration/database/, tests/unit/database/) is also green
  • pnpm format has been run
  • I have added/updated tests for my changes
  • User-visible strings in the admin UI are wrapped for translation — n/a
  • I have added a changeset
  • New features link to an approved Discussion — n/a (bug fix)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.7 via OpenCode. Adversarial review pass run with the same model in a sub-agent; findings (self-FK cascade, dangling-row case, missing idx_content_taxonomies_term, regression test gap) all incorporated.

…tion 036

D1 ignores PRAGMA foreign_keys = OFF and defer_foreign_keys only defers
constraint validation, not CASCADE actions, so dropping the old taxonomies
table during the i18n rebuild fired both the ON DELETE CASCADE on
content_taxonomies (wiping post-taxonomy associations) and the
ON DELETE SET NULL on the new table's own parent_id (flattening taxonomy
hierarchies).

The migration now physically removes those FK relationships before any
drop: it rebuilds content_taxonomies without the FK first, and points the
new taxonomies table's self-FK at its temporary name (taxonomies_new),
which SQLite rebinds on RENAME. The rollback path is restructured to
match and now refuses to run when content_taxonomies has rows referencing
translation groups with no surviving taxonomies row, surfacing dangling
data before any destructive work. The idx_content_taxonomies_term index
from migration 015 is restored after each rebuild.

Adds regression tests that run against a Kysely instance which mimics D1
by treating PRAGMA foreign_keys = OFF as a no-op.

Closes #1021
Copilot AI review requested due to automatic review settings May 18, 2026 06:41
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-perf-coordinator 7f6aed0 May 18 2026, 11:51 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-i18n 7f6aed0 May 18 2026, 11:51 AM

@changeset-bot

changeset-bot Bot commented May 18, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7f6aed0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs 7f6aed0 May 18 2026, 11:52 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 7f6aed0 May 18 2026, 11:53 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 7f6aed0 May 18 2026, 11:53 AM

@pkg-pr-new

pkg-pr-new Bot commented May 18, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1086

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1086

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1086

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1086

emdash

npm i https://pkg.pr.new/emdash@1086

create-emdash

npm i https://pkg.pr.new/create-emdash@1086

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1086

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1086

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1086

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1086

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1086

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1086

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1086

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1086

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1086

commit: 7f6aed0

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes migration 036’s handling of taxonomy-related foreign keys on SQLite/D1 to avoid silent taxonomy association and hierarchy loss during the i18n migration.

Changes:

  • Reorders SQLite up() to rebuild content_taxonomies before dropping/rebuilding taxonomies.
  • Adjusts taxonomy self-FK creation and rollback remapping/restoration.
  • Adds D1-like regression tests and a patch changeset.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/core/src/database/migrations/036_i18n_menus_and_taxonomies.ts Updates migration/rollback ordering, FK handling, assertions, and index restoration.
packages/core/tests/unit/database/migrations/036_i18n_menus_and_taxonomies.test.ts Adds D1-like regression coverage for taxonomy parent and content taxonomy preservation.
.changeset/fix-1021-d1-taxonomy-cascade.md Documents the migration data-loss fix as a patch release.
Comments suppressed due to low confidence (1)

packages/core/src/database/migrations/036_i18n_menus_and_taxonomies.ts:400

  • Rollback still rebuilds _emdash_menus before removing or neutralizing the _emdash_menu_items.menu_id FK. With foreign keys enforced, DROP TABLE _emdash_menus inside rebuildMenusDown() cascades into _emdash_menu_items and wipes menu items during rollback; the old PRAGMA foreign_keys = OFF masked this but D1 will not.
		await rebuildMenusDown(db);
		await rebuildMenuItemsDown(db);
		await rebuildTaxonomiesDown(db);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// not CASCADE actions — so DROP TABLE taxonomies still wipes child
// rows (#1021). The FK has to be physically removed before the drop.
await rebuildContentTaxonomies(db);
await rebuildMenus(db, defaultLocale);
Comment on lines +259 to +267
it("preserves taxonomy parent_id hierarchy on D1 (regression for #1021)", async () => {
// On D1 where `PRAGMA foreign_keys = OFF` is a no-op, dropping the old
// taxonomies table cascades ON DELETE SET NULL through the new table's
// self-FK on parent_id and flattens the hierarchy. Pointing the self-FK
// at `taxonomies_new` (rebound to `taxonomies` by SQLite's RENAME) avoids
// this. Run against a Kysely instance that mimics D1's locked-on FK
// enforcement.
await db.destroy();
db = createD1LikeDatabase();
Comment on lines +324 to +329
/**
* down() restores the FK on content_taxonomies. Rows whose taxonomy_id doesn't
* resolve to a (translation_group, defaultLocale) pair would fail the rebuild
* after other tables are already stripped — leaving the user mid-rollback.
* Surface dangling rows up front instead.
*/
@ascorbic

Copy link
Copy Markdown
Member Author

/review

ask-bonk[bot]
ask-bonk Bot previously requested changes May 18, 2026

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the taxonomy fix empirically — the self-FK temp-name trick and the FK-first rebuild are both correct. But the same bug class still wipes data on the menu side, which the PR description's audit claims to have ruled out.

From migration 005 (packages/core/src/database/migrations/005_menus.ts:38-47):

.addForeignKeyConstraint("menu_items_menu_fk", ["menu_id"], "_emdash_menus", ["id"], (cb) =>
  cb.onDelete("cascade"),
)
.addForeignKeyConstraint("menu_items_parent_fk", ["parent_id"], "_emdash_menu_items", ["id"], (cb) =>
  cb.onDelete("cascade"),
)

So _emdash_menu_items.menu_id → _emdash_menus(id) ON DELETE CASCADE is in the pre-036 schema. With PRAGMA foreign_keys = OFF removed, rebuildMenus() doing DROP TABLE _emdash_menus cascades into _emdash_menu_items and empties it — the parent-self CASCADE then mops up any nested items. Identical to the content_taxonomies failure mode the PR fixes for taxonomies. rebuildMenusDown() has the same issue in reverse.

Reproduced against production-shaped FKs with FK enforcement on (better-sqlite3, FK enforcement matching D1):

// pre-036 schema with real menu_items.menu_id FK
INSERT INTO _emdash_menus VALUES ('m1', ...);
INSERT INTO _emdash_menu_items VALUES ('mi1', 'm1', ...);
// migration 036's rebuildMenus body, paraphrased:
CREATE TABLE _emdash_menus_new (...);
INSERT INTO _emdash_menus_new SELECT ... FROM _emdash_menus;
DROP TABLE _emdash_menus;
// → SELECT COUNT(*) FROM _emdash_menu_items returns 0

Count went from 1 → 0 after the drop. Same result the issue reporter hit on content_taxonomies.

The regression tests don't catch it because seedPreMigrationSchema() declares _emdash_menu_items without any FK constraints — not faithful to migration 005's output, so the D1-like harness has nothing to cascade on. The D1-like cases only seed taxonomies.

This needs to be fixed before merge — silent menu-item wipeout on D1 upgrade has the same blast radius as #1021. The fix is the same pattern already applied to rebuildContentTaxonomies: rebuild _emdash_menu_items first (stripping the menu_id and parent_id FKs) before rebuildMenus, and do the symmetric thing in down().

Also flagging the duplicate-JSDoc nit from Copilot's review — minor but worth fixing in the same pass.

// not CASCADE actions — so DROP TABLE taxonomies still wipes child
// rows (#1021). The FK has to be physically removed before the drop.
await rebuildContentTaxonomies(db);
await rebuildMenus(db, defaultLocale);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical — same bug class as #1021, still present for menus on D1.

With PRAGMA foreign_keys = OFF removed, rebuildMenus() now runs against live FK enforcement on D1. _emdash_menu_items.menu_id carries an ON DELETE CASCADE FK to _emdash_menus(id) from migration 005 (see packages/core/src/database/migrations/005_menus.ts:38-40), and _emdash_menu_items.parent_id has a CASCADE self-FK. Inside rebuildMenus() the DROP TABLE _emdash_menus step fires ON DELETE CASCADE, deletes every menu item, and the self-FK propagates through any nested children. Silent — same pattern the issue reporter hit on content_taxonomies.

Verified against better-sqlite3 with FK enforcement on and the real migration-005 FKs in place: menu_items count goes from N → 0 the moment DROP TABLE _emdash_menus executes inside rebuildMenus.

The PR description audit says "_emdash_menus, _emdash_menu_items, … have no FKs in the pre-036 schema" — that's not what migration 005 ships. The fix needs the same pattern applied to taxonomies here: rebuild _emdash_menu_items first (FK-strip step before rebuildMenus, copying values verbatim — menu_id already holds the same string after the menu rebuild because IDs are preserved). The taxonomies_new self-FK rename trick alone doesn't help here because the offending FK is on the child table, not self-referential.

Blast radius: anyone with menu items running migration 036 on D1, which includes the upgrade path the issue reporter was on. Should block the merge.

// D1's only PRAGMA escape, `defer_foreign_keys`, doesn't suppress
// CASCADE actions, only constraint validation).
await remapContentTaxonomiesDown(db, defaultLocale);
await rebuildMenusDown(db);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same cascade bug on the rollback path.

rebuildMenusDown() does DROP TABLE _emdash_menus. At this point in down(), _emdash_menu_items still has the post-036 shape and — critically — still carries the menu_id → _emdash_menus(id) ON DELETE CASCADE FK from migration 005 (the rebuild in up() didn't drop it; addItemColumns() only adds columns). With FK enforcement on (D1), this drops every menu item before rebuildMenuItemsDown even runs.

Mirror whatever the up-side fix does: pre-strip the menu_id FK from _emdash_menu_items before rebuildMenusDown — i.e. rebuild _emdash_menu_items first in the rollback ordering, then rebuild _emdash_menus, then add the _emdash_menu_items FKs back at the end (mirroring how restoreContentTaxonomiesFk is called last for content_taxonomies).

// enforcement.
await db.destroy();
db = createD1LikeDatabase();
await seedPreMigrationSchema(db);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage gap that masks the menus bug.

seedPreMigrationSchema() declares _emdash_menu_items without the two FK constraints from migration 005 (menu_id → _emdash_menus(id) ON DELETE CASCADE and parent_id → _emdash_menu_items(id) ON DELETE CASCADE). As a result the D1-like regression tests here (preserves taxonomy parent_id hierarchy on D1, preserves content_taxonomies rows on D1) can't reproduce the menu-side cascade even though it's the same bug class.

Make the seeded schema match migration 005 by adding the FKs, then add a third D1-like case that seeds a menu + menu_item and asserts the menu_item survives up() (and another asserting it survives down()). That test will fail against the current migration code and pass once the menu rebuild order is fixed.

* translated rows onto an ambiguous unique key). Refuse to run when any row
* sits at a locale other than the configured defaultLocale.
*/
/**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: this new JSDoc block sits immediately below another /** ... */ that was originally written for assertSingleLocale (file lines 319-323, unchanged by this PR), so the older block is now orphaned above this one and assertSingleLocale at line 352 ends up effectively undocumented. Move the older JSDoc down to immediately precede assertSingleLocale, or fold the two into a single header. Already flagged by Copilot.

@ask-bonk

ask-bonk Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Review posted successfully (id 4307925621, state CHANGES_REQUESTED).

Summary of what I posted:

1 critical, 1 critical (rollback mirror), 1 critical (test gap), 1 minor

  • migrations/036_i18n_menus_and_taxonomies.ts:29 — rebuildMenus() still hits the same FK-cascade bug class on D1 because _emdash_menu_items.menu_id has ON DELETE CASCADE to _emdash_menus(id) (migration 005, lines 38–47). Empirically verified: dropping _emdash_menus with FKs enforced wipes every menu item. Blocking.
  • migrations/036_i18n_menus_and_taxonomies.ts:398 — same cascade on rollback path. rebuildMenusDown drops _emdash_menus before the _emdash_menu_items.menu_id FK is gone.
  • tests/.../036_*.test.ts:268 — seedPreMigrationSchema() omits the menu FKs from migration 005, so the D1-like regression tests can't reproduce the cascade. Coverage gap that hid the issue.
  • migrations/036_i18n_menus_and_taxonomies.ts:324 — minor: new JSDoc orphans the older assertSingleLocale doc-block (also flagged by Copilot).

Verified the cascade empirically before posting — better-sqlite3 with PRAGMA foreign_keys = ON and the real migration-005 schema, count 1 → 0 on DROP TABLE _emdash_menus.

github run

Same bug class as the taxonomies fix: `_emdash_menu_items.menu_id`
and `parent_id` had `ON DELETE CASCADE` to `_emdash_menus` and self
from migration 005. When migration 036 dropped the old `_emdash_menus`
during the i18n widening, the cascade fired on D1 (which enforces FKs
but ignores `PRAGMA foreign_keys = OFF`) and wiped every menu item.

Rebuild `_emdash_menu_items` first to strip both FKs before the
parent drop, mirroring the existing `rebuildContentTaxonomies`
pattern. The runtime already deletes children explicitly
(`MenuRepository.delete` / `setItems`), so the cascade loss is
invisible to callers.

`down()` does not restore the migration-005 FKs: they were the source
of #1021 in the first place, and the runtime doesn't depend on them.
Added a regression test under the D1-like harness (better-sqlite3 with
`PRAGMA foreign_keys = OFF` made a no-op) and corrected the
pre-migration seed schema so the harness can actually reproduce the
cascade.
@ascorbic

Copy link
Copy Markdown
Member Author

/review

@ask-bonk

ask-bonk Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

I have already reviewed this PR (visible in the pull_request_reviews section — review id 4307925621, state CHANGES_REQUESTED, posted at 2026-05-18T07:03:14Z). The critical findings about the menu-side cascade bug and test coverage gap have been raised.

Since I've already posted a thorough adversarial review on this PR and the findings still stand (no new commits since), there's nothing new to add.

LGTM!

github run

@ascorbic

Copy link
Copy Markdown
Member Author

/review there has been a new commit since your review. Please re-check

@ascorbic ascorbic changed the title fix(core): preserve taxonomy + content_taxonomies data on D1 in migration 036 (#1021) fix(core): preserve taxonomy + content_taxonomies data on D1 in migration 036 May 18, 2026
@ask-bonk

ask-bonk Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Good — runs all migrations, then asserts no FKs. This validates the post-migration state of a real install.

Now let me check the existing PR description audit claim: "Postgres path (pgWiden, pgRemapContentTaxonomies) is unchanged." Did Postgres have the same FK cascade issue? Let me confirm that pg's ADD COLUMN locale doesn't drop child rows... no, ADD COLUMN doesn't fire FK cascades anywhere, and pg correctly handles ALTER TABLE with constraints. Postgres path is structurally different — it widens columns in place rather than rebuilding tables, so DROP TABLE never fires. ✓

I've reviewed the fix exhaustively. The new commit 7f6aed03:

  1. ✅ Fixed the menu cascade on up() — adds rebuildMenuItems() that strips both FKs before rebuildMenus() drops the parent.
  2. ✅ Fixed the rollback path — chooses not to restore the migration-005 FKs (justified: runtime does explicit deletes; restoring them would just re-introduce the cascade hazard).
  3. ✅ Test coverage gap closed — seedPreMigrationSchema now correctly declares both menu FKs from migration 005 (with indexes), and three new regression tests cover D1-like preservation on up(), the FK-stripped invariant, and rollback preservation.
  4. ✅ JSDoc orphan fixed — assertSingleLocale doc-block is now back in place.
  5. ✅ Idempotence guard preserved (hasColumn(... "locale") check at the top of rebuildMenuItems).
  6. ✅ Indexes recreated after rebuild — idx_menu_items_menu, idx_menu_items_parent, plus new _locale and _translation_group indexes.
  7. ✅ Runtime correctness preserved — MenuRepository.delete and setItems already do explicit child deletion; only one site-wide deleteFrom("_emdash_menus") exists and it's already correctly preceded by an item delete.
  8. ✅ No new code paths bypass the explicit-delete contract — confirmed by grep.

All four findings from my previous review have been addressed thoroughly and correctly. The fix is well-structured, well-justified in code comments, and the test harness has been corrected to actually reproduce the bug it claims to test.

LGTM!

github run

@ascorbic
ascorbic merged commit 23597d0 into main May 18, 2026
39 checks passed
@ascorbic
ascorbic deleted the fix/1021-d1-taxonomy-cascade branch May 18, 2026 12:02
@emdashbot emdashbot Bot mentioned this pull request May 18, 2026
ski added a commit to ski/emdash that referenced this pull request May 20, 2026
Catches deployment/suhail-ski up with emdash-cms/emdash main. Conflict in
pnpm-lock.yaml resolved by taking upstream's lock and re-running
pnpm install to pick up the @suhailski/57th-parallel template deps.

Notable upstream changes folded in:
  - Plugin authoring CLI + manifest format (emdash-cms#1057, emdash-cms#1059)
  - Registry packages — lexicons, client, CLI (emdash-cms#923)
  - Migration 036 taxonomy preservation (emdash-cms#1086)
  - WXR import w/ WPML/Polylang translations (emdash-cms#1087)
  - TypeScript 6 upgrade, tsgo beta (emdash-cms#1074)
  - FTS5 corruption fix on publish (emdash-cms#768)
  - Plugin bundle size caps (emdash-cms#978)
  - And ~280 smaller fixes / chores

CLI rebuilt against the new core. Verified by listing posts on
suhail.ski — both tutorial posts come back as expected.

57th-parallel template untouched by upstream. Our 5 local commits
preserved across the merge.

Used --config.manage-package-manager-versions=false to bypass pnpm's
self-switch to 11.1.3, which packages weirdly on Windows. The current
shell's pnpm 10.12.4 worked fine against the merged manifests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migration 036 (0.12.0) silently destroys content_taxonomies data on Cloudflare D1

2 participants