mirror of https://github.com/django/django.git
Refs #23822 -- Made MigrationOptimizer aware of model managers
This commit is contained in:
parent
127f9e073d
commit
1f03d2d924
|
@ -211,6 +211,7 @@ class MigrationOptimizer(object):
|
||||||
fields=operation.fields,
|
fields=operation.fields,
|
||||||
options=operation.options,
|
options=operation.options,
|
||||||
bases=operation.bases,
|
bases=operation.bases,
|
||||||
|
managers=operation.managers,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -247,6 +248,7 @@ class MigrationOptimizer(object):
|
||||||
fields=operation.fields + [(other.name, other.field)],
|
fields=operation.fields + [(other.name, other.field)],
|
||||||
options=operation.options,
|
options=operation.options,
|
||||||
bases=operation.bases,
|
bases=operation.bases,
|
||||||
|
managers=operation.managers,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -261,6 +263,7 @@ class MigrationOptimizer(object):
|
||||||
],
|
],
|
||||||
options=operation.options,
|
options=operation.options,
|
||||||
bases=operation.bases,
|
bases=operation.bases,
|
||||||
|
managers=operation.managers,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -275,6 +278,7 @@ class MigrationOptimizer(object):
|
||||||
],
|
],
|
||||||
options=operation.options,
|
options=operation.options,
|
||||||
bases=operation.bases,
|
bases=operation.bases,
|
||||||
|
managers=operation.managers,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -290,6 +294,7 @@ class MigrationOptimizer(object):
|
||||||
],
|
],
|
||||||
options=operation.options,
|
options=operation.options,
|
||||||
bases=operation.bases,
|
bases=operation.bases,
|
||||||
|
managers=operation.managers,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,10 @@ class UnmigratedModel(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class EmptyManager(models.Manager):
|
||||||
|
use_in_migrations = True
|
||||||
|
|
||||||
|
|
||||||
class FoodQuerySet(models.query.QuerySet):
|
class FoodQuerySet(models.query.QuerySet):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ from django.db.migrations.optimizer import MigrationOptimizer
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
from .models import CustomModelBase, EmptyManager
|
||||||
|
|
||||||
|
|
||||||
class OptimizerTests(TestCase):
|
class OptimizerTests(TestCase):
|
||||||
"""
|
"""
|
||||||
|
@ -55,13 +57,26 @@ class OptimizerTests(TestCase):
|
||||||
"""
|
"""
|
||||||
CreateModel should absorb RenameModels.
|
CreateModel should absorb RenameModels.
|
||||||
"""
|
"""
|
||||||
|
managers = [('objects', EmptyManager())]
|
||||||
self.assertOptimizesTo(
|
self.assertOptimizesTo(
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
|
migrations.CreateModel(
|
||||||
|
name="Foo",
|
||||||
|
fields=[("name", models.CharField(max_length=255))],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
),
|
||||||
migrations.RenameModel("Foo", "Bar"),
|
migrations.RenameModel("Foo", "Bar"),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Bar", [("name", models.CharField(max_length=255))]),
|
migrations.CreateModel(
|
||||||
|
"Bar",
|
||||||
|
[("name", models.CharField(max_length=255))],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -159,16 +174,29 @@ class OptimizerTests(TestCase):
|
||||||
"""
|
"""
|
||||||
AddField should optimize into CreateModel.
|
AddField should optimize into CreateModel.
|
||||||
"""
|
"""
|
||||||
|
managers = [('objects', EmptyManager())]
|
||||||
self.assertOptimizesTo(
|
self.assertOptimizesTo(
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
|
migrations.CreateModel(
|
||||||
|
name="Foo",
|
||||||
|
fields=[("name", models.CharField(max_length=255))],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
),
|
||||||
migrations.AddField("Foo", "age", models.IntegerField()),
|
migrations.AddField("Foo", "age", models.IntegerField()),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Foo", [
|
migrations.CreateModel(
|
||||||
("name", models.CharField(max_length=255)),
|
name="Foo",
|
||||||
("age", models.IntegerField()),
|
fields=[
|
||||||
]),
|
("name", models.CharField(max_length=255)),
|
||||||
|
("age", models.IntegerField()),
|
||||||
|
],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -214,15 +242,28 @@ class OptimizerTests(TestCase):
|
||||||
"""
|
"""
|
||||||
AlterField should optimize into CreateModel.
|
AlterField should optimize into CreateModel.
|
||||||
"""
|
"""
|
||||||
|
managers = [('objects', EmptyManager())]
|
||||||
self.assertOptimizesTo(
|
self.assertOptimizesTo(
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
|
migrations.CreateModel(
|
||||||
|
name="Foo",
|
||||||
|
fields=[("name", models.CharField(max_length=255))],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
),
|
||||||
migrations.AlterField("Foo", "name", models.IntegerField()),
|
migrations.AlterField("Foo", "name", models.IntegerField()),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Foo", [
|
migrations.CreateModel(
|
||||||
("name", models.IntegerField()),
|
name="Foo",
|
||||||
]),
|
fields=[
|
||||||
|
("name", models.IntegerField()),
|
||||||
|
],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -230,15 +271,28 @@ class OptimizerTests(TestCase):
|
||||||
"""
|
"""
|
||||||
RenameField should optimize into CreateModel.
|
RenameField should optimize into CreateModel.
|
||||||
"""
|
"""
|
||||||
|
managers = [('objects', EmptyManager())]
|
||||||
self.assertOptimizesTo(
|
self.assertOptimizesTo(
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
|
migrations.CreateModel(
|
||||||
|
name="Foo",
|
||||||
|
fields=[("name", models.CharField(max_length=255))],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
),
|
||||||
migrations.RenameField("Foo", "name", "title"),
|
migrations.RenameField("Foo", "name", "title"),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Foo", [
|
migrations.CreateModel(
|
||||||
("title", models.CharField(max_length=255)),
|
name="Foo",
|
||||||
]),
|
fields=[
|
||||||
|
("title", models.CharField(max_length=255)),
|
||||||
|
],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -277,18 +331,31 @@ class OptimizerTests(TestCase):
|
||||||
"""
|
"""
|
||||||
RemoveField should optimize into CreateModel.
|
RemoveField should optimize into CreateModel.
|
||||||
"""
|
"""
|
||||||
|
managers = [('objects', EmptyManager())]
|
||||||
self.assertOptimizesTo(
|
self.assertOptimizesTo(
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Foo", [
|
migrations.CreateModel(
|
||||||
("name", models.CharField(max_length=255)),
|
name="Foo",
|
||||||
("age", models.IntegerField()),
|
fields=[
|
||||||
]),
|
("name", models.CharField(max_length=255)),
|
||||||
|
("age", models.IntegerField()),
|
||||||
|
],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
),
|
||||||
migrations.RemoveField("Foo", "age"),
|
migrations.RemoveField("Foo", "age"),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
migrations.CreateModel("Foo", [
|
migrations.CreateModel(
|
||||||
("name", models.CharField(max_length=255)),
|
name="Foo",
|
||||||
]),
|
fields=[
|
||||||
|
("name", models.CharField(max_length=255)),
|
||||||
|
],
|
||||||
|
options={'verbose_name': 'Foo'},
|
||||||
|
bases=(CustomModelBase),
|
||||||
|
managers=managers,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue