diff --git a/HISTORY.rst b/HISTORY.rst index 4ed4354..ad07293 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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 + `__. + 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 + `__. + 1.0.0 (2020-12-10) ------------------ diff --git a/src/django_linear_migrations/management/commands/create-max-migration-files.py b/src/django_linear_migrations/management/commands/create-max-migration-files.py index 2ea04ef..3c5f58b 100644 --- a/src/django_linear_migrations/management/commands/create-max-migration-files.py +++ b/src/django_linear_migrations/management/commands/create-max-migration-files.py @@ -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( diff --git a/tests/test_create_max_migration_files.py b/tests/test_create_max_migration_files.py index af09f9b..8f6951b 100644 --- a/tests/test_create_max_migration_files.py +++ b/tests/test_create_max_migration_files.py @@ -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()