mirror of
https://github.com/django/django.git
synced 2025-07-29 08:04:27 +00:00
Fixed #35704 -- Fixed reduction for AddIndex subclasses.
This commit is contained in:
parent
ad7f8129f3
commit
f5ddd54986
4 changed files with 90 additions and 39 deletions
|
@ -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"})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue