alter col leaves sqlitesequence table behind note that i'm unsure of alter column rules,…
- User
alter col leaves sqlite_sequence table behind note that i'm unsure of alter column rules, i was not able to find any docs or rules around this, but my expectation is when we change a autoincrement col to plain text there shouldn't be a stale sqlite_sequence.
turso> CREATE TABLE t(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); INSERT INTO t(b) VALUES('x'),('y'); ALTER TABLE t ALTER COLUMN a TO a2 TEXT; SELECT * FROM sqlite_sequence; SELECT sql FROM sqlite_schema WHERE name='t'; ┌──────┬─────┐ │ name │ seq │ ├──────┼─────┤ │ t │ 2 │ └──────┴─────┘ ┌──────────────────────────────────┐ │ sql │ ├──────────────────────────────────┤ │ CREATE TABLE t (a2 TEXT, b TEXT) │ └──────────────────────────────────┘ turso> select * from sqlite_schema; ┌───────┬─────────────────┬─────────────────┬──────────┬────────────────────────────────────────┐ │ type │ name │ tbl_name │ rootpage │ sql │ ├───────┼─────────────────┼─────────────────┼──────────┼────────────────────────────────────────┤ │ table │ sqlite_sequence │ sqlite_sequence │ 2 │ CREATE TABLE sqlite_sequence(name,seq) │ ├───────┼─────────────────┼─────────────────┼──────────┼────────────────────────────────────────┤ │ table │ t │ t │ 3 │ CREATE TABLE t (a2 TEXT, b TEXT) │ └───────┴─────────────────┴─────────────────┴──────────┴────────────────────────────────────────┘Interface
No new interfaces are introduced.
- Assistant
Now let me see how DROP TABLE cleans up sqlite_sequence entries, and how the table tracks autoincrement:
- Assistant
Now let me check how
Insn::AlterColumnupdates the in-memory schema (doeshas_autoincrementget cleared?): - Assistant
Let me see the start of the function to understand
btree,table_name,original_btree: - Assistant
Now add the call site in the ALTER COLUMN branch. First the flag, computed where the constraint checks are:
- Assistant
Now emit the deletion after the sqlite_schema update loop:
- Assistant
The
py-tursolink failure is a pre-existing environment issue (Python linker), unrelated to my change —turso_corecompiles clean. Let me verify the fix with the CLI: - Assistant
All pass. Now run the full alter/autoincrement test files to check for regressions, plus fmt:
- Assistant
All 37 autoinc tests pass. Now verify the new test actually fails without the fix — temporarily disable the emission and rerun:
- Assistant
Both new tests fail without the fix. Restoring it:
- Assistant
Clippy is clean. One final check — core unit tests touching alter:
- Assistant
Fixed.
ALTER TABLE ... ALTER COLUMNon the AUTOINCREMENT rowid-alias column now deletes the table'ssqlite_sequencerow instead of leaving it stale.Why it happened
The ALTER COLUMN branch in
core/translate/alter.rsrejects a new definition carryingPRIMARY KEY("PRIMARY KEY constraint cannot be altered"), which means altering theINTEGER PRIMARY KEY AUTOINCREMENTcolumn always strips the AUTOINCREMENT property from the rewritten schema — but nothing cleaned up the table's row insqlite_sequence, unlikeDROP TABLE(core/translate/schema.rs:2244) andRENAME TO(which renames the entry).The fix (
core/translate/alter.rs)- Added
emit_delete_sqlite_sequence_entry()(core/translate/alter.rs:250) — scanssqlite_sequenceand deletes the row matching the table name, mirroring DROP TABLE's cleanup. - In the ALTER COLUMN branch, computed
removes_autoincrement = !rename && btree.has_autoincrement && btree.columns()[column_index].is_rowid_alias()and emit the deletion after thesqlite_schemarewrite loop. RENAME COLUMN (rename == true) keeps constraints, so the entry survives there.
Verification
- Your exact repro now shows
sqlite_sequenceempty after the alter, and it persists across reopen withPRAGMA integrity_check→ok. - Scoping verified: altering a different column keeps the entry; renaming the autoincrement column keeps it (and the sequence keeps advancing); with two autoincrement tables only the altered one's row is removed.
- Added 3 tests to
testing/sqltests/turso-tests/alter_column.sqltest(skipped under MVCC since AUTOINCREMENT isn't supported there). Confirmed the two new positive tests fail without the fix and pass with it. - All 50 alter sqltests, all 37 autoinc sqltests,
cargo test -p turso_core alter,cargo fmt, andcargo clippy -p turso_core --all-features --all-targets --deny=warningspass. (Full-workspace build has a pre-existingpy-tursolinker failure in this environment, unrelated to the change.)
One note: SQLite itself has no
ALTER COLUMN— this is a Turso extension, so there's no upstream rule to match. The behavior implemented follows the same principle asDROP TABLE/RENAME TO:sqlite_sequencerows track tables that actually have AUTOINCREMENT, so removing the property removes the row. - Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →