Repository navigation
Preserve hidden row IDs when a column shadows rowid #1000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3130,10 +3130,24 @@ def fk_with_renamed_columns(fk: ForeignKey) -> ForeignKey: | |
| for from_, to_ in copy_from_to.items(): | ||
| old_cols.append(from_) | ||
| new_cols.append(to_) | ||
| # Ensure rowid is copied too | ||
| if "rowid" not in new_cols: | ||
| new_cols.insert(0, "rowid") | ||
| old_cols.insert(0, "rowid") | ||
|
|
||
| # A declared column can shadow a rowid alias on either side of a rename. | ||
| def rowid_alias(columns: Iterable[str]) -> str | None: | ||
| declared = {fold_identifier_case(column) for column in columns} | ||
| return next( | ||
| ( | ||
| alias | ||
| for alias in ("rowid", "_rowid_", "oid") | ||
| if alias not in declared | ||
| ), | ||
| None, | ||
| ) | ||
|
|
||
| source_rowid = rowid_alias(existing_columns) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a populated Useful? React with 👍 / 👎. |
||
| target_rowid = rowid_alias(new_cols) | ||
| if source_rowid and target_rowid: | ||
| new_cols.insert(0, target_rowid) | ||
| old_cols.insert(0, source_rowid) | ||
|
|
||
| def _copy_expr(col): | ||
| if col in text_to_numeric_cols: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a table declares
rowid INTEGER PRIMARY KEYalongside_rowid_ TEXTandoid TEXT,rowidstill aliases the actual integer row ID, but this helper treats all three names as shadowed and returnsNone. Starting with a single row whose ID is 42,transform(drop={'rowid'}, pk=None)consequently skips the hidden-ID copy and silently renumbers that row to 1; the parent commit preserved 42. Allow an integer-primary-key alias to supply source row IDs even when every magic alias is declared.Useful? React with 👍 / 👎.