mirror of https://github.com/django/django.git
Fix my slightly hasty autodetector changes
This commit is contained in:
parent
80bbe2265d
commit
bad9456b9c
|
@ -31,7 +31,7 @@ class MigrationAutodetector(object):
|
||||||
to try and restrict to (restriction is not guaranteed)
|
to try and restrict to (restriction is not guaranteed)
|
||||||
"""
|
"""
|
||||||
changes = self._detect_changes()
|
changes = self._detect_changes()
|
||||||
changes = self._arrange_for_graph(changes, graph)
|
changes = self.arrange_for_graph(changes, graph)
|
||||||
if trim_to_apps:
|
if trim_to_apps:
|
||||||
changes = self._trim_to_apps(changes, trim_to_apps)
|
changes = self._trim_to_apps(changes, trim_to_apps)
|
||||||
return changes
|
return changes
|
||||||
|
@ -299,7 +299,7 @@ class MigrationAutodetector(object):
|
||||||
dependency = ("__setting__", setting_name)
|
dependency = ("__setting__", setting_name)
|
||||||
self.migrations[app_label][-1].dependencies.append(dependency)
|
self.migrations[app_label][-1].dependencies.append(dependency)
|
||||||
|
|
||||||
def _arrange_for_graph(self, changes, graph):
|
def arrange_for_graph(self, changes, graph):
|
||||||
"""
|
"""
|
||||||
Takes in a result from changes() and a MigrationGraph,
|
Takes in a result from changes() and a MigrationGraph,
|
||||||
and fixes the names and dependencies of the changes so they
|
and fixes the names and dependencies of the changes so they
|
||||||
|
@ -388,7 +388,8 @@ class MigrationAutodetector(object):
|
||||||
return "%s_%s" % (ops[0].model_name.lower(), ops[0].name.lower())
|
return "%s_%s" % (ops[0].model_name.lower(), ops[0].name.lower())
|
||||||
elif isinstance(ops[0], operations.RemoveField):
|
elif isinstance(ops[0], operations.RemoveField):
|
||||||
return "remove_%s_%s" % (ops[0].model_name.lower(), ops[0].name.lower())
|
return "remove_%s_%s" % (ops[0].model_name.lower(), ops[0].name.lower())
|
||||||
elif all(isinstance(o, operations.CreateModel) for o in ops):
|
elif len(ops) > 1:
|
||||||
|
if all(isinstance(o, operations.CreateModel) for o in ops):
|
||||||
return "_".join(sorted(o.name.lower() for o in ops))
|
return "_".join(sorted(o.name.lower() for o in ops))
|
||||||
return "auto_%s" % datetime.datetime.now().strftime("%Y%m%d_%H%M")
|
return "auto_%s" % datetime.datetime.now().strftime("%Y%m%d_%H%M")
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ class AutodetectorTests(TestCase):
|
||||||
autodetector = MigrationAutodetector(before, after)
|
autodetector = MigrationAutodetector(before, after)
|
||||||
changes = autodetector._detect_changes()
|
changes = autodetector._detect_changes()
|
||||||
# Run through arrange_for_graph
|
# Run through arrange_for_graph
|
||||||
changes = autodetector._arrange_for_graph(changes, graph)
|
changes = autodetector.arrange_for_graph(changes, graph)
|
||||||
# Make sure there's a new name, deps match, etc.
|
# Make sure there's a new name, deps match, etc.
|
||||||
self.assertEqual(changes["testapp"][0].name, "0003_author")
|
self.assertEqual(changes["testapp"][0].name, "0003_author")
|
||||||
self.assertEqual(changes["testapp"][0].dependencies, [("testapp", "0002_foobar")])
|
self.assertEqual(changes["testapp"][0].dependencies, [("testapp", "0002_foobar")])
|
||||||
|
@ -70,7 +70,7 @@ class AutodetectorTests(TestCase):
|
||||||
changes = autodetector._detect_changes()
|
changes = autodetector._detect_changes()
|
||||||
# Run through arrange_for_graph
|
# Run through arrange_for_graph
|
||||||
graph = MigrationGraph()
|
graph = MigrationGraph()
|
||||||
changes = autodetector._arrange_for_graph(changes, graph)
|
changes = autodetector.arrange_for_graph(changes, graph)
|
||||||
changes["testapp"][0].dependencies.append(("otherapp", "0001_initial"))
|
changes["testapp"][0].dependencies.append(("otherapp", "0001_initial"))
|
||||||
changes = autodetector._trim_to_apps(changes, set(["testapp"]))
|
changes = autodetector._trim_to_apps(changes, set(["testapp"]))
|
||||||
# Make sure there's the right set of migrations
|
# Make sure there's the right set of migrations
|
||||||
|
|
Loading…
Reference in New Issue