From 604a1b6a663958a12366f597f899fb44b8d8381f Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 2 Mar 2025 12:29:13 +0100 Subject: [PATCH] Test reworking migration for mysql/postgresql --- ...index_instead_of_index_together_in_tags.py | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/evennia/typeclasses/migrations/0017_use_index_instead_of_index_together_in_tags.py b/evennia/typeclasses/migrations/0017_use_index_instead_of_index_together_in_tags.py index 4cb2f273fb..e192a66f8d 100644 --- a/evennia/typeclasses/migrations/0017_use_index_instead_of_index_together_in_tags.py +++ b/evennia/typeclasses/migrations/0017_use_index_instead_of_index_together_in_tags.py @@ -9,19 +9,34 @@ class Migration(migrations.Migration): ("typeclasses", "0016_alter_attribute_id_alter_tag_id"), ] - operations = [ - # First create the index with the old name that Django expects - migrations.AddIndex( - model_name="tag", - index=models.Index( - fields=["db_key", "db_category", "db_tagtype", "db_model"], - name="typeclasses_tag_db_key_db_category_db_tagtype_db_model_idx", - ), - ), - # Then rename it to the new name - migrations.RenameIndex( - model_name="tag", - new_name="typeclasses_db_key_be0c81_idx", - old_fields=("db_key", "db_category", "db_tagtype", "db_model"), - ), - ] + def get_operations(self, app_labels, schema_editor): + """Return database-specific operations""" + if schema_editor.connection.vendor == "sqlite": + # For SQLite, we know the two-step process works + return [ + migrations.AddIndex( + model_name="tag", + index=models.Index( + fields=["db_key", "db_category", "db_tagtype", "db_model"], + name="typeclasses_tag_db_key_db_category_db_tagtype_db_model_idx", + ), + ), + migrations.RenameIndex( + model_name="tag", + new_name="typeclasses_db_key_be0c81_idx", + old_fields=("db_key", "db_category", "db_tagtype", "db_model"), + ), + ] + else: + # For other databases, create the index directly with its final name + return [ + migrations.AddIndex( + model_name="tag", + index=models.Index( + fields=["db_key", "db_category", "db_tagtype", "db_model"], + name="typeclasses_db_key_be0c81_idx", + ), + ), + ] + + operations = [] # Will be populated at runtime by get_operations()