Document, add to changelog the data migrations and rename to 'warnings-as-errors' (plural)

This commit is contained in:
David Wobrock committed 2020-02-07 23:29:15 +01:00
1 parent 71614bd377
commit e49f6dea9c
6 files changed
+21 -7

No files matched your search

+6
View File
@@ -1,3 +1,9 @@
## 2.0.0
* Add linting on data migrations that will raise warnings
* Add `--quiet warning` option to suppress warning messages
* Add `--warnings-as-errors` option to handle warnings as errors
## 1.5.0 ## 1.5.0
* Rework documentation. * Rework documentation.
@@ -110,7 +110,7 @@ class Command(BaseCommand):
help="don't print linting messages to stdout", help="don't print linting messages to stdout",
) )
parser.add_argument( parser.add_argument(
"--warning-as-error", action="store_true", help="handle warnings as errors", "--warnings-as-errors", action="store_true", help="handle warnings as errors",
) )
def handle(self, *args, **options): def handle(self, *args, **options):
@@ -139,7 +139,7 @@ class Command(BaseCommand):
only_unapplied_migrations=options["unapplied_migrations"], only_unapplied_migrations=options["unapplied_migrations"],
exclude_migration_tests=options["exclude_migration_tests"], exclude_migration_tests=options["exclude_migration_tests"],
quiet=options["quiet"], quiet=options["quiet"],
warning_as_error=options["warning_as_error"], warnings_as_errors=options["warnings_as_errors"],
) )
linter.lint_all_migrations( linter.lint_all_migrations(
git_commit_id=options["commit_id"], git_commit_id=options["commit_id"],
+3 -3
View File
@@ -52,7 +52,7 @@ class MigrationLinter(object):
only_unapplied_migrations=False, only_unapplied_migrations=False,
exclude_migration_tests=None, exclude_migration_tests=None,
quiet=None, quiet=None,
warning_as_error=False, warnings_as_errors=False,
): ):
# Store parameters and options # Store parameters and options
self.django_path = path self.django_path = path
@@ -67,7 +67,7 @@ class MigrationLinter(object):
self.only_applied_migrations = only_applied_migrations self.only_applied_migrations = only_applied_migrations
self.only_unapplied_migrations = only_unapplied_migrations self.only_unapplied_migrations = only_unapplied_migrations
self.quiet = quiet or [] self.quiet = quiet or []
self.warning_as_error = warning_as_error self.warnings_as_errors = warnings_as_errors
# Initialise counters # Initialise counters
self.nb_valid = 0 self.nb_valid = 0
@@ -142,7 +142,7 @@ class MigrationLinter(object):
if ignored_data: if ignored_data:
ignored += ignored_data ignored += ignored_data
if self.warning_as_error: if self.warnings_as_errors:
errors += warnings errors += warnings
warnings = [] warnings = []
+7
View File
@@ -12,3 +12,10 @@ The linter analyses your migrations and checks the SQL for:
Those are the most important and frequent backward incompatible migrations. Those are the most important and frequent backward incompatible migrations.
We are happy to add more if you can specify them to us. We are happy to add more if you can specify them to us.
## Warnings
On data migrations, the linter will show a warning when:
* you are missing a reverse migration
* the RunPython arguments do not respect the naming convention `apps, schema_editor`
+1
View File
@@ -25,6 +25,7 @@ Detailed command line options:
|`--project-root-path DJANGO_PROJECT_FOLDER` | An absolute or relative path to the django project. | |`--project-root-path DJANGO_PROJECT_FOLDER` | An absolute or relative path to the django project. |
|`--include-migrations-from FILE_PATH` | If specified, only migrations listed in the given file will be considered. | |`--include-migrations-from FILE_PATH` | If specified, only migrations listed in the given file will be considered. |
|`--quiet or -q {ok,ignore,warning,error}` | Suppress certain output messages, instead of writing them to stdout. | |`--quiet or -q {ok,ignore,warning,error}` | Suppress certain output messages, instead of writing them to stdout. |
|`--warnings-as-errors` | Handle warnings as errors and therefore return an error status code if we should. |
## Ignoring migration tests ## Ignoring migration tests
+2 -2
View File
@@ -49,11 +49,11 @@ class DataMigrationDetectionTestCase(unittest.TestCase):
self.assertEqual(1, self.linter.nb_valid) self.assertEqual(1, self.linter.nb_valid)
self.assertFalse(self.linter.has_errors) self.assertFalse(self.linter.has_errors)
def test_warning_as_error(self): def test_warnings_as_errors(self):
self.linter = MigrationLinter( self.linter = MigrationLinter(
self.test_project_path, self.test_project_path,
include_apps=fixtures.DATA_MIGRATIONS, include_apps=fixtures.DATA_MIGRATIONS,
warning_as_error=True, warnings_as_errors=True,
) )
reverse_migration = self.linter.migration_loader.disk_migrations[ reverse_migration = self.linter.migration_loader.disk_migrations[