summaryrefslogtreecommitdiff
path: root/tests/migrations
diff options
context:
space:
mode:
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'