fix(kit): use batchWithPragma for libSQL push to avoid HTTP transaction errors#5491
Open
sleitor wants to merge 1 commit intodrizzle-team:betafrom
Open
fix(kit): use batchWithPragma for libSQL push to avoid HTTP transaction errors#5491sleitor wants to merge 1 commit intodrizzle-team:betafrom
sleitor wants to merge 1 commit intodrizzle-team:betafrom
Conversation
…on errors libSQL/Turso HTTP clients do not support manual begin/commit via execute() because each call is an independent HTTP request with no shared transaction context. This causes drizzle-kit push to fail with: QueryError: cannot commit - no transaction is active when a schema change requires table recreation (e.g. FK onDelete change). The connectToLibSQL function already exposes batchWithPragma() which wraps client.migrate() — the correct API for running DDL batches over HTTP. Fix: detect batchWithPragma on the db object and use it instead of manual begin/commit for libSQL connections. Regular SQLite drivers continue to use the begin/commit transaction path. D1-HTTP continues to run statements individually without transactions. Also consolidates verbose logging before the execution branch so all paths log SQL statements when --verbose is set. Closes drizzle-team#5489
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 #5489
libSQL/Turso HTTP clients do not support manual
begin/commitviaexecute()because each call is an independent HTTP request with no shared transaction context. This causesdrizzle-kit pushto fail with:when a schema change requires table recreation (e.g. changing a foreign key's
onDeleteaction).Root Cause
In
push-sqlite.ts, the push handler wraps DDL statements in manualbegin/committransactions:The outer
if (!('driver' in credentials))check was meant to skip this for D1-HTTP, butLibSQLCredentialsalso has nodriverfield, so the libSQL path falls into the transaction block too — and fails on HTTP.Fix
connectToLibSQLalready exposesbatchWithPragma()which wrapsclient.migrate()— the correct API for running DDL batches over the libSQL HTTP protocol.The fix detects
batchWithPragmaon the db object and uses it for libSQL connections. Regular SQLite drivers continue to use thebegin/committransaction path. D1-HTTP continues to run statements individually without transactions.Changes
drizzle-kit/src/cli/commands/push-sqlite.ts: detectdb.batchWithPragmaand use it for libSQL; fix D1 transaction skip (was broken — always ran transaction due to outer if-check); consolidate verbose logging across all execution paths