Skip to content

Commit

Permalink
Fix create-max-migration-files for apps without migrations
Browse files Browse the repository at this point in the history
Fixes #13.
  • Loading branch information
adamchainz committed Dec 11, 2020
1 parent 89cfaeb commit 70fb54f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
9 changes: 9 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
History
=======

* Fix ``create-max-migration-files`` for apps without migrations folders or
files.

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

1.0.1 (2020-12-11)
------------------

* Move initial ``max_migration.txt`` file creation into a separate management
command, ``create-max-migration-files``.

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

1.0.0 (2020-12-10)
------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def handle(self, *app_labels, **options):
continue

migration_details = MigrationDetails(app_config.label)
if not migration_details.has_migrations:
continue

max_migration_txt = migration_details.dir / "max_migration.txt"
if not max_migration_txt.exists():
if not max_migration_txt.exists() and len(migration_details.names) > 0:
max_migration_name = max(migration_details.names)
max_migration_txt.write_text(max_migration_name + "\n")
self.stdout.write(
Expand Down
25 changes: 25 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,31 @@ def call_command(self, *args, **kwargs):
returncode = exc.code
return out.getvalue(), err.getvalue(), returncode

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

out, err, returncode = self.call_command()

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

def test_success_empty_migrations_dir(self):
out, err, returncode = self.call_command()

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

def test_success_only_init(self):
(self.migrations_dir / "__init__.py").touch()

out, err, returncode = self.call_command()

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

def test_success(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").touch()
Expand Down

0 comments on commit 70fb54f

Please sign in to comment.