mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
Initial version of MigrationOptimizer and tests
This commit is contained in:
@@ -63,3 +63,16 @@ class Operation(object):
|
||||
Outputs a brief summary of what the action does.
|
||||
"""
|
||||
return "%s: %s" % (self.__class__.__name__, self._constructor_args)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s %s%s>" % (
|
||||
self.__class__.__name__,
|
||||
", ".join(map(repr, self._constructor_args[0])),
|
||||
",".join(" %s=%r" % x for x in self._constructor_args[1].items()),
|
||||
)
|
||||
|
||||
def __eq__(self, other):
|
||||
return (self.__class__ == other.__class__) and (self.deconstruct() == other.deconstruct())
|
||||
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
@@ -29,6 +29,14 @@ class AddField(Operation):
|
||||
def describe(self):
|
||||
return "Add field %s to %s" % (self.name, self.model_name)
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
(self.__class__ == other.__class__) and
|
||||
(self.name == other.name) and
|
||||
(self.model_name == other.model_name) and
|
||||
(self.field.deconstruct()[1:] == other.field.deconstruct()[1:])
|
||||
)
|
||||
|
||||
|
||||
class RemoveField(Operation):
|
||||
"""
|
||||
@@ -92,6 +100,14 @@ class AlterField(Operation):
|
||||
def describe(self):
|
||||
return "Alter field %s on %s" % (self.name, self.model_name)
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
(self.__class__ == other.__class__) and
|
||||
(self.name == other.name) and
|
||||
(self.model_name == other.model_name) and
|
||||
(self.field.deconstruct()[1:] == other.field.deconstruct()[1:])
|
||||
)
|
||||
|
||||
|
||||
class RenameField(Operation):
|
||||
"""
|
||||
|
||||
@@ -32,6 +32,15 @@ class CreateModel(Operation):
|
||||
def describe(self):
|
||||
return "Create model %s" % (self.name, )
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
(self.__class__ == other.__class__) and
|
||||
(self.name == other.name) and
|
||||
(self.options == other.options) and
|
||||
(self.bases == other.bases) and
|
||||
([(k, f.deconstruct()[1:]) for k, f in self.fields] == [(k, f.deconstruct()[1:]) for k, f in other.fields])
|
||||
)
|
||||
|
||||
|
||||
class DeleteModel(Operation):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user