diff --git a/django_migration_linter/sql_analyser/postgresql.py b/django_migration_linter/sql_analyser/postgresql.py index 778ac76..9fbf920 100644 --- a/django_migration_linter/sql_analyser/postgresql.py +++ b/django_migration_linter/sql_analyser/postgresql.py @@ -67,7 +67,7 @@ class PostgresqlAnalyser(BaseAnalyser): fn=has_create_index_in_transaction, message="CREATE INDEX prolongs transaction, delaying lock release", mode=CheckMode.TRANSACTION, - type=CheckType.ERROR, + type=CheckType.WARNING, ), Check( code="DROP_INDEX", diff --git a/docs/incompatibilities.md b/docs/incompatibilities.md index 1867339..ecff7b3 100644 --- a/docs/incompatibilities.md +++ b/docs/incompatibilities.md @@ -40,7 +40,7 @@ You can ignore checks through the `--exclude-migration-tests` option by specifyi | `RUNPYTHON_MODEL_VARIABLE_NAME` | The model variable name is different from the model class itself | Warning | | `RUNSQL_REVERSIBLE` | RunSQL data migration is not reversible (missing reverse SQL) | Warning | | `CREATE_INDEX` | (Postgresql specific) Creating an index without the concurrent keyword will lock the table and may generate downtime | Warning | -| `CREATE_INDEX_EXCLUSIVE` | (Postgresql specific) Creating an index in a transaction (after an `EXCLUSIVE` lock) prolongs the exclusive lock | Error | +| `CREATE_INDEX_EXCLUSIVE` | (Postgresql specific) Creating an index in a transaction (after an `EXCLUSIVE` lock) prolongs the exclusive lock | Warning | | `DROP_INDEX` | (Postgresql specific) Dropping an index without the concurrent keyword will lock the table and may generate downtime | Warning | | `REINDEX` | (Postgresql specific) Reindexing will lock the table and may generate downtime | Warning | diff --git a/tests/functional/test_migration_linter.py b/tests/functional/test_migration_linter.py index 5318ba5..c2b1549 100644 --- a/tests/functional/test_migration_linter.py +++ b/tests/functional/test_migration_linter.py @@ -150,5 +150,6 @@ class PostgresqlBackwardCompatibilityDetectionTestCase( self._test_linter_finds_errors(app) def test_create_index_exclusive(self): - app = fixtures.CREATE_INDEX_EXCLUSIVE - self._test_linter_finds_errors(app) + linter = self._launch_linter(fixtures.CREATE_INDEX_EXCLUSIVE) + self.assertFalse(linter.has_errors) + self.assertTrue(linter.nb_warnings) diff --git a/tests/unit/test_sql_analyser.py b/tests/unit/test_sql_analyser.py index 8f58d6a..0781f51 100644 --- a/tests/unit/test_sql_analyser.py +++ b/tests/unit/test_sql_analyser.py @@ -36,9 +36,16 @@ class SqlAnalyserTestCase(unittest.TestCase): ), ) - def assertWarningSql(self, sql): + def assertWarningSql(self, sql, code=None): _, _, warnings = self.analyse_sql(sql) self.assertNotEqual(0, len(warnings), "Found no warnings in sql") + if code: + self.assertTrue( + any(warning.code == code for warning in warnings), + "Didn't find error code {} in returned errors ({})".format( + code, [warning.code for warning in warnings] + ), + ) class MySqlAnalyserTestCase(SqlAnalyserTestCase): @@ -322,7 +329,7 @@ class PostgresqlAnalyserTestCase(SqlAnalyserTestCase): 'CREATE INDEX "user_email" ON "users" ("email");', "COMMIT;", ] - self.assertBackwardIncompatibleSql(sql, code="CREATE_INDEX_EXCLUSIVE") + self.assertWarningSql(sql, code="CREATE_INDEX_EXCLUSIVE") def test_create_index_exclusive_no_lock(self): sql = [