Rename data migration lint checks

This commit is contained in:
David-Wobrock committed 2020-11-30 21:40:57 +01:00
1 parent 1824410ac5
commit 4b15e11faa
4 files changed
+32 -22

No files matched your search

+11 -1
View File
@@ -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
+5 -5
View File
@@ -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:
+14 -14
View File
@@ -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)
+2 -2
View File
@@ -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;")