Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create-max-migration-files for apps without migrations #14

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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