summaryrefslogtreecommitdiff
path: root/tests/postgres_tests
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2024-08-22 19:26:42 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-09-03 12:51:06 +0200
commitf5ddd54986172c29c32f5d835584ea237d5a3781 (patch)
treed65cc2b95640189f5c47eff618c507385b0227bd /tests/postgres_tests
parentad7f8129f3d2de937611d72e257fb07d1306a855 (diff)
Fixed #35704 -- Fixed reduction for AddIndex subclasses.
Diffstat (limited to 'tests/postgres_tests')
-rw-r--r--tests/postgres_tests/test_operations.py50
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"})