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
Let me look at how DROP TABLE cleans up sqlite_sequence, and check the table's autoincrement flag.
- Assistant
Now let me check what
Insn::AlterColumndoes at runtime to confirm the in-memory schema is updated: - Assistant
Let me reproduce the issue first, including behavior after the ALTER within the same session:
- Assistant
There are several related edge cases here. Let me probe current behavior for PK declaration variants:
- Assistant
Now add the condition and call in the AlterColumn branch:
- Assistant
Main case fixed. Now the table-level PK variants:
- Assistant
Now append the tests:
- Assistant
TCL isn't available in this environment; the full sqltest suite (preferred runner) already passed. Waiting on
cargo test -p turso_core: - Assistant
Rollback correctly restores both the sequence entry and autoincrement behavior. Waiting on the unit test suite:
- Assistant
The diff is complete. Now waiting for the unit test suite to finish before summarizing.
- Assistant
While tests run, here's a summary of what was done:
Changes
Bug:
ALTER TABLE t ALTER COLUMN a TO a2 TEXTon an AUTOINCREMENT column left a stalesqlite_sequencerow behind — and worse, the altering connection kept a stale in-memoryhas_autoincrementflag, so subsequent inserts kept bumping the sequence for a table that no longer has AUTOINCREMENT.Semantics (no SQLite precedent since ALTER COLUMN is a Turso extension): ALTER COLUMN on the AUTOINCREMENT rowid-alias column always drops AUTOINCREMENT — the new definition can't re-declare PRIMARY KEY (already rejected) — so the sequence entry goes with it. RENAME COLUMN preserves everything.
- Assistant
All green:
cargo test -p turso_core— 1775 passed, 0 failed.Final result
The fix is complete. Three coordinated changes:
File Change core/translate/alter.rsNew emit_delete_sqlite_sequence_entryhelper; theAlterColumnbranch emits it when the altered column is the AUTOINCREMENT rowid alias, deleting the table's row in the same statement - Assistant
That was the earlier redundant monitor timing out — the test run it was watching already completed successfully (1775 passed, 0 failed). No action needed; the task is done.
To recap the final state:
- Fix implemented in
core/translate/alter.rs(sequence-row deletion) andcore/vdbe/execute.rs(AUTOINCREMENT keyword stripping in the schema rewrite + stale in-memory flag cleared) - Tests added in
testing/sqltests/turso-tests/alter_column.sqltest(5 cases, all passing) - All checks green: sqltest suite (1297 passed),
cargo test -p turso_core(1775 passed), clippy--deny=warnings,cargo fmt
The working tree has the three modified files uncommitted — let me know if you'd like me to commit them.
- Fix implemented in
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.