Skip to content

Commit 2eeee4c

Browse files
committed
improved renamed table detection
If a table has the same class name, but a different tablename, we now assume it's a deliberate rename. In situations where we ask users if it's a renamed table, the text is now more explicit (contains class name and tablename).
1 parent dfd8710 commit 2eeee4c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

piccolo/apps/migrations/auto/schema_differ.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,31 @@ def check_rename_tables(self) -> RenameTableCollection:
129129
drop_column_names
130130
)
131131
if len(same_column_names) > 0:
132+
if (
133+
drop_table.class_name == new_table.class_name
134+
and drop_table.tablename != new_table.tablename
135+
):
136+
# The class names are the same, but the tablename
137+
# has changed - we can assume this is a deliberate
138+
# rename.
139+
collection.append(
140+
RenameTable(
141+
old_class_name=drop_table.class_name,
142+
old_tablename=drop_table.tablename,
143+
new_class_name=new_table.class_name,
144+
new_tablename=new_table.tablename,
145+
)
146+
)
147+
continue
148+
132149
user_response = (
133150
self.auto_input
134151
if self.auto_input
135152
else input(
136-
f"Did you rename {drop_table.class_name} to "
137-
f"{new_table.class_name}? (y/N)"
153+
f"Did you rename {drop_table.class_name} "
154+
f"(tablename: {drop_table.tablename}) to "
155+
f"{new_table.class_name} "
156+
f"(tablename: {new_table.tablename})? (y/N)"
138157
)
139158
)
140159
if user_response.lower() == "y":

0 commit comments

Comments
 (0)