Skip to content

fix(drizzle-kit): include ON DELETE/ON UPDATE in SQLite ALTER TABLE ADD COLUMN#5621

Open
JosephDoUrden wants to merge 1 commit intodrizzle-team:mainfrom
JosephDoUrden:fix/sqlite-alter-fk-actions
Open

fix(drizzle-kit): include ON DELETE/ON UPDATE in SQLite ALTER TABLE ADD COLUMN#5621
JosephDoUrden wants to merge 1 commit intodrizzle-team:mainfrom
JosephDoUrden:fix/sqlite-alter-fk-actions

Conversation

@JosephDoUrden
Copy link
Copy Markdown

Summary

Fix SQLiteAlterTableAddColumnConvertor omitting ON DELETE and ON UPDATE clauses from REFERENCES in ALTER TABLE ADD COLUMN statements.

Fixes #5619

Problem

When using drizzle-kit generate with SQLite, foreign key columns added via ALTER TABLE ADD COLUMN lost their referential actions:

-- Generated (missing ON DELETE SET NULL)
ALTER TABLE `tasks` ADD `assigned_to` text REFERENCES users(id);

-- Expected
ALTER TABLE `tasks` ADD `assigned_to` text REFERENCES users(id) ON DELETE SET NULL;

SQLiteSquasher.unsquashFK() correctly parsed onDelete/onUpdate, but the referenceStatement template in SQLiteAlterTableAddColumnConvertor.convert() only output REFERENCES table(col) without the action clauses.

Fix

Append ON DELETE and ON UPDATE clauses to the referenceStatement when present, matching the pattern used by SQLiteCreateTableConvertor.

Test plan

  • Existing SQLite tests pass (tests/test/sqlite.test.ts)
  • LibSQL statement combiner tests pass (tests/statements-combiner/libsql-statements-combiner.test.ts)

…DD COLUMN

SQLiteAlterTableAddColumnConvertor.convert() was omitting ON DELETE and
ON UPDATE clauses from REFERENCES in ALTER TABLE ADD COLUMN statements,
even though SQLiteSquasher.unsquashFK() correctly parsed them.

This caused generated migrations to produce invalid foreign key
constraints that silently lost their referential actions.

Fixes drizzle-team#5619
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: SQLite ALTER TABLE ADD COLUMN omits ON DELETE / ON UPDATE from REFERENCES clause

1 participant