Skip to content

fix(kit): use batchWithPragma for libSQL push to avoid HTTP transaction errors#5491

Open
sleitor wants to merge 1 commit intodrizzle-team:betafrom
sleitor:fix-5489
Open

fix(kit): use batchWithPragma for libSQL push to avoid HTTP transaction errors#5491
sleitor wants to merge 1 commit intodrizzle-team:betafrom
sleitor:fix-5489

Conversation

@sleitor
Copy link

@sleitor sleitor commented Mar 16, 2026

Summary

Fixes #5489

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. changing a foreign key's onDelete action).

Root Cause

In push-sqlite.ts, the push handler wraps DDL statements in manual begin/commit transactions:

if (!isD1) await db.run('begin');
// ...
if (!isD1) await db.run('commit');

The outer if (!('driver' in credentials)) check was meant to skip this for D1-HTTP, but LibSQLCredentials also has no driver field, so the libSQL path falls into the transaction block too — and fails on HTTP.

Fix

connectToLibSQL already exposes batchWithPragma() which wraps client.migrate() — the correct API for running DDL batches over the libSQL HTTP protocol.

The fix detects batchWithPragma on the db object and uses it for libSQL connections. Regular SQLite drivers continue to use the begin/commit transaction path. D1-HTTP continues to run statements individually without transactions.

Changes

  • drizzle-kit/src/cli/commands/push-sqlite.ts: detect db.batchWithPragma and 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

…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
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.

1 participant