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
Reproduced. Now let's understand exactly when we should delete the sqlite_sequence row: when the altered column was the rowid alias AND the table had
has_autoincrement, and after the alter, the column is no longer a valid autoincrement rowid alias (e.g., type changed away from INTEGER, or PK removed).Assistant
Let's add the shared helper function right before
translate_drop_table, and refactor the inline code to call it.Assistant
Now let's replace the inline block within
translate_drop_tablewith a call to this helper.Assistant
Now let's make sure the helper is exported and check compile of schema.rs alone quickly (via cargo check later). Now let's look for how to call it from alter.rs.
Assistant
Now let's insert a flag computation right after this match block.
Assistant
Now let's build to check for compile errors.
Assistant
Compiles clean. Now let's rebuild the CLI and test.
Assistant
The
sqlite_sequencetable is now empty (no rows returned for the SELECT). Let's verify more thoroughly, including that the wholesqlite_sequencetable itself isn't deleted (it should just have no rows fort), and test edge cases: rename-only column (should preserve), and multiple autoincrement tables.Assistant
Rename column preserves the sequence entry (t stays), and altering a2/type properly removed t2's row while leaving t's untouched. Now let's test the case where ALTER COLUMN is applied but the column wasn't the autoincrement PK (no unintended deletion), and case where table doesn't have AUTOINCREMENT at all but is INTEGER PRIMARY KEY (should not touch sqlite_sequence since it never had one).
Assistant
Correct — non-PK column alteration doesn't touch sqlite_sequence, and PK/AUTOINCREMENT column
aremains untouched. Now let's test plainINTEGER PRIMARY KEY(no AUTOINCREMENT) column being altered — should never touch sqlite_sequence since it never had entries.Assistant
Now let's also run broader test suite for
drop_tableand general schema tests to ensure the refactor didn't break anything.Assistant
All 1775 tests pass. Now let's check clippy/fmt for the modified files.
Assistant
Now let's run clippy on the affected files.
Assistant
No clippy warnings. Now let's double check with the CLI, run the exact issue reproduction once more, and clean up test artifacts.
Assistant
The empty result for the
SELECT * FROM sqlite_sequenceconfirms the stale row is gone. Let's clean up temp files and finalize.Assistant
The diff looks clean and focused. Let me also verify the CDC (change data capture) path doesn't need special handling here — check if DROP TABLE's sqlite_sequence cleanup emits CDC entries (it doesn't seem to in the original code either), so we're consistent.
Assistant
Let's find the test runner for sqltest files and run this specific file.
Assistant
These are unrelated snapshot tests (hash-join bytecode / TPC-H query plan snapshots), not related to ALTER TABLE or sqlite_sequence. Let's verify they fail even without our changes (pre-existing).
Assistant
Confirmed — these 8 failures are pre-existing (before our change) and unrelated snapshot tests. Let's restore our changes.
Assistant
Let's clean up these generated
.snap.newfiles since they're just artifacts from running the pre-existing failing snapshot tests, not part of our fix.Assistant
Now let's rebuild core with our changes restored and re-confirm the fix works after the stash pop.
Assistant
The fix is confirmed working. Let's run the sqltests autoincr suite one more time plus a broader run of the alter-table related tests to be thorough.
Assistant
All good. Let's do a final review of the diff and re-run cargo core lib tests once more to be safe after stash pop.
Assistant
Everything's clean. Now let's go through the checklist.
Assistant
This diff looks correct, minimal, and well-tested. Now let's go through the checklist explicitly.
Checklist review:
Assistant
All checklist items are satisfied. Let's do one final sanity check of
git statusbefore submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.