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:
Claude 2026-08-02 14:38:05 +00:00
commit 95826535c7
No known key found for this signature in database
2 changed files with 33 additions and 11 deletions

View file

@ -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