diff -rNu django-1.7/django/core/management/commands/makemigrations.py django-1.7-makemigrations-patch/django/core/management/commands/makemigrations.py
old
|
new
|
|
25 | 25 | help="Create an empty migration."), |
26 | 26 | make_option('--noinput', action='store_false', dest='interactive', default=True, |
27 | 27 | help='Tells Django to NOT prompt the user for input of any kind.'), |
| 28 | make_option('--name', '-n', action='store', dest='name', default=None, |
| 29 | help="Use this name for migration file(s)."), |
28 | 30 | ) |
29 | 31 | |
30 | 32 | help = "Creates new migration(s) for apps." |
… |
… |
|
38 | 40 | self.dry_run = options.get('dry_run', False) |
39 | 41 | self.merge = options.get('merge', False) |
40 | 42 | self.empty = options.get('empty', False) |
| 43 | self.migration_name = options.get('name') |
41 | 44 | |
42 | 45 | # Make sure the app they asked for exists |
43 | 46 | app_labels = set(app_labels) |
… |
… |
|
100 | 103 | (app, [Migration("custom", app)]) |
101 | 104 | for app in app_labels |
102 | 105 | ) |
103 | | changes = autodetector.arrange_for_graph(changes, loader.graph) |
| 106 | # here is where the --empty migrations are processed |
| 107 | changes = autodetector.arrange_for_graph( |
| 108 | changes=changes, |
| 109 | graph=loader.graph, |
| 110 | migration_name=self.migration_name, |
| 111 | ) |
104 | 112 | self.write_migration_files(changes) |
105 | 113 | return |
106 | 114 | |
… |
… |
|
109 | 117 | graph=loader.graph, |
110 | 118 | trim_to_apps=app_labels or None, |
111 | 119 | convert_apps=app_labels or None, |
| 120 | migration_name=self.migration_name, |
112 | 121 | ) |
113 | 122 | |
114 | 123 | # No changes? Tell them. |
diff -rNu django-1.7/django/db/migrations/autodetector.py django-1.7-makemigrations-patch/django/db/migrations/autodetector.py
old
|
new
|
|
31 | 31 | self.to_state = to_state |
32 | 32 | self.questioner = questioner or MigrationQuestioner() |
33 | 33 | |
34 | | def changes(self, graph, trim_to_apps=None, convert_apps=None): |
| 34 | def changes(self, graph, trim_to_apps=None, convert_apps=None, migration_name=None): |
35 | 35 | """ |
36 | 36 | Main entry point to produce a list of appliable changes. |
37 | 37 | Takes a graph to base names on and an optional set of apps |
38 | 38 | to try and restrict to (restriction is not guaranteed) |
39 | 39 | """ |
40 | 40 | changes = self._detect_changes(convert_apps, graph) |
41 | | changes = self.arrange_for_graph(changes, graph) |
| 41 | changes = self.arrange_for_graph(changes, graph, migration_name) |
42 | 42 | if trim_to_apps: |
43 | 43 | changes = self._trim_to_apps(changes, trim_to_apps) |
44 | 44 | return changes |
… |
… |
|
937 | 937 | dependencies=dependencies, |
938 | 938 | ) |
939 | 939 | |
940 | | def arrange_for_graph(self, changes, graph): |
| 940 | def arrange_for_graph(self, changes, graph, migration_name=None): |
941 | 941 | """ |
942 | 942 | Takes in a result from changes() and a MigrationGraph, |
943 | 943 | and fixes the names and dependencies of the changes so they |
… |
… |
|
971 | 971 | if i == 0 and app_leaf: |
972 | 972 | migration.dependencies.append(app_leaf) |
973 | 973 | if i == 0 and not app_leaf: |
974 | | new_name = "0001_initial" |
| 974 | if migration_name is None: |
| 975 | new_name = "0001_initial" |
| 976 | else: |
| 977 | new_name = "0001_%s" % migration_name |
975 | 978 | else: |
| 979 | if migration_name is None: |
| 980 | migration_name = self.suggest_name(migration.operations)[:100] |
976 | 981 | new_name = "%04i_%s" % ( |
977 | 982 | next_number, |
978 | | self.suggest_name(migration.operations)[:100], |
| 983 | migration_name, |
979 | 984 | ) |
980 | 985 | name_map[(app_label, migration.name)] = (app_label, new_name) |
981 | 986 | next_number += 1 |