diff options
author | Andrew Godwin <andrew@aeracode.org> | 2013-10-16 11:09:33 +0100 |
---|---|---|
committer | Andrew Godwin <andrew@aeracode.org> | 2013-10-16 11:09:33 +0100 |
commit | 42f8666f6aed126d9606e00688087a76dd17afc6 (patch) | |
tree | 122b008ecf66647eb12e68fc66402075f64c6c70 /tests | |
parent | 694d7da6c53b9ad35381dccdf4f688771b0b932e (diff) | |
download | django-42f8666f6aed126d9606e00688087a76dd17afc6.tar.gz |
Improve migration optimizer to be able to optimize through other ops
Diffstat (limited to 'tests')
-rw-r--r-- | tests/migrations/test_optimizer.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/migrations/test_optimizer.py b/tests/migrations/test_optimizer.py index f2b6e58a84..c7913d3352 100644 --- a/tests/migrations/test_optimizer.py +++ b/tests/migrations/test_optimizer.py @@ -93,3 +93,65 @@ class OptimizerTests(TestCase): ], [], ) + + def test_optimize_through_create(self): + """ + We should be able to optimize away create/delete through a create or delete + of a different model, but only if the create operation does not mention the model + at all. + """ + # These should work + self.assertOptimizesTo( + [ + migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), + migrations.CreateModel("Bar", [("size", models.IntegerField())]), + migrations.DeleteModel("Foo"), + ], + [ + migrations.CreateModel("Bar", [("size", models.IntegerField())]), + ], + ) + self.assertOptimizesTo( + [ + migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), + migrations.CreateModel("Bar", [("size", models.IntegerField())]), + migrations.DeleteModel("Bar"), + migrations.DeleteModel("Foo"), + ], + [], + ) + self.assertOptimizesTo( + [ + migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), + migrations.CreateModel("Bar", [("size", models.IntegerField())]), + migrations.DeleteModel("Foo"), + migrations.DeleteModel("Bar"), + ], + [], + ) + # This should not work - FK should block it + self.assertOptimizesTo( + [ + migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), + migrations.CreateModel("Bar", [("other", models.ForeignKey("testapp.Foo"))]), + migrations.DeleteModel("Foo"), + ], + [ + migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), + migrations.CreateModel("Bar", [("other", models.ForeignKey("testapp.Foo"))]), + migrations.DeleteModel("Foo"), + ], + ) + # This should not work - bases should block it + self.assertOptimizesTo( + [ + migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), + migrations.CreateModel("Bar", [("size", models.IntegerField())], bases=("testapp.Foo", )), + migrations.DeleteModel("Foo"), + ], + [ + migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), + migrations.CreateModel("Bar", [("size", models.IntegerField())], bases=("testapp.Foo", )), + migrations.DeleteModel("Foo"), + ], + ) |