Repository navigation
fix(drizzle): preserve input during write transformation - #19483
Conversation
Written with AI
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖 |
Written with AI
Written with AI
|
🚀 This is included in version v4.0.0-beta.8 |
) Written with AI ## Description Publishing an inherited page on a content branch can fail with `UNIQUE constraint failed: pages_blocks_content.id` on SQLite. The editor submits main’s existing block and array IDs after the document has been forked, but those IDs were also used as database primary keys. Store logical array/block IDs separately from database primary keys for branchable SQL collections and globals, allowing main and branch copies to retain the same logical IDs. This PR targets `fix/branch-name-only-19112` and contains only the branch-specific schema changes and publishing regression coverage. ## Prerequisite Depends on #19483, which targets `main` and preserves caller-owned input during database writes. Its deep-copy implementation and input-preservation regression have been removed from this PR’s incremental diff. Merge #19483 and propagate it through the feature stack before merging this PR. On the current base without that prerequisite, the nested-publish regressions fail because logical row IDs are lost during writes. Validation with the prerequisite is recorded below. ## Changes - Store logical array/block IDs separately from generated database primary keys for branchable SQL collections and globals, using the existing version-table mechanism. - Add an adapter-independent integration suite covering direct publication and autosave followed by publication of inherited localized blocks with nested arrays. Verify persisted IDs, isolation of main, merge preflight/execution, and preservation of the other locale. - Add schema coverage confirming branchable entities use separate logical IDs while excluded collections retain their existing schema. Existing SQL databases require a schema/data migration that preserves existing logical row IDs and nested relationships. The regression tests use fresh schemas; migration of existing databases is not covered here. ## Test Plan - After extraction: schema unit suite passed (9 tests). - With only #19483’s production deep-copy fix temporarily applied for validation: both nested-publish integration cases passed on SQLite and PostgreSQL (2 cases per adapter). The prerequisite overlay was removed afterward and is not part of this PR’s diff. - Confirmed both SQLite cases fail on the current base without #19483, losing logical block/array IDs. - Targeted production/schema unit-file lint and formatting passed; `git diff --check` passed. - Diff audit: 7 files remain, with no changes under `packages/drizzle/src/transform/write`. - The integration suite uses `db: 'all'` for the existing database matrix. Other adapter variants were not rerun after this extraction. - Local checks used Node 22.23.1; the repository declares Node >=24.22.1.
Written with AI ## Description Backports #19483 to `3.x`. Drizzle write transformation mutates caller-owned input while moving array/block IDs into `_uuid` storage fields and annotating nested groups. Deep-copy the input once with `deepCopyObjectSimple` before traversal so relational storage transformations preserve the caller's document data. ## Changes - Preserve the production fix from #19483 without modification. - Backport the database version regression and its collection, covering blocks, nested arrays, ordinary groups, localized groups, and logical row IDs. - Adapt regression tests to the existing `3.x` test helpers and preserve its auth security assertions. The fixture-based `test.suite` API used on `main` does not exist on `3.x`. - Generate the new collection types using `3.x`, excluding unrelated existing type drift. ## Test Plan - Passed the targeted database version regression on SQLite. - Passed the targeted auth constrained-session regression on SQLite. - Confirmed the database regression fails without the fix because caller-owned IDs are replaced by `_uuid` metadata. - Prettier checks and `git diff --check` passed. - Local tests used available dependencies under Node 22.23.1 and a temporary Vitest OXC JSX configuration adjustment; the runner adjustment is excluded from this PR. Other database adapters were not rerun for this backport.
Written with AI
Description
Drizzle write transformation mutates caller-owned input while moving array/block IDs into
_uuidstorage fields and annotating nested groups. Reusing that input after transformation therefore observes missing IDs and internal storage metadata.Deep-copy the input once with
deepCopyObjectSimplebefore traversal so relational storage transformations preserve the caller's document data.Extracted from #19375 as an independent prerequisite targeting
main. This fixes shared adapter behavior and requires no content branching configuration or schema changes. The branch-specific logical-row-ID schema changes remain in #19375.Changes
transformForWriteentry point before recursive traversal.test/database/int.spec.tsusingtest.optionswithdb: 'all', so the existing database matrix exercises every adapter. Register its collection in the shared database config and clean up its records after the test.Test Plan
_uuidproperties are added to caller-owned objects.git diff --checkpassed. The existing database spec has 53 lint diagnostics; verified the updated file has the same diagnostics and introduces none.