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:
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",
|
||||
|
||||
@@ -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 |
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -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 = [
|
||||
|
||||
Reference in new issue
Block a user