summaryrefslogtreecommitdiff
path: root/tests/migrations
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes.ljungberg@gmail.com>2021-10-15 22:17:26 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-10-18 08:25:23 +0200
commit86971c40909430a798e4e55b140004c4b1fb02ff (patch)
treec0a04010d73086c968ec0bcfe2f7d982ba01d87e /tests/migrations
parent0d4e575c96d408e0efb4dfd0cbfc864219776950 (diff)
Fixed #33194 -- Fixed migrations when altering a field with functional indexes/unique constraints on SQLite.
This adjusts Expressions.rename_table_references() to only update alias when needed. Regression in 83fcfc9ec8610540948815e127101f1206562ead. Co-authored-by: Simon Charette <charettes@users.noreply.github.com>
Diffstat (limited to 'tests/migrations')
-rw-r--r--tests/migrations/test_operations.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 5ae75a477b..11961a1f40 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -2106,6 +2106,25 @@ class OperationTests(OperationTestBase):
self.assertEqual(definition[1], [])
self.assertEqual(definition[2], {'model_name': 'Pony', 'name': index_name})
+ @skipUnlessDBFeature('supports_expression_indexes')
+ def test_alter_field_with_func_index(self):
+ app_label = 'test_alfuncin'
+ index_name = f'{app_label}_pony_idx'
+ table_name = f'{app_label}_pony'
+ project_state = self.set_up_test_model(
+ app_label,
+ indexes=[models.Index(Abs('pink'), name=index_name)],
+ )
+ operation = migrations.AlterField('Pony', 'pink', models.IntegerField(null=True))
+ new_state = project_state.clone()
+ operation.state_forwards(app_label, new_state)
+ with connection.schema_editor() as editor:
+ operation.database_forwards(app_label, editor, project_state, new_state)
+ self.assertIndexNameExists(table_name, index_name)
+ with connection.schema_editor() as editor:
+ operation.database_backwards(app_label, editor, new_state, project_state)
+ self.assertIndexNameExists(table_name, index_name)
+
def test_alter_field_with_index(self):
"""
Test AlterField operation with an index to ensure indexes created via
@@ -2664,6 +2683,26 @@ class OperationTests(OperationTestBase):
'name': 'covering_pink_constraint_rm',
})
+ def test_alter_field_with_func_unique_constraint(self):
+ app_label = 'test_alfuncuc'
+ constraint_name = f'{app_label}_pony_uq'
+ table_name = f'{app_label}_pony'
+ project_state = self.set_up_test_model(
+ app_label,
+ constraints=[models.UniqueConstraint('pink', 'weight', name=constraint_name)]
+ )
+ operation = migrations.AlterField('Pony', 'pink', models.IntegerField(null=True))
+ new_state = project_state.clone()
+ operation.state_forwards(app_label, new_state)
+ with connection.schema_editor() as editor:
+ operation.database_forwards(app_label, editor, project_state, new_state)
+ if connection.features.supports_expression_indexes:
+ self.assertIndexNameExists(table_name, constraint_name)
+ with connection.schema_editor() as editor:
+ operation.database_backwards(app_label, editor, new_state, project_state)
+ if connection.features.supports_expression_indexes:
+ self.assertIndexNameExists(table_name, constraint_name)
+
def test_add_func_unique_constraint(self):
app_label = 'test_adfuncuc'
constraint_name = f'{app_label}_pony_abs_uq'