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.
sqlturso> 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
Investigating how
ALTER COLUMNandsqlite_sequenceare handled so we can remove stale entries when autoincrement is dropped. - Assistant
Implementing the fix: adding a helper and sqlite_sequence cleanup in the ALTER COLUMN path, and updating in-memory schema in
op_alter_column. - Assistant
Capturing
was_autoincrement_columnbefore the column is replaced. - Assistant
The bug was that
ALTER COLUMNremovedAUTOINCREMENTfrom the schema SQL but left thesqlite_sequencerow and the in-memoryhas_autoincrementflag untouched.Fix
-
emit_delete_sqlite_sequence_entryinalter.rs— deletes the table's row fromsqlite_sequencewhen anALTER COLUMNremoves autoincrement (same pattern asDROP TABLE). -
column_definition_has_autoincrementinschema.rs— detects whether the new column definition preservesINTEGER PRIMARY KEY AUTOINCREMENT. -
op_alter_columninexecute.rs— when autoincrement is removed:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.