Skip to content

Commit

Permalink
Handle apps with migrations disabled via MIGRATION_MODULES (#24)
Browse files Browse the repository at this point in the history
Fixes #23.
  • Loading branch information
adamchainz authored Dec 15, 2020
1 parent 87650c0 commit c5f83fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
History
=======

* Handle apps with whose migrations have been disabled by mapping them to
``None`` in the ``MIGRATION_MODULES`` setting.

Thanks to Helmut for the report in `Issue #23
<https://github.com/adamchainz/django-linear-migrations/issues/23>`__.

1.2.0 (2020-12-14)
------------------

Expand Down
15 changes: 9 additions & 6 deletions src/django_linear_migrations/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ def __init__(self, app_label, do_reload=False):
self.migrations_module_name, _explicit = MigrationLoader.migrations_module(
app_label
)
try:
self.migrations_module = import_module(self.migrations_module_name)
except ModuleNotFoundError:
# Unmigrated app
if self.migrations_module_name is None:
self.migrations_module = None
else:
if do_reload:
reload(self.migrations_module)
try:
self.migrations_module = import_module(self.migrations_module_name)
except ModuleNotFoundError:
# Unmigrated app
self.migrations_module = None
else:
if do_reload:
reload(self.migrations_module)

@property
def has_migrations(self):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_create_max_migration_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ def call_command(self, *args, **kwargs):
returncode = exc.code
return out.getvalue(), err.getvalue(), returncode

def test_success_migrations_disabledi(self):
self.migrations_dir.rmdir()
with override_settings(MIGRATION_MODULES={"testapp": None}):
out, err, returncode = self.call_command()

assert out == "No max_migration.txt files need creating.\n"
assert err == ""
assert returncode == 0

def test_success_no_migrations_dir(self):
self.migrations_dir.rmdir()

Expand Down

0 comments on commit c5f83fb

Please sign in to comment.