Skip to content

Commit 7f630ea

Browse files
committed
Allow DELETE on sqlite_sequence in Turso
Real SQLite permits DELETE FROM sqlite_sequence as the documented way to reset an AUTOINCREMENT counter after TRUNCATE. Turso's delete translator blocks any table starting with "sqlite_"; exempt sqlite_sequence specifically. Fixes the "AUTO_INCREMENT not reset after TRUNCATE" failures in testInformationSchemaTablesAutoIncrement, testShowTableStatusAutoIncrement, etc. (the driver issues DELETE FROM sqlite_sequence WHERE name=... as the TRUNCATE emulation path).
1 parent 70393ec commit 7f630ea

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,35 @@ jobs:
404404
print('patched CollationSeq to alias MySQL collations')
405405
PY_COLLATION
406406
407+
# Real SQLite permits DELETE on sqlite_sequence (it's the documented
408+
# way to reset the AUTOINCREMENT counter after a TRUNCATE). Turso's
409+
# delete translator rejects any table whose name starts with
410+
# "sqlite_"; exempt sqlite_sequence specifically.
411+
python3 - <<'PY_DELETE_SEQ'
412+
p = 'core/translate/delete.rs'
413+
s = open(p).read()
414+
old = (
415+
" if !connection.is_nested_stmt()\n"
416+
" && !connection.is_mvcc_bootstrap_connection()\n"
417+
" && crate::schema::is_system_table(tbl_name)\n"
418+
" {\n"
419+
" crate::bail_parse_error!(\"table {tbl_name} may not be modified\");\n"
420+
" }\n"
421+
)
422+
new = (
423+
" if !connection.is_nested_stmt()\n"
424+
" && !connection.is_mvcc_bootstrap_connection()\n"
425+
" && crate::schema::is_system_table(tbl_name)\n"
426+
" && !tbl_name.eq_ignore_ascii_case(\"sqlite_sequence\")\n"
427+
" {\n"
428+
" crate::bail_parse_error!(\"table {tbl_name} may not be modified\");\n"
429+
" }\n"
430+
)
431+
assert old in s, 'delete.rs system-table guard not found'
432+
open(p, 'w').write(s.replace(old, new, 1))
433+
print('patched delete.rs to allow DELETE FROM sqlite_sequence')
434+
PY_DELETE_SEQ
435+
407436
echo '--- Patched stub! macro ---'
408437
sed -n '/macro_rules! stub/,/^}$/p' sqlite3/src/lib.rs
409438

0 commit comments

Comments
 (0)