mirror of
https://github.com/django/django.git
synced 2025-06-04 19:19:13 +00:00
Fixed #36165 -- Made PostgreSQL's SchemaEditor._delete_index_sql() respect the "sql" argument.
This is a follow up of bd366ca2aeffa869b7dbc0b0aa01caea75e6dc31. Thank you Daniel Finch for the report.
This commit is contained in:
parent
e2a8f4dac8
commit
1f33f21fca
@ -322,7 +322,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
|||||||
self.execute(index.remove_sql(model, self, concurrently=concurrently))
|
self.execute(index.remove_sql(model, self, concurrently=concurrently))
|
||||||
|
|
||||||
def _delete_index_sql(self, model, name, sql=None, concurrently=False):
|
def _delete_index_sql(self, model, name, sql=None, concurrently=False):
|
||||||
sql = (
|
sql = sql or (
|
||||||
self.sql_delete_index_concurrently
|
self.sql_delete_index_concurrently
|
||||||
if concurrently
|
if concurrently
|
||||||
else self.sql_delete_index
|
else self.sql_delete_index
|
||||||
|
@ -665,6 +665,30 @@ class SchemaTests(PostgreSQLTestCase):
|
|||||||
str(index.create_sql(CharFieldModel, editor)),
|
str(index.create_sql(CharFieldModel, editor)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_custom_sql(self):
|
||||||
|
class CustomSQLIndex(PostgresIndex):
|
||||||
|
sql_create_index = "SELECT 1"
|
||||||
|
sql_delete_index = "SELECT 2"
|
||||||
|
|
||||||
|
def create_sql(self, model, schema_editor, using="", **kwargs):
|
||||||
|
kwargs.setdefault("sql", self.sql_create_index)
|
||||||
|
return super().create_sql(model, schema_editor, using, **kwargs)
|
||||||
|
|
||||||
|
def remove_sql(self, model, schema_editor, **kwargs):
|
||||||
|
kwargs.setdefault("sql", self.sql_delete_index)
|
||||||
|
return super().remove_sql(model, schema_editor, **kwargs)
|
||||||
|
|
||||||
|
index = CustomSQLIndex(fields=["field"], name="custom_sql_idx")
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
(index.create_sql, CustomSQLIndex.sql_create_index),
|
||||||
|
(index.remove_sql, CustomSQLIndex.sql_delete_index),
|
||||||
|
]
|
||||||
|
for operation, expected in operations:
|
||||||
|
with self.subTest(operation=operation.__name__):
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
self.assertEqual(expected, str(operation(CharFieldModel, editor)))
|
||||||
|
|
||||||
def test_op_class(self):
|
def test_op_class(self):
|
||||||
index_name = "test_op_class"
|
index_name = "test_op_class"
|
||||||
index = Index(
|
index = Index(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user