[SQLite-kit] Fix column rename breaking INSERT INTO...SELECT during table recreate#5597
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 03ebf69ee1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (stmts) { | ||
| const recreate = stmts.find((s) => s.type === 'recreate_table') as JsonRecreateTableStatement | undefined; | ||
| if (recreate) { | ||
| recreate.columnRenames = renames; |
There was a problem hiding this comment.
Skip columnRenames when rename_column statement is retained
This assignment copies every alter_table_rename_column into recreate_table, even in flows where the rename statement is still executed (for example when rename_table is present and the combiner keeps prior statements). In that case migration order becomes RENAME COLUMN ... followed by recreate SQL that now selects the old name from the already-renamed table, so INSERT INTO ... SELECT fails with a missing-column error. columnRenames should only include renames that were removed from the final statement list, not renames that will run explicitly.
Useful? React with 👍 / 👎.
…olumn rename When rename_column coincides with table recreation, the generated INSERT INTO...SELECT now correctly uses old column names in SELECT while using new names in INSERT. Also strips retained rename_column statements when a recreate_table absorbs them via columnRenames, preventing double-rename when rename_table is present. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
03ebf69 to
22c20fc
Compare
Summary
Fixes #5587
When a SQLite column rename coincides with a table recreation (e.g., renaming a column while also changing its type or default value), the generated
INSERT INTO...SELECTmigration SQL uses the new column name in theSELECTclause. Since the old table still has the old column name, the migration fails.Before (broken):
After (fixed):
Root Cause
When
sqliteCombineStatements/libSQLCombineStatementscombine analter_table_rename_columnwith other statements that trigger table recreation, the column rename info is lost — the rename statement is dropped whenrecreate_tablereplaces existing statements, so the SQL generator uses new column names on both sides of theINSERT INTO...SELECT.Changes
jsonStatements.ts: Added optionalcolumnRenamesfield toJsonRecreateTableStatementstatementCombiner.ts: Track column renames per table during statement combination, inject them into anyrecreate_tablefor that table. WhencolumnRenamesis injected, also strip retainedalter_table_rename_columnstatements from the output — prevents double-rename whenrename_tablecauses the combiner to preserve (push) rather than replace statements.sqlgenerator.ts:SQLiteRecreateTableConvertorandLibSQLRecreateTableConvertorbuild a rename map and use old column names inSELECTwhile keeping new names inINSERTrename_table+rename_column+ type change on same table (verifies rename is absorbed into recreate, not retained as separate statement)Testing