[SQLite-kit]: make index drop/recreate idempotent for libSQL/Turso push#5607
Open
MorganTitcher wants to merge 2 commits intodrizzle-team:mainfrom
Open
Conversation
Use DROP INDEX IF EXISTS when LibSQLModifyColumn tears down indexes, and CREATE INDEX IF NOT EXISTS when recreating them so batchWithPragma survives multiple column modifications in one push. Use DROP INDEX IF EXISTS in SqliteDropIndexConvertor for explicit drop_index on sqlite/turso. Fixes duplicate DROP INDEX failures (no such index) reported in drizzle-team#5564. Co-authored-by: Morgan Titcher <MorganTitcher@users.noreply.github.com>
…team#5564 Align snapshots with IF EXISTS drops and IF NOT EXISTS index recreation. Add regression test for two set_notnull statements across indexed tables. Co-authored-by: Morgan Titcher <MorganTitcher@users.noreply.github.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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
Fixes
drizzle-kit push/db:pushfailures on libSQL/Turso when multipleLibSQLModifyColumnoperations are executed in a single batch.Previously, repeated
DROP INDEXstatements could fail with:no such index(index already removed earlier in the batch)This occurs because
LibSQLModifyColumnemits unconditional index teardown and recreation, which is not safe when multiple table/column modifications are processed together.Changes
Idempotent index handling in LibSQLModifyColumn
Update index teardown and recreation to be safe under batching:
DROP INDEX→DROP INDEX IF EXISTSCREATE INDEX→CREATE INDEX IF NOT EXISTSCREATE UNIQUE INDEX→CREATE UNIQUE INDEX IF NOT EXISTSThis ensures that:
SQLite drop_index convertor
Update
SqliteDropIndexConvertorto emit:DROP INDEX IF EXISTSfor explicit
drop_indexstatements on SQLite/libSQL/Turso.Tests
Updated expectations in:
tests/push/libsql.test.tstests/libsql-statements.test.tstests/push/sqlite.test.tsAdded regression coverage for:
All
drizzle-kittests pass:Rationale
The current drop/recreate strategy is correct in principle, but not safe under batched execution where the same index may be touched multiple times.
Making index operations idempotent:
Notes / Follow-ups
A more targeted approach (only dropping/recreating indexes affected by a given column change) could reduce redundant operations, but would require deeper schema/index dependency analysis and is out of scope for this fix.
Reproduction
See #5564 for a minimal reproduction case involving:
set not nullconversions in a singlepushChecklist
Fixes #5564