mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #31468 -- Allowed specifying migration filename in Operation.
This adds also suggested filename for many built-in operations.
This commit is contained in:
committed by
Mariusz Felisiak
parent
5bd585a82d
commit
fa58450a9a
@@ -2495,6 +2495,11 @@ class AutodetectorSuggestNameTests(SimpleTestCase):
|
||||
]
|
||||
self.assertEqual(MigrationAutodetector.suggest_name(ops), 'animal_person')
|
||||
|
||||
def test_none_name(self):
|
||||
ops = [migrations.RunSQL('SELECT 1 FROM person;')]
|
||||
suggest_name = MigrationAutodetector.suggest_name(ops)
|
||||
self.assertIs(suggest_name.startswith('auto_'), True)
|
||||
|
||||
def test_auto(self):
|
||||
suggest_name = MigrationAutodetector.suggest_name([])
|
||||
self.assertIs(suggest_name.startswith('auto_'), True)
|
||||
|
||||
@@ -36,6 +36,7 @@ class OperationTests(OperationTestBase):
|
||||
],
|
||||
)
|
||||
self.assertEqual(operation.describe(), "Create model Pony")
|
||||
self.assertEqual(operation.migration_name_fragment, 'pony')
|
||||
# Test the state alteration
|
||||
project_state = ProjectState()
|
||||
new_state = project_state.clone()
|
||||
@@ -486,6 +487,7 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration
|
||||
operation = migrations.DeleteModel("Pony")
|
||||
self.assertEqual(operation.describe(), "Delete model Pony")
|
||||
self.assertEqual(operation.migration_name_fragment, 'delete_pony')
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_dlmo", new_state)
|
||||
self.assertNotIn(("test_dlmo", "pony"), new_state.models)
|
||||
@@ -559,6 +561,7 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration
|
||||
operation = migrations.RenameModel("Pony", "Horse")
|
||||
self.assertEqual(operation.describe(), "Rename model Pony to Horse")
|
||||
self.assertEqual(operation.migration_name_fragment, 'rename_pony_horse')
|
||||
# Test initial state and database
|
||||
self.assertIn(("test_rnmo", "pony"), project_state.models)
|
||||
self.assertNotIn(("test_rnmo", "horse"), project_state.models)
|
||||
@@ -855,6 +858,7 @@ class OperationTests(OperationTestBase):
|
||||
models.FloatField(null=True, default=5),
|
||||
)
|
||||
self.assertEqual(operation.describe(), "Add field height to Pony")
|
||||
self.assertEqual(operation.migration_name_fragment, 'pony_height')
|
||||
project_state, new_state = self.make_test_state("test_adfl", operation)
|
||||
self.assertEqual(len(new_state.models["test_adfl", "pony"].fields), 4)
|
||||
field = new_state.models['test_adfl', 'pony'].fields['height']
|
||||
@@ -1155,6 +1159,7 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration
|
||||
operation = migrations.RemoveField("Pony", "pink")
|
||||
self.assertEqual(operation.describe(), "Remove field pink from Pony")
|
||||
self.assertEqual(operation.migration_name_fragment, 'remove_pony_pink')
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_rmfl", new_state)
|
||||
self.assertEqual(len(new_state.models["test_rmfl", "pony"].fields), 2)
|
||||
@@ -1198,6 +1203,7 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration
|
||||
operation = migrations.AlterModelTable("Pony", "test_almota_pony_2")
|
||||
self.assertEqual(operation.describe(), "Rename table for Pony to test_almota_pony_2")
|
||||
self.assertEqual(operation.migration_name_fragment, 'alter_pony_table')
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_almota", new_state)
|
||||
self.assertEqual(new_state.models["test_almota", "pony"].options["db_table"], "test_almota_pony_2")
|
||||
@@ -1286,6 +1292,7 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration
|
||||
operation = migrations.AlterField("Pony", "pink", models.IntegerField(null=True))
|
||||
self.assertEqual(operation.describe(), "Alter field pink on Pony")
|
||||
self.assertEqual(operation.migration_name_fragment, 'alter_pony_pink')
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_alfl", new_state)
|
||||
self.assertIs(project_state.models['test_alfl', 'pony'].fields['pink'].null, False)
|
||||
@@ -1543,6 +1550,7 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration
|
||||
operation = migrations.RenameField("Pony", "pink", "blue")
|
||||
self.assertEqual(operation.describe(), "Rename field pink on Pony to blue")
|
||||
self.assertEqual(operation.migration_name_fragment, 'rename_pink_pony_blue')
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_rnfl", new_state)
|
||||
self.assertIn("blue", new_state.models["test_rnfl", "pony"].fields)
|
||||
@@ -1624,6 +1632,10 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration
|
||||
operation = migrations.AlterUniqueTogether("Pony", [("pink", "weight")])
|
||||
self.assertEqual(operation.describe(), "Alter unique_together for Pony (1 constraint(s))")
|
||||
self.assertEqual(
|
||||
operation.migration_name_fragment,
|
||||
'alter_pony_unique_together',
|
||||
)
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_alunto", new_state)
|
||||
self.assertEqual(len(project_state.models["test_alunto", "pony"].options.get("unique_together", set())), 0)
|
||||
@@ -1675,6 +1687,10 @@ class OperationTests(OperationTestBase):
|
||||
index = models.Index(fields=["pink"], name="test_adin_pony_pink_idx")
|
||||
operation = migrations.AddIndex("Pony", index)
|
||||
self.assertEqual(operation.describe(), "Create index test_adin_pony_pink_idx on field(s) pink of model Pony")
|
||||
self.assertEqual(
|
||||
operation.migration_name_fragment,
|
||||
'pony_test_adin_pony_pink_idx',
|
||||
)
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_adin", new_state)
|
||||
# Test the database alteration
|
||||
@@ -1702,6 +1718,10 @@ class OperationTests(OperationTestBase):
|
||||
self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
|
||||
operation = migrations.RemoveIndex("Pony", "pony_test_idx")
|
||||
self.assertEqual(operation.describe(), "Remove index pony_test_idx from Pony")
|
||||
self.assertEqual(
|
||||
operation.migration_name_fragment,
|
||||
'remove_pony_pony_test_idx',
|
||||
)
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_rmin", new_state)
|
||||
# Test the state alteration
|
||||
@@ -1789,6 +1809,10 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration
|
||||
operation = migrations.AlterIndexTogether("Pony", [("pink", "weight")])
|
||||
self.assertEqual(operation.describe(), "Alter index_together for Pony (1 constraint(s))")
|
||||
self.assertEqual(
|
||||
operation.migration_name_fragment,
|
||||
'alter_pony_index_together',
|
||||
)
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_alinto", new_state)
|
||||
self.assertEqual(len(project_state.models["test_alinto", "pony"].options.get("index_together", set())), 0)
|
||||
@@ -1845,6 +1869,10 @@ class OperationTests(OperationTestBase):
|
||||
self.assertEqual(
|
||||
gt_operation.describe(), "Create constraint test_add_constraint_pony_pink_gt_2 on model Pony"
|
||||
)
|
||||
self.assertEqual(
|
||||
gt_operation.migration_name_fragment,
|
||||
'pony_test_add_constraint_pony_pink_gt_2',
|
||||
)
|
||||
# Test the state alteration
|
||||
new_state = project_state.clone()
|
||||
gt_operation.state_forwards("test_addconstraint", new_state)
|
||||
@@ -1982,6 +2010,10 @@ class OperationTests(OperationTestBase):
|
||||
self.assertEqual(
|
||||
gt_operation.describe(), "Remove constraint test_remove_constraint_pony_pink_gt_2 from model Pony"
|
||||
)
|
||||
self.assertEqual(
|
||||
gt_operation.migration_name_fragment,
|
||||
'remove_pony_test_remove_constraint_pony_pink_gt_2',
|
||||
)
|
||||
# Test state alteration
|
||||
new_state = project_state.clone()
|
||||
gt_operation.state_forwards("test_removeconstraint", new_state)
|
||||
@@ -2212,6 +2244,7 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration (no DB alteration to test)
|
||||
operation = migrations.AlterModelOptions("Pony", {"permissions": [("can_groom", "Can groom")]})
|
||||
self.assertEqual(operation.describe(), "Change Meta options on Pony")
|
||||
self.assertEqual(operation.migration_name_fragment, 'alter_pony_options')
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_almoop", new_state)
|
||||
self.assertEqual(len(project_state.models["test_almoop", "pony"].options.get("permissions", [])), 0)
|
||||
@@ -2249,6 +2282,10 @@ class OperationTests(OperationTestBase):
|
||||
# Test the state alteration
|
||||
operation = migrations.AlterOrderWithRespectTo("Rider", "pony")
|
||||
self.assertEqual(operation.describe(), "Set order_with_respect_to on Rider to pony")
|
||||
self.assertEqual(
|
||||
operation.migration_name_fragment,
|
||||
'alter_rider_order_with_respect_to',
|
||||
)
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards("test_alorwrtto", new_state)
|
||||
self.assertIsNone(
|
||||
@@ -2298,6 +2335,7 @@ class OperationTests(OperationTestBase):
|
||||
]
|
||||
)
|
||||
self.assertEqual(operation.describe(), "Change managers on Pony")
|
||||
self.assertEqual(operation.migration_name_fragment, 'alter_pony_managers')
|
||||
managers = project_state.models["test_almoma", "pony"].managers
|
||||
self.assertEqual(managers, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user