Add exclusive options for linting only applied or unapplied migrations

This commit is contained in:
David Wobrock committed 2019-06-06 22:54:08 +02:00
1 parent b17c872996
commit 3273f1bdc4
2 files changed
+20

No files matched your search

@@ -71,6 +71,20 @@ class Command(BaseCommand):
help="ignore migrations that are in the specified django apps",
)
applied_unapplied_migrations_group = parser.add_mutually_exclusive_group(
required=False
)
applied_unapplied_migrations_group.add_argument(
"--unapplied-migrations",
action="store_true",
help="check only migrations have not been applied to the database yet",
)
applied_unapplied_migrations_group.add_argument(
"--applied-migrations",
action="store_true",
help="check only migrations that have already been applied to the database",
)
def handle(self, *args, **options):
settings_path = os.path.dirname(
import_module(os.getenv("DJANGO_SETTINGS_MODULE")).__file__
@@ -90,6 +104,8 @@ class Command(BaseCommand):
database=options["database"],
cache_path=options["cache_path"],
no_cache=options["no_cache"],
only_applied_migrations=options["applied_migrations"],
only_unapplied_migrations=options["unapplied_migrations"],
)
linter.lint_all_migrations(git_commit_id=options["commit_id"])
linter.print_summary()
@@ -46,6 +46,8 @@ class MigrationLinter(object):
database=DEFAULT_DB_ALIAS,
cache_path=DEFAULT_CACHE_PATH,
no_cache=False,
only_applied_migrations=False,
only_unapplied_migrations=False,
):
# Store parameters and options
self.django_path = path
@@ -56,6 +58,8 @@ class MigrationLinter(object):
self.database = database or DEFAULT_DB_ALIAS
self.cache_path = cache_path or DEFAULT_CACHE_PATH
self.no_cache = no_cache
self.only_applied_migrations = only_applied_migrations
self.only_unapplied_migrations = only_unapplied_migrations
# Initialise counters
self.nb_valid = 0