fix(drizzle-kit): prevent duplicate CREATE INDEX on table recreation#5268
Open
mabels wants to merge 1 commit intodrizzle-team:mainfrom
Open
fix(drizzle-kit): prevent duplicate CREATE INDEX on table recreation#5268mabels wants to merge 1 commit intodrizzle-team:mainfrom
mabels wants to merge 1 commit intodrizzle-team:mainfrom
Conversation
When a table with indexes needed recreation (e.g., composite PK changes), CREATE INDEX statements were being emitted twice: - Once from _moveDataStatements() during table recreation - Again from separate create_index JSON statements This resulted in SQL like: CREATE UNIQUE INDEX `UserSlug_userSlug` ... PRAGMA foreign_keys=ON; CREATE UNIQUE INDEX `UserSlug_userSlug` ... <-- duplicate! Fix: Track which tables have been recreated and skip create_index statements for those tables since indexes are already created in _moveDataStatements(). Added regression test with UserSlugBindings table schema that has composite primary key, uniqueIndex, and regular index.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_moveDataStatements())Problem
When running
drizzle-kit pushon a table that requires recreation (e.g., composite primary key changes), CREATE INDEX statements were emitted twice:Root Cause
Indexes were being generated from two separate places:
_moveDataStatements()in libSqlPushUtils.ts/sqlitePushUtils.ts - generates index SQL during table recreationcreate_indexJSON statements fromprepareLibSQLRecreateTable()that were also converted to SQLFix
Track which tables have been recreated using a
Set<string>and skipcreate_indexstatements for those tables.Test plan