ISSUE DESCRIPTION alter col leaves sqlitesequence table behind note that i'm unsure of…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- Assistant
I'll start by exploring the repository structure and locating the code that handles ALTER COLUMN and sqlite_sequence.
- Assistant
Let me search more specifically for alter column and sqlite_sequence handling.
- Assistant
Let me check the core directory structure.
- Assistant
Let me search again with different approaches.
- Assistant
Found
alter.rs— switching to grep and inspecting it. - Assistant
Inspecting AlterColumn handling and sqlite_sequence cleanup logic in alter.rs.
- Assistant
Looking at the AlterColumn path and related drop/table rewrite logic.
- Assistant
I used wrong sed syntax - should use commas not colons.
- Assistant
Looking for how drop table handles sqlite_sequence and when autoincrement is tracked.
- Assistant
Checking DROP TABLE and DROP COLUMN handling for sqlite_sequence cleanup.
- Assistant
Let me look at translate_drop_table for how it handles sqlite_sequence.
- Assistant
Found the drop sequence handling — reading that section next.
- Assistant
Inspecting the AlterColumn VDBE instruction and schema updates for autoincrement.
- Assistant
Let me search for AlterColumn definition
- Assistant
Let me read the op_alter_column function and how has_autoincrement is updated.
- Assistant
I need to see more of this function and also understand whether ALTER column that removes PRIMARY KEY autoincrement is supposed to update has_autoincrement.
- Assistant
Checking drop column and how BTreeTable tracks autoincrement after schema changes.
- Assistant
Checking for existing tests and docs about this behavior.
- Assistant
There's a test about drop column preserving autoincrement — inspecting those next.
- Assistant
Reproducing the issue first with the CLI or a quick Rust test.
- Assistant
Reproducing the bug with tursodb.
- Assistant
Checking DROP TABLE cleanup of sqlite_sequence when it's the last autoincrement table.
- Assistant
Checking in-memory state after ALTER and whether autoincrement is incorrectly preserved.
- Assistant
Investigating how inserts use
has_autoincrementand how related metadata is maintained. - Assistant
Looking at Column::try_from and PK/autoincrement interaction on alter.
- Assistant
Checking primary key with table-level AUTOINCREMENT handling on alter.
- Assistant
Confirming altering a non-autoincrement column keeps AUTOINCREMENT.
- Assistant
Good. So the case is specifically when we ALTER COLUMN the autoincrement PK column itself.
- Assistant
Checking what happens when altering a column that is part of a table-level or composite PK.
- Assistant
Checking table-level single-column PRIMARY KEY behavior.
- Assistant
Implementing cleanup: adding a helper to delete the sequence entry and updating AlterColumn translation and the VDBE op.
- Assistant
Adding the delete helper and wiring it into the AlterColumn path.
- Assistant
I'll use the edit command to add the delete function after the rename function.
- Assistant
Wiring the call into the AlterColumn path.
- Assistant
Let me read the section around line 1639 and 2070-2110 to make the right edit.
- Assistant
I'll add the lost_autoincrement detection after we have column_index, and emit delete before SetCookie.
- Assistant
Fixing the comment and emitting the sequence delete before SetCookie.
- Assistant
Now add the emit call before SetCookie.
- Assistant
I need to insert the emit_delete call before SetCookie at line 2107.
- Assistant
There's a stray
});on line 2129 — removing it. - Assistant
Updating
op_alter_columnto clearhas_autoincrementwhen the AUTOINCREMENT column is altered. - Assistant
I need to capture whether we're losing autoincrement before replacing columns.
- Assistant
I'll open the execute.go file and make the edit.
- Assistant
I'll replace the section that handles primary_key_columns and the rowid alias maintenance to also handle loses autoincrement.
- Assistant
Fixing a potential borrow conflict with
existing_column. - Assistant
Building and verifying the fix.
- Assistant
Build succeeded. Reproducing the original issue.
- Assistant
Checking the no-insert case and whether the empty
sqlite_sequencetable remains (expected SQLite behavior): - Assistant
Running related alter-column and autoincrement tests.
- Assistant
Checking how many alter-column tests actually ran:
- Assistant
Let me check the test runner help.
- Assistant
It ran all tests - the path was treated incorrectly. Let me run properly.
- Assistant
All alter_column tests passed. Running autoincrement-related tests next.
- Assistant
Checking quoted/case-sensitive table names for sequence cleanup.
- Assistant
Running cargo fmt, then submitting.
- Assistant
Final verification of the original issue scenario:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.