1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Fixed #35717 -- Reduced Create/RemoveCollation operations when optimizing migrations.

This commit is contained in:
Adam Johnson 2024-08-29 18:52:31 +01:00 committed by Sarah Boyce
parent 68cee15a8f
commit cee95e6172
2 changed files with 24 additions and 1 deletions

View File

@ -237,6 +237,11 @@ class CreateCollation(CollationOperation):
def migration_name_fragment(self):
return "create_collation_%s" % self.name.lower()
def reduce(self, operation, app_label):
if isinstance(operation, RemoveCollation) and self.name == operation.name:
return []
return super().reduce(operation, app_label)
class RemoveCollation(CollationOperation):
"""Remove a collation."""

View File

@ -318,7 +318,7 @@ class CreateExtensionTests(PostgreSQLTestCase):
@unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific tests.")
class CreateCollationTests(PostgreSQLTestCase):
class CreateCollationTests(OptimizerTestBase, PostgreSQLTestCase):
app_label = "test_allow_create_collation"
@override_settings(DATABASE_ROUTERS=[NoMigrationRouter()])
@ -459,6 +459,24 @@ class CreateCollationTests(PostgreSQLTestCase):
"),",
)
def test_reduce_create_remove(self):
self.assertOptimizesTo(
[
CreateCollation(
"sample_collation",
"und-u-ks-level2",
provider="icu",
deterministic=False,
),
RemoveCollation(
"sample_collation",
# Different locale
"de-u-ks-level1",
),
],
[],
)
@unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific tests.")
class RemoveCollationTests(PostgreSQLTestCase):