Skip to content

Commit

Permalink
fix untracked migration state (#2663)
Browse files Browse the repository at this point in the history
a previous change to safe rename indexes did not separate database and state hence on Django does not recognize that the migration was applied. Running `makemigrations` command creates a new migration
  • Loading branch information
kelvin-muchiri authored Aug 9, 2024
1 parent 5a66f9c commit a228a4f
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def rename_index_if_exists(apps, schema_editor, old_name, new_name, table_name):
[old_name, table_name],
)
exists = cursor.fetchone()[0]

if exists:
cursor.execute(f"ALTER INDEX {old_name} RENAME TO {new_name}")

Expand Down Expand Up @@ -58,7 +59,35 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(rename_indexes, reverse_code=migrations.RunPython.noop),
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunPython(
rename_indexes, reverse_code=migrations.RunPython.noop
),
],
state_operations=[
migrations.RenameIndex(
model_name="instance",
new_name="logger_inst_deleted_da31a3_idx",
old_name="logger_inst_deleted_at_da31a3_idx",
),
migrations.RenameIndex(
model_name="instance",
new_name="logger_inst_xform_i_504638_idx",
old_name="logger_instance_id_xform_id_index",
),
migrations.RenameIndex(
model_name="instancehistory",
new_name="logger_inst_checksu_05f7bf_idx",
old_name="logger_inst_hist_checksum_05f7bf_idx",
),
migrations.RenameIndex(
model_name="instancehistory",
new_name="logger_inst_uuid_f5ae42_idx",
old_name="logger_inst_hist_uuid_f5ae42_idx",
),
],
),
migrations.AlterField(
model_name="instance",
name="date_created",
Expand Down

0 comments on commit a228a4f

Please sign in to comment.