From c2ad3e6aeb21141869f2042b773f5ff4bbe51ec5 Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Sun, 13 Mar 2022 17:50:02 +0100 Subject: [PATCH] Allow passing '--sql-analyser' to makemigrations command --- CHANGELOG.md | 7 ++++--- .../management/commands/lintmigrations.py | 7 ------- .../management/commands/makemigrations.py | 2 ++ django_migration_linter/management/utils.py | 9 +++++++++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 502700e..c1b2e43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ -## 4.x.y (unreleased) +## 4.1.0 (unreleased) -- Allow configuring logging for `makemigrations` command and unify behaviour with `lintmigrations` -- Adapt `--warnings-as-errors` option to allow selecting some migration tests only +- Allow configuring logging for `makemigrations` command and unify behaviour with `lintmigrations` (issue #207) +- Adapt `--warnings-as-errors` option to allow selecting some migration tests only (issue #201) +- Add `sql_analyser` option to `makemigrations` in order to specify the SQL analyser to use (issue #208) ## 4.0.0 diff --git a/django_migration_linter/management/commands/lintmigrations.py b/django_migration_linter/management/commands/lintmigrations.py index 237a572..379bf3a 100644 --- a/django_migration_linter/management/commands/lintmigrations.py +++ b/django_migration_linter/management/commands/lintmigrations.py @@ -10,7 +10,6 @@ from django.core.management.base import BaseCommand from ...constants import __version__ from ...migration_linter import MessageType, MigrationLinter -from ...sql_analyser.analyser import ANALYSER_STRING_MAPPING from ..utils import ( configure_logging, extract_warnings_as_errors_option, @@ -130,12 +129,6 @@ class Command(BaseCommand): choices=MessageType.values(), help="don't print linting messages to stdout", ) - parser.add_argument( - "--sql-analyser", - nargs="?", - choices=list(ANALYSER_STRING_MAPPING.keys()), - help="select the SQL analyser", - ) register_linting_configuration_options(parser) def handle(self, *args, **options): diff --git a/django_migration_linter/management/commands/makemigrations.py b/django_migration_linter/management/commands/makemigrations.py index 9aad28e..c6512e5 100644 --- a/django_migration_linter/management/commands/makemigrations.py +++ b/django_migration_linter/management/commands/makemigrations.py @@ -46,6 +46,7 @@ class Command(MakeMigrationsCommand): self.database = options["database"] self.exclude_migrations_tests = options["exclude_migration_tests"] self.warnings_as_errors = options["warnings_as_errors"] + self.sql_analyser = options["sql_analyser"] configure_logging(options["verbosity"]) return super(Command, self).handle(*app_labels, **options) @@ -85,6 +86,7 @@ class Command(MakeMigrationsCommand): exclude_migration_tests=self.exclude_migrations_tests, warnings_as_errors_tests=warnings_as_errors_tests, all_warnings_as_errors=all_warnings_as_errors, + analyser_string=self.sql_analyser, ) for app_label, app_migrations in changes.items(): diff --git a/django_migration_linter/management/utils.py b/django_migration_linter/management/utils.py index 4d781c1..49a0b7d 100644 --- a/django_migration_linter/management/utils.py +++ b/django_migration_linter/management/utils.py @@ -1,5 +1,7 @@ import logging +from ..sql_analyser.analyser import ANALYSER_STRING_MAPPING + def register_linting_configuration_options(parser): parser.add_argument( @@ -27,6 +29,13 @@ def register_linting_configuration_options(parser): "errors (e.g. RUNPYTHON_REVERSIBLE)", ) + parser.add_argument( + "--sql-analyser", + nargs="?", + choices=list(ANALYSER_STRING_MAPPING.keys()), + help="select the SQL analyser", + ) + def configure_logging(verbosity): logger = logging.getLogger("django_migration_linter")