Document (README & CHANGELOG) and rename option to 'exclude-migration-tests'
This commit is contained in:
1 parent
579e7c68b4
commit
af4b11c563
5 files changed
+48
-36
No files matched your search
@@ -50,11 +50,6 @@ class Command(BaseCommand):
|
||||
"--project-root-path", type=str, nargs="?", help="django project root path"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--exclude-tests", type=str, nargs="*", help="Specify tests to be ignored"
|
||||
" (e.g. ALTER_COLUMN)"
|
||||
)
|
||||
|
||||
cache_group = parser.add_mutually_exclusive_group(required=False)
|
||||
cache_group.add_argument(
|
||||
"--cache-path",
|
||||
@@ -93,6 +88,13 @@ class Command(BaseCommand):
|
||||
help="check only migrations that have already been applied to the database",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--exclude-migration-tests",
|
||||
type=str,
|
||||
nargs="*",
|
||||
help="Specify backward incompatible migration tests to be ignored (e.g. ALTER_COLUMN)",
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if options["project_root_path"]:
|
||||
settings_path = options["project_root_path"]
|
||||
@@ -112,12 +114,12 @@ class Command(BaseCommand):
|
||||
ignore_name=options["ignore_name"],
|
||||
include_apps=options["include_apps"],
|
||||
exclude_apps=options["exclude_apps"],
|
||||
exclude_tests=options["exclude_tests"],
|
||||
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"],
|
||||
exclude_migration_tests=options["exclude_migration_tests"],
|
||||
)
|
||||
linter.lint_all_migrations(git_commit_id=options["commit_id"])
|
||||
linter.print_summary()
|
||||
|
||||
@@ -42,12 +42,12 @@ class MigrationLinter(object):
|
||||
ignore_name=None,
|
||||
include_apps=None,
|
||||
exclude_apps=None,
|
||||
exclude_tests=None,
|
||||
database=DEFAULT_DB_ALIAS,
|
||||
cache_path=DEFAULT_CACHE_PATH,
|
||||
no_cache=False,
|
||||
only_applied_migrations=False,
|
||||
only_unapplied_migrations=False,
|
||||
exclude_migration_tests=None,
|
||||
):
|
||||
# Store parameters and options
|
||||
self.django_path = path
|
||||
@@ -55,7 +55,7 @@ class MigrationLinter(object):
|
||||
self.ignore_name = ignore_name or tuple()
|
||||
self.include_apps = include_apps
|
||||
self.exclude_apps = exclude_apps
|
||||
self.exclude_tests = exclude_tests
|
||||
self.exclude_migration_tests = exclude_migration_tests
|
||||
self.database = database or DEFAULT_DB_ALIAS
|
||||
self.cache_path = cache_path or DEFAULT_CACHE_PATH
|
||||
self.no_cache = no_cache
|
||||
@@ -120,8 +120,8 @@ class MigrationLinter(object):
|
||||
return
|
||||
|
||||
sql_statements = self.get_sql(app_label, migration_name)
|
||||
exclude_tests = self.exclude_tests or []
|
||||
errors = analyse_sql_statements(sql_statements, exclude_tests)
|
||||
exclude_migration_tests = self.exclude_migration_tests or []
|
||||
errors = analyse_sql_statements(sql_statements, exclude_migration_tests)
|
||||
|
||||
if not errors:
|
||||
print("OK")
|
||||
|
||||
@@ -70,12 +70,18 @@ migration_tests = (
|
||||
)
|
||||
|
||||
|
||||
def analyse_sql_statements(sql_statements, exclude_tests):
|
||||
def get_migration_tests(exclude_migration_tests):
|
||||
for test in migration_tests:
|
||||
if test["code"] in exclude_migration_tests:
|
||||
continue
|
||||
yield test
|
||||
|
||||
|
||||
def analyse_sql_statements(sql_statements, exclude_migration_tests):
|
||||
errors = []
|
||||
for statement in sql_statements:
|
||||
for test in migration_tests:
|
||||
if test["code"] not in exclude_tests and test["fn"](statement,
|
||||
errors=errors):
|
||||
for test in get_migration_tests(exclude_migration_tests):
|
||||
if test["fn"](statement, errors=errors):
|
||||
logger.debug("Testing {0} -- ERROR".format(statement))
|
||||
table_search = re.search("TABLE `([^`]*)`", statement, re.IGNORECASE)
|
||||
col_search = re.search("COLUMN `([^`]*)`", statement, re.IGNORECASE)
|
||||
|
||||
Reference in new issue
Block a user