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 ALTER COLUMN / sqlite_sequence handling so we can reproduce the leftover sequence row.
- Assistant
Let me look at AGENTS.md and search for alter column and sqlite_sequence related code.
- Assistant
Let me search for alter column and sqlite_sequence related code.
- Assistant
I'll inspect alter table translation and how drop/autoincrement interact with sqlite_sequence.
- Assistant
I'll read the alter column logic and rename-of-sqlite_sequence handling next.
- Assistant
Let me look at the AlterColumn path around line 1564.
- Assistant
Let me continue reading the alter column logic and also look for drop table sequence cleanup.
- Assistant
There's a comment in schema.rs about drops table resetting sequence. Let me look at that and also drop table handling.
- Assistant
I'll experiment with SQLite's behavior for this case and examine the rest of the alter-column path.
- Assistant
I'll check how drop table cleans sequence rows and inspect alter-column end handling.
- Assistant
I'll read the remainder of the alter-column path to see how the schema is rewritten.
- Assistant
Let me continue reading until the end of alter column handling.
- Assistant
Let me continue to see what happens at the end of AlterColumn.
- Assistant
I'll use
emit_rename_sqlite_sequence_entryas a template and check DropColumn for related sequence cleanup. - Assistant
Let me look at the AlterColumn opcode implementation and how has_autoincrement is updated.
- Assistant
Let me continue reading op_alter_column to see if has_autoincrement is cleared.
- Assistant
I'll inspect how column alteration updates autoincrement and related schema metadata.
- Assistant
There's already an alter_table.sqltest. Let me look at it and also autoincr.
- Assistant
I'll inspect whether DROP COLUMN handles date autoincrement, and how column PK/rowid alias is typed.
- Assistant
I'll check Column construction and complete the end of op_alter_column.
- Assistant
Let me open execute.rs at the rest of op_alter_column.
- Assistant
I'll check unique_sets creation for INTEGER PRIMARY KEY AUTOINCREMENT tables.
- Assistant
I'll probe whether sqlite_sequence is still updated after the alter.
- Assistant
I'll confirm whether
has_autoincrementstays true after ALTER and inspect related insert behavior. - Assistant
I'll inspect how CREATE TABLE is rewritten in the AlterColumn SQL function.
- Assistant
I'll dig into how stale primary_key_columns interact after alter.
- Assistant
I accidentally wrote Arabic text. Let me redo.
- Assistant
I'll check whether the logical-to-physical map is updated when a rowid alias is removed.
- Assistant
Let me look at ColumnsMut Drop or update map:
- Assistant
Looking at build_logical_to_physical_map - it uses columns' is_rowid_alias and primary_key_columns. If primary_key_columns still has the column after alter, but column.is_rowid_alias is false, the map...
- Assistant
How does rowid alias work with the physical map then?
- Assistant
Looking at builder for make record affinity:
- Assistant
I'll finish reading
emit_rename_sqlite_sequence_entryand then implement the delete helper. - Assistant
I'll also check how table names are stored in sqlite_sequence.
- Assistant
I'll craft a focused fix: delete the sequence entry and clear
has_autoincrementwhen autoincrement is removed. - Assistant
Need to navigate to the right location first.
- Assistant
Now I can edit.
- Assistant
I'll wire the helper into the AlterColumn path next.
- Assistant
I'll add detection of autoincrement removal and call the emit just before SetCookie/AlterColumn.
- Assistant
There's a problem - after
get_columnreturns, we might callget_columnagain with col_name. But the first get' gives a reference old_col_ref. Then have_holdingons . If get_column returns a borrowe... - Assistant
I'll call the helper near the end of the AlterColumn path.
- Assistant
I'll add the delete call before SetCookie, matching DROP TABLE that cleans sequence before DropTable schema instruction.
- Assistant
I'll update
op_alter_columnto clearhas_autoincrementand fixprimary_key_columnswhen the PK is stripped. - Assistant
I'll update the schema mutation path in
op_alter_column. - Assistant
I'll verify how table names are stored in the schema versus sqlite_sequence.
- Assistant
Looking at insert table.name -.
how is table_name set in create_table?
- Assistant
table.name is normalize_ident'd. Good.
- Assistant
I'll build and reproduce the original issue to verify the و fix.
- Assistant
Build succeeded. Let me reproduce the исход issue.
- Assistant
I'll run the related autoincrement and alter_table sqltests.
- Assistant
Need to check how to run multiple filters.
- Assistant
Hmm - "All tests passed" but 0 test runs? Total time 3.88ms with no count. Maybe filter didn't match. Let me check.
- Assistant
Let me try running with path.
- Assistant
Oh it ran all tests. Looking at usage - PATHS is the path. Let me check properly.
- Assistant
So PATH is required and filter by test name. Let me run oddly with paths.
- Assistant
All 240 tests passed. Let me also check turso-tests for altercolumn related.
- Assistant
There's a turso-tests/alter_column.sqltest - perfection.
- Assistant
I'll run a few more edge cases: mixed-case table names and altering a non-autoincrement column.
- Assistant
Need to run from root
- Assistant
I'll check how
table_nameis determined during ALTER translation. - Assistant
I'll review the full diff and run a quick format check.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.