Loading AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -649,6 +649,7 @@ answer newbie questions, and generally made Django that much better: Thomas Stromberg <tstromberg@google.com> tibimicu@gmx.net Tim Graham <timograham@gmail.com> Tim Heap <tim@timheap.me> Tim Saylor <tim.saylor@gmail.com> Tobias McNulty <http://www.caktusgroup.com/blog> tobias@neuyork.de Loading django/core/management/commands/makemigrations.py +16 −8 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ class Command(BaseCommand): help='Tells Django to NOT prompt the user for input of any kind.') parser.add_argument('-n', '--name', action='store', dest='name', default=None, help="Use this name for migration file(s).") parser.add_argument('-e', '--exit', action='store_true', dest='exit_code', default=False, help='Exit with error code 1 if no changes needing migrations are found.') def handle(self, *app_labels, **options): Loading @@ -39,6 +41,7 @@ class Command(BaseCommand): self.merge = options.get('merge', False) self.empty = options.get('empty', False) self.migration_name = options.get('name', None) self.exit_code = options.get('exit_code', False) # Make sure the app they asked for exists app_labels = set(app_labels) Loading Loading @@ -120,14 +123,19 @@ class Command(BaseCommand): migration_name=self.migration_name, ) if not changes: # No changes? Tell them. if not changes and self.verbosity >= 1: if self.verbosity >= 1: if len(app_labels) == 1: self.stdout.write("No changes detected in app '%s'" % app_labels.pop()) elif len(app_labels) > 1: self.stdout.write("No changes detected in apps '%s'" % ("', '".join(app_labels))) else: self.stdout.write("No changes detected") if self.exit_code: sys.exit(1) else: return self.write_migration_files(changes) Loading docs/ref/django-admin.txt +8 −0 Original line number Diff line number Diff line Loading @@ -719,6 +719,14 @@ a merge. The ``--name`` option allows you to give the migration(s) a custom name instead of a generated one. .. django-admin-option:: --exit, -e .. versionadded:: 1.8 The ``--exit`` option will cause ``makemigrations`` to exit with error code 1 when no migration are created (or would have been created, if combined with ``--dry-run``). migrate [<app_label> [<migrationname>]] --------------------------------------- Loading docs/releases/1.8.txt +3 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,9 @@ Management Commands :setting:`FIXTURE_DIRS` contains duplicates or a default fixture directory path (``app_name/fixtures``), an exception is raised. * :djadmin:`makemigrations` now supports an :djadminopt:`--exit` option to exit with an error code if no migrations are created. Middleware ^^^^^^^^^^ Loading tests/migrations/test_commands.py +12 −0 Original line number Diff line number Diff line Loading @@ -543,6 +543,18 @@ class MakeMigrationsTests(MigrationTestBase): self.assertIn("dependencies=[\n('migrations','0001_%s'),\n]" % migration_name_0001, content) self.assertIn("operations=[\n]", content) def test_makemigrations_exit(self): """ makemigrations --exit should exit with sys.exit(1) when there are no changes to an app. """ with self.settings(MIGRATION_MODULES={"migrations": self.migration_pkg}): call_command("makemigrations", "--exit", "migrations", verbosity=0) with self.settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_changes"}): with self.assertRaises(SystemExit): call_command("makemigrations", "--exit", "migrations", verbosity=0) class SquashMigrationsTest(MigrationTestBase): """ Loading Loading
AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -649,6 +649,7 @@ answer newbie questions, and generally made Django that much better: Thomas Stromberg <tstromberg@google.com> tibimicu@gmx.net Tim Graham <timograham@gmail.com> Tim Heap <tim@timheap.me> Tim Saylor <tim.saylor@gmail.com> Tobias McNulty <http://www.caktusgroup.com/blog> tobias@neuyork.de Loading
django/core/management/commands/makemigrations.py +16 −8 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ class Command(BaseCommand): help='Tells Django to NOT prompt the user for input of any kind.') parser.add_argument('-n', '--name', action='store', dest='name', default=None, help="Use this name for migration file(s).") parser.add_argument('-e', '--exit', action='store_true', dest='exit_code', default=False, help='Exit with error code 1 if no changes needing migrations are found.') def handle(self, *app_labels, **options): Loading @@ -39,6 +41,7 @@ class Command(BaseCommand): self.merge = options.get('merge', False) self.empty = options.get('empty', False) self.migration_name = options.get('name', None) self.exit_code = options.get('exit_code', False) # Make sure the app they asked for exists app_labels = set(app_labels) Loading Loading @@ -120,14 +123,19 @@ class Command(BaseCommand): migration_name=self.migration_name, ) if not changes: # No changes? Tell them. if not changes and self.verbosity >= 1: if self.verbosity >= 1: if len(app_labels) == 1: self.stdout.write("No changes detected in app '%s'" % app_labels.pop()) elif len(app_labels) > 1: self.stdout.write("No changes detected in apps '%s'" % ("', '".join(app_labels))) else: self.stdout.write("No changes detected") if self.exit_code: sys.exit(1) else: return self.write_migration_files(changes) Loading
docs/ref/django-admin.txt +8 −0 Original line number Diff line number Diff line Loading @@ -719,6 +719,14 @@ a merge. The ``--name`` option allows you to give the migration(s) a custom name instead of a generated one. .. django-admin-option:: --exit, -e .. versionadded:: 1.8 The ``--exit`` option will cause ``makemigrations`` to exit with error code 1 when no migration are created (or would have been created, if combined with ``--dry-run``). migrate [<app_label> [<migrationname>]] --------------------------------------- Loading
docs/releases/1.8.txt +3 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,9 @@ Management Commands :setting:`FIXTURE_DIRS` contains duplicates or a default fixture directory path (``app_name/fixtures``), an exception is raised. * :djadmin:`makemigrations` now supports an :djadminopt:`--exit` option to exit with an error code if no migrations are created. Middleware ^^^^^^^^^^ Loading
tests/migrations/test_commands.py +12 −0 Original line number Diff line number Diff line Loading @@ -543,6 +543,18 @@ class MakeMigrationsTests(MigrationTestBase): self.assertIn("dependencies=[\n('migrations','0001_%s'),\n]" % migration_name_0001, content) self.assertIn("operations=[\n]", content) def test_makemigrations_exit(self): """ makemigrations --exit should exit with sys.exit(1) when there are no changes to an app. """ with self.settings(MIGRATION_MODULES={"migrations": self.migration_pkg}): call_command("makemigrations", "--exit", "migrations", verbosity=0) with self.settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_changes"}): with self.assertRaises(SystemExit): call_command("makemigrations", "--exit", "migrations", verbosity=0) class SquashMigrationsTest(MigrationTestBase): """ Loading