From 4b15e11faaa691fb1866097a1876f84ae8381cd2 Mon Sep 17 00:00:00 2001 From: David-Wobrock Date: Mon, 30 Nov 2020 21:39:03 +0100 Subject: [PATCH] Rename data migration lint checks --- CHANGELOG.md | 12 ++++++++- django_migration_linter/migration_linter.py | 10 ++++---- docs/incompatibilities.md | 28 ++++++++++----------- tests/functional/test_data_migrations.py | 4 +-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 629983a..268d540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,21 @@ ## 2.5.0 +**Renamed lint checks**: +* `REVERSIBLE_DATA_MIGRATION` -> `RUNPYTHON_REVERSIBLE` +* `NAMING_CONVENTION_RUNPYTHON_ARGS` -> `RUNPYTHON_ARGS_NAMING_CONVENTION` +* `DATA_MIGRATION_MODEL_IMPORT` -> `RUNPYTHON_MODEL_IMPORT` +* `DATA_MIGRATION_MODEL_VARIABLE_NAME` -> `RUNPYTHON_MODEL_VARIABLE_NAME` +* `REVERSIBLE_RUNSQL_DATA_MIGRATION` -> `RUNSQL_REVERSIBLE` + +Features/fixes: * Add Python 3.9 support * Make data migration model import error less strict (issue #121) * Add warning detection on RunPython call when model variable name is not the same as model class name * Run checks on RunSQL migration operations +* Rename the RunPython data migration lint checks for improved consistency -Switched from Travis CI to GitHub Actions for tests +Others: +* Switched from Travis CI to GitHub Actions for tests ## 2.4.1 diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index 9a3d006..435441a 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -415,7 +415,7 @@ class MigrationLinter(object): # Detect warning on missing reverse operation if not runpython.reversible: issue = { - "code": "REVERSIBLE_DATA_MIGRATION", + "code": "RUNPYTHON_REVERSIBLE", "msg": "'{}': RunPython data migration is not reversible".format( function_name ), @@ -433,7 +433,7 @@ class MigrationLinter(object): ) if tuple(args_spec.args) != EXPECTED_DATA_MIGRATION_ARGS: issue = { - "code": "NAMING_CONVENTION_RUNPYTHON_ARGS", + "code": "RUNPYTHON_ARGS_NAMING_CONVENTION", "msg": ( "'{}': By convention, " "RunPython names the two arguments: apps, schema_editor" @@ -502,7 +502,7 @@ class MigrationLinter(object): if not has_get_model_call: issues.append( { - "code": "DATA_MIGRATION_MODEL_IMPORT", + "code": "RUNPYTHON_MODEL_IMPORT", "msg": ( "'{}': Could not find an 'apps.get_model(\"...\", \"{}\")' " "call. Importing the model directly is incorrect for " @@ -543,7 +543,7 @@ class MigrationLinter(object): if not has_same_model_name: issues.append( { - "code": "DATA_MIGRATION_MODEL_VARIABLE_NAME", + "code": "RUNPYTHON_MODEL_VARIABLE_NAME", "msg": ( "'{}': Model variable name {} is different from the " "model class name that was found in the " @@ -561,7 +561,7 @@ class MigrationLinter(object): # Detect warning on missing reverse operation if not runsql.reversible: issue = { - "code": "REVERSIBLE_RUNSQL_DATA_MIGRATION", + "code": "RUNSQL_REVERSIBLE", "msg": "RunSQL data migration is not reversible", } if issue["code"] in self.exclude_migration_tests: diff --git a/docs/incompatibilities.md b/docs/incompatibilities.md index 0818d3b..4f7b0ef 100644 --- a/docs/incompatibilities.md +++ b/docs/incompatibilities.md @@ -25,17 +25,17 @@ On data migrations, the linter will show a warning when: You can ignore check through the `--exclude-migration-test` option and specifying any of the codes: -| Code | Description | -|-------------------------------------|----------------------------------------------------------------------| -|`NOT_NULL` | Not NULL constraint on columns -|`DROP_COLUMN` | Dropping columns -|`DROP_TABLE` | Dropping tables -|`RENAME_COLUMN` | Renaming columns -|`RENAME_TABLE` | Renaming tables -|`ALTER_COLUMN` | Altering columns (could be backward compatible) -|`ADD_UNIQUE` | Add unique constraints -|`REVERSIBLE_DATA_MIGRATION` | RunPython data migration is not reversible (missing reverse code) -|`NAMING_CONVENTION_RUNPYTHON_ARGS` | By convention, RunPython names two arguments: apps, schema_editor -|`DATA_MIGRATION_MODEL_IMPORT` | Missing apps.get_model() calls for model -|`DATA_MIGRATION_MODEL_VARIABLE_NAME` | The model variable name is different from the model class itself -|`REVERSIBLE_RUNSQL_DATA_MIGRATION` | RunSQL data migration is not reversible (missing reverse SQL) +| Code | Description | +|-----------------------------------|----------------------------------------------------------------------| +|`NOT_NULL` | Not NULL constraint on columns +|`DROP_COLUMN` | Dropping columns +|`DROP_TABLE` | Dropping tables +|`RENAME_COLUMN` | Renaming columns +|`RENAME_TABLE` | Renaming tables +|`ALTER_COLUMN` | Altering columns (could be backward compatible) +|`ADD_UNIQUE` | Add unique constraints +|`RUNPYTHON_REVERSIBLE` | RunPython data migration is not reversible (missing reverse code) +|`RUNPYTHON_ARGS_NAMING_CONVENTION` | By convention, RunPython names two arguments: apps, schema_editor +|`RUNPYTHON_MODEL_IMPORT` | Missing apps.get_model() calls for model +|`RUNPYTHON_MODEL_VARIABLE_NAME` | The model variable name is different from the model class itself +|`RUNSQL_REVERSIBLE` | RunSQL data migration is not reversible (missing reverse SQL) diff --git a/tests/functional/test_data_migrations.py b/tests/functional/test_data_migrations.py index d048b3d..11b6aac 100644 --- a/tests/functional/test_data_migrations.py +++ b/tests/functional/test_data_migrations.py @@ -39,7 +39,7 @@ class DataMigrationDetectionTestCase(unittest.TestCase): self.linter = MigrationLinter( self.test_project_path, include_apps=fixtures.DATA_MIGRATIONS, - exclude_migration_tests=("REVERSIBLE_DATA_MIGRATION",), + exclude_migration_tests=("RUNPYTHON_REVERSIBLE",), ) reverse_migration = self.linter.migration_loader.disk_migrations[ @@ -254,7 +254,7 @@ class RunSQLMigrationTestCase(unittest.TestCase): runsql = migrations.RunSQL("sql;") error, ignored, warning = self.linter.lint_runsql(runsql) - self.assertEqual("REVERSIBLE_RUNSQL_DATA_MIGRATION", warning[0]["code"]) + self.assertEqual("RUNSQL_REVERSIBLE", warning[0]["code"]) def test_sql_linting_error(self): runsql = migrations.RunSQL("ALTER TABLE t DROP COLUMN t;")