Downgrade CREATE_INDEX_EXCLUSIVE to a warning

While it's always a dangerous *pattern* to create an index while a
transaction is open & holds an exclusive lock, in practice it's not
always a big deal (for example, indexing a table with very few rows can
be fast). Accordingly, downgrade to a warning.
This commit is contained in:
David Cain authored and David Wobrock committed 2023-07-09 14:42:35 +02:00
1 parent 0c5519d9dc
commit 48fac8856b
4 files changed
+14 -6

No files matched your search

@@ -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",
+1 -1
View File
@@ -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 |
+3 -2
View File
@@ -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)
+9 -2
View File
@@ -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 = [