Implement include migration name options
This commit is contained in:
1 parent
1eccbbfc07
commit
137089573c
4 files changed
+47
No files matched your search
@@ -47,6 +47,18 @@ class Command(BaseCommand):
|
|||||||
nargs="*",
|
nargs="*",
|
||||||
help="ignore migrations with exactly one of these names",
|
help="ignore migrations with exactly one of these names",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--include-name-contains",
|
||||||
|
type=str,
|
||||||
|
nargs="?",
|
||||||
|
help="only consider migrations containing this name",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--include-name",
|
||||||
|
type=str,
|
||||||
|
nargs="*",
|
||||||
|
help="only consider migrations with exactly one of these names",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--project-root-path", type=str, nargs="?", help="django project root path"
|
"--project-root-path", type=str, nargs="?", help="django project root path"
|
||||||
)
|
)
|
||||||
@@ -126,6 +138,12 @@ class Command(BaseCommand):
|
|||||||
ignore_name = options["ignore_name"] or config_parser.get(
|
ignore_name = options["ignore_name"] or config_parser.get(
|
||||||
CONFIG_NAME, "ignore_name", fallback=None
|
CONFIG_NAME, "ignore_name", fallback=None
|
||||||
)
|
)
|
||||||
|
include_name_contains = options["include_name_contains"] or config_parser.get(
|
||||||
|
CONFIG_NAME, "include_name_contains", fallback=None
|
||||||
|
)
|
||||||
|
include_name = options["include_name"] or config_parser.get(
|
||||||
|
CONFIG_NAME, "include_name", fallback=None
|
||||||
|
)
|
||||||
include_apps = options["include_apps"] or config_parser.get(
|
include_apps = options["include_apps"] or config_parser.get(
|
||||||
CONFIG_NAME, "include_apps", fallback=None
|
CONFIG_NAME, "include_apps", fallback=None
|
||||||
)
|
)
|
||||||
@@ -163,6 +181,8 @@ class Command(BaseCommand):
|
|||||||
settings_path,
|
settings_path,
|
||||||
ignore_name_contains=ignore_name_contains,
|
ignore_name_contains=ignore_name_contains,
|
||||||
ignore_name=ignore_name,
|
ignore_name=ignore_name,
|
||||||
|
include_name_contains=include_name_contains,
|
||||||
|
include_name=include_name,
|
||||||
include_apps=include_apps,
|
include_apps=include_apps,
|
||||||
exclude_apps=exclude_apps,
|
exclude_apps=exclude_apps,
|
||||||
database=database,
|
database=database,
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ class MigrationLinter(object):
|
|||||||
path=None,
|
path=None,
|
||||||
ignore_name_contains=None,
|
ignore_name_contains=None,
|
||||||
ignore_name=None,
|
ignore_name=None,
|
||||||
|
include_name_contains=None,
|
||||||
|
include_name=None,
|
||||||
include_apps=None,
|
include_apps=None,
|
||||||
exclude_apps=None,
|
exclude_apps=None,
|
||||||
database=DEFAULT_DB_ALIAS,
|
database=DEFAULT_DB_ALIAS,
|
||||||
@@ -60,6 +62,8 @@ class MigrationLinter(object):
|
|||||||
self.django_path = path
|
self.django_path = path
|
||||||
self.ignore_name_contains = ignore_name_contains
|
self.ignore_name_contains = ignore_name_contains
|
||||||
self.ignore_name = ignore_name or tuple()
|
self.ignore_name = ignore_name or tuple()
|
||||||
|
self.include_name_contains = include_name_contains
|
||||||
|
self.include_name = include_name or tuple()
|
||||||
self.include_apps = include_apps
|
self.include_apps = include_apps
|
||||||
self.exclude_apps = exclude_apps
|
self.exclude_apps = exclude_apps
|
||||||
self.exclude_migration_tests = exclude_migration_tests or []
|
self.exclude_migration_tests = exclude_migration_tests or []
|
||||||
@@ -371,7 +375,12 @@ class MigrationLinter(object):
|
|||||||
self.ignore_name_contains
|
self.ignore_name_contains
|
||||||
and self.ignore_name_contains in migration_name
|
and self.ignore_name_contains in migration_name
|
||||||
)
|
)
|
||||||
|
or (
|
||||||
|
self.include_name_contains
|
||||||
|
and self.include_name_contains not in migration_name
|
||||||
|
)
|
||||||
or (migration_name in self.ignore_name)
|
or (migration_name in self.ignore_name)
|
||||||
|
or (self.include_name and migration_name not in self.include_name)
|
||||||
or (
|
or (
|
||||||
self.only_applied_migrations
|
self.only_applied_migrations
|
||||||
and (app_label, migration_name)
|
and (app_label, migration_name)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ Below the detailed command line options, which can all also be defined using a c
|
|||||||
|`GIT_COMMIT_ID` | If specified, only migrations since this commit will be taken into account. If not specified, all migrations will be linted.|
|
|`GIT_COMMIT_ID` | If specified, only migrations since this commit will be taken into account. If not specified, all migrations will be linted.|
|
||||||
|`--ignore-name-contains IGNORE_NAME_CONTAINS` | Ignore migrations containing this name. |
|
|`--ignore-name-contains IGNORE_NAME_CONTAINS` | Ignore migrations containing this name. |
|
||||||
|`--ignore-name IGNORE_NAME [IGNORE_NAME ...]` | Ignore migrations with exactly one of these names. |
|
|`--ignore-name IGNORE_NAME [IGNORE_NAME ...]` | Ignore migrations with exactly one of these names. |
|
||||||
|
|`--include-name-contains INCLUDE_NAME_CONTAINS` | Include migrations containing this name. |
|
||||||
|
|`--include-name INCLUDE_NAME [INCLUDE_NAME ...]` | Include migrations with exactly one of these names. |
|
||||||
|`--include-apps INCLUDE_APPS [INCLUDE_APPS ...]` | Check only migrations that are in the specified django apps. |
|
|`--include-apps INCLUDE_APPS [INCLUDE_APPS ...]` | Check only migrations that are in the specified django apps. |
|
||||||
|`--exclude-apps EXCLUDE_APPS [EXCLUDE_APPS ...]` | Ignore migrations that are in the specified django apps. |
|
|`--exclude-apps EXCLUDE_APPS [EXCLUDE_APPS ...]` | Ignore migrations that are in the specified django apps. |
|
||||||
|`--exclude-migration-tests MIGRATION_TEST_CODE [...]` | Specify backward incompatible migration tests to be ignored using the code (e.g. ALTER_COLUMN). |
|
|`--exclude-migration-tests MIGRATION_TEST_CODE [...]` | Specify backward incompatible migration tests to be ignored using the code (e.g. ALTER_COLUMN). |
|
||||||
|
|||||||
@@ -56,6 +56,22 @@ class LinterFunctionsTestCase(unittest.TestCase):
|
|||||||
self.assertFalse(linter.should_ignore_migration("app_correct", "0001_initial"))
|
self.assertFalse(linter.should_ignore_migration("app_correct", "0001_initial"))
|
||||||
self.assertTrue(linter.should_ignore_migration("app_correct", "0002_foo"))
|
self.assertTrue(linter.should_ignore_migration("app_correct", "0002_foo"))
|
||||||
|
|
||||||
|
def test_include_migration_name_contains(self):
|
||||||
|
linter = MigrationLinter(include_name_contains="foo")
|
||||||
|
self.assertTrue(linter.should_ignore_migration("app_correct", "0001_initial"))
|
||||||
|
self.assertFalse(linter.should_ignore_migration("app_correct", "0002_foo"))
|
||||||
|
|
||||||
|
def test_include_migration_full_name(self):
|
||||||
|
linter = MigrationLinter(include_name=("0002_foo",))
|
||||||
|
self.assertTrue(linter.should_ignore_migration("app_correct", "0001_initial"))
|
||||||
|
self.assertFalse(linter.should_ignore_migration("app_correct", "0002_foo"))
|
||||||
|
|
||||||
|
def test_include_migration_multiple_names(self):
|
||||||
|
linter = MigrationLinter(include_name=("0002_foo", "0003_bar"))
|
||||||
|
self.assertTrue(linter.should_ignore_migration("app_correct", "0001_initial"))
|
||||||
|
self.assertFalse(linter.should_ignore_migration("app_correct", "0002_foo"))
|
||||||
|
self.assertFalse(linter.should_ignore_migration("app_correct", "0003_bar"))
|
||||||
|
|
||||||
def test_gather_all_migrations(self):
|
def test_gather_all_migrations(self):
|
||||||
linter = MigrationLinter()
|
linter = MigrationLinter()
|
||||||
migrations = linter._gather_all_migrations()
|
migrations = linter._gather_all_migrations()
|
||||||
|
|||||||
Reference in new issue
Block a user