diff options
Diffstat (limited to 'tests/postgres_tests/test_operations.py')
| -rw-r--r-- | tests/postgres_tests/test_operations.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/tests/postgres_tests/test_operations.py b/tests/postgres_tests/test_operations.py index 5780348251..f344d4ae74 100644 --- a/tests/postgres_tests/test_operations.py +++ b/tests/postgres_tests/test_operations.py @@ -1,8 +1,9 @@ import unittest -from migrations.test_base import OperationTestBase +from migrations.test_base import OperationTestBase, OptimizerTestBase from django.db import IntegrityError, NotSupportedError, connection, transaction +from django.db.migrations.operations import RemoveIndex, RenameIndex from django.db.migrations.state import ProjectState from django.db.migrations.writer import OperationWriter from django.db.models import CheckConstraint, Index, Q, UniqueConstraint @@ -30,7 +31,7 @@ except ImportError: @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific tests.") @modify_settings(INSTALLED_APPS={"append": "migrations"}) -class AddIndexConcurrentlyTests(OperationTestBase): +class AddIndexConcurrentlyTests(OptimizerTestBase, OperationTestBase): app_label = "test_add_concurrently" def test_requires_atomic_false(self): @@ -129,6 +130,51 @@ class AddIndexConcurrentlyTests(OperationTestBase): ) self.assertIndexNotExists(table_name, ["pink"]) + def test_reduce_add_remove_concurrently(self): + self.assertOptimizesTo( + [ + AddIndexConcurrently( + "Pony", + Index(fields=["pink"], name="pony_pink_idx"), + ), + RemoveIndex("Pony", "pony_pink_idx"), + ], + [], + ) + + def test_reduce_add_remove(self): + self.assertOptimizesTo( + [ + AddIndexConcurrently( + "Pony", + Index(fields=["pink"], name="pony_pink_idx"), + ), + RemoveIndexConcurrently("Pony", "pony_pink_idx"), + ], + [], + ) + + def test_reduce_add_rename(self): + self.assertOptimizesTo( + [ + AddIndexConcurrently( + "Pony", + Index(fields=["pink"], name="pony_pink_idx"), + ), + RenameIndex( + "Pony", + old_name="pony_pink_idx", + new_name="pony_pink_index", + ), + ], + [ + AddIndexConcurrently( + "Pony", + Index(fields=["pink"], name="pony_pink_index"), + ), + ], + ) + @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific tests.") @modify_settings(INSTALLED_APPS={"append": "migrations"}) |
