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) │ └───────┴─────────────────┴─────────────────┴──────────┴────────────────────────────────────────┘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.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Assistant
I’ll first inspect the repository structure and search for the ALTER COLUMN implementation and any handling of
sqlite_sequence. Then I’ll reproduce the behavior using the project’s existing test or CLI tooling before making a targeted fix. - Assistant
ripgrepis unavailable, so I’ll use recursivegrepwhile excluding build metadata. I’ll also inspect the workspace package layout and repository guidance to identify the narrowest crate and its test conventions. - Assistant
The relevant compiler is
core/translate/alter.rs; it already updates sequence rows on table rename, suggesting ALTER COLUMN needs analogous conditional cleanup. I’ll inspect its helper functions and ALTER COLUMN compilation path, plus DROP TABLE’s sequence-row deletion, so the fix reuses established bytecode patterns and transaction semantics. - Assistant
I need the complete helper and branch without truncation. I’ll locate exact line ranges and inspect how the old/new table metadata exposes
AUTOINCREMENT, as the cleanup should occur only when ALTER COLUMN removes the property—not when changing an unrelated column or preserving it. - Assistant
The schema model has a direct
has_autoincrementflag. I’ll now read the full ALTER COLUMN branch and schema DROP helper to determine the correct emission point relative to schema SQL updates, row rewrites, and schema reload. - Assistant
The key subtlety is that mutating only
columns_mut()does not recomputehas_autoincrement; the rewritten table clone remains marked autoincrement even after replacing its PK column. Therefore, cleanup should be based on the operation semantics (btree.has_autoincrementand ALTER COLUMN targeting its rowid-alias column), not the clone’s stale flag. I’ll inspect the remaining branch and determine whetherColumnexposes rowid alias only through table context. - Assistant
The ALTER branch emits schema SQL replacement, optional row rewrite, then updates the in-memory schema. Sequence cleanup can safely be emitted before the schema cookie/update and should use the normalized table name matching existing rename/drop behavior. I’ll inspect the existing DROP sequence deletion helper and table-name normalization details, then build the CLI once and reproduce the issue.
- Assistant
The established DROP behavior intentionally leaves the internal
sqlite_sequencetable but deletes the affected table’s row, including when it is the last autoincrement table. That aligns with SQLite semantics and the issue’s “stale” entry concern. Before editing, I’ll reproduce via the noninteractive CLI using the reported SQL and capture the stale row. - Assistant
I reproduced the exact stale row (
t|2). I’ll add a small sequence-entry deletion emitter modeled on DROP TABLE, scoped to the correct database (including attached schemas), and invoke it only when a true ALTER COLUMN replaces the original autoincrement rowid-alias column. Rename-column and unrelated-column operations must preserve the counter. - Assistant
The implementation is in place. I’ll now rerun the reproduction and exercise preservation/cleanup edge cases: altering a non-key column, renaming the autoincrement column, retaining another table’s sequence row, and quoted mixed-case names. This verifies both absence of stale state and avoidance of over-deletion.
- Assistant
All targeted runtime cases passed: the stale row is removed, unrelated counters continue from the prior value, rename-column preserves its counter, other tables remain untouched, and normalized quoted names are handled. I’ll test transactional rollback and duplicate stale rows, then run the existing ALTER COLUMN sqltest suite and core crate tests/checks.
- Assistant
Transactional rollback and deletion of duplicate matching rows both passed. The core translation tests passed (132/132). My first sqltest invocation used an unsupported filter flag; I’ll rerun correctly by passing the ALTER COLUMN test file path directly, then run
cargo check/Clippy on the core crate and inspect the final diff/status. - Assistant
cargo checkand Clippy both passed. The Make target appendsARGSafter a fixed directory and therefore ran the entire suite rather than one file; 9,692 tests passed, while 8 unrelated snapshot mismatches generated.snap.newartifacts. I’ll remove only those generated untracked files, then invoke the runner directly againstturso-tests/alter_column.sqltestand verify no repository artifacts remain. - Assistant
The dedicated ALTER COLUMN suite passed all 57 tests. I’ll minimize the patch by restoring unrelated import ordering changed by the newer formatter, then test an attached database to confirm the helper’s
database_idscoping and perform a final compile/diff review. - Assistant
The patch is now limited to 61 added lines and still compiles. The attached-database attempt was blocked because the CLI requires its explicit experimental flag; I’ll rerun with that flag rather than treating the parse rejection as a product failure.
- Assistant
Attached-database cleanup passed and did not create or touch
main.sqlite_sequence. One last formatting nuance remains: restoring preexisting import order minimized the diff, but I’ll runcargo fmt --checkto determine whether the pinned toolchain requires the reordered imports; if so, I’ll retain formatter output as required by repository policy rather than an artificially smaller diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.