mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-08 01:24:20 +02:00
Fix transform() raising TransformError when renaming an indexed column
Renaming a column that has an index is valid — the index should be recreated using the new column name. Only dropping a column makes an index unrecoverable and warrants the error.
This commit is contained in:
parent
6a456830ca
commit
95826535c7
2 changed files with 33 additions and 11 deletions
|
|
@ -2851,13 +2851,17 @@ class Table(Queryable):
|
|||
if keep_table:
|
||||
sqls.append(f"DROP INDEX IF EXISTS {quote_identifier(index.name)};")
|
||||
for col in index.columns:
|
||||
if col in rename or col in drop:
|
||||
if col in drop:
|
||||
raise TransformError(
|
||||
f"Index '{index.name}' column '{col}' is not in updated table '{self.name}'. "
|
||||
f"You must manually drop this index prior to running this transformation "
|
||||
f"and manually recreate the new index after running this transformation. "
|
||||
f"The original index sql statement is: `{index_sql}`. No changes have been applied to this table."
|
||||
)
|
||||
elif col in rename:
|
||||
index_sql = index_sql.replace(
|
||||
quote_identifier(col), quote_identifier(rename[col])
|
||||
)
|
||||
sqls.append(index_sql)
|
||||
return sqls
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue