Add PG reindex linting warning and improve some smaller stuff

This commit is contained in:
David Wobrock committed 2021-06-19 18:15:40 +02:00
1 parent 6e15f65467
commit fa56196f04
4 files changed
+21 -7

No files matched your search

+3 -3
View File
@@ -121,15 +121,14 @@ class BaseAnalyser(object):
@property
def one_line_migration_tests(self):
return [test for test in self.migration_tests if test["mode"] == "one_liner"]
return (test for test in self.migration_tests if test["mode"] == "one_liner")
@property
def transaction_migration_tests(self):
return [test for test in self.migration_tests if test["mode"] == "transaction"]
return (test for test in self.migration_tests if test["mode"] == "transaction")
def _test_sql(self, test, sql):
if test["fn"](sql, errors=self.errors):
err = self.build_error_dict(migration_test=test, sql_statement=sql)
if test["code"] in self.exclude_migration_tests:
action = "IGNORED"
list_to_add = self.ignored
@@ -140,6 +139,7 @@ class BaseAnalyser(object):
action = "ERROR"
list_to_add = self.errors
logger.debug("Testing %s -- %s", sql, action)
err = self.build_error_dict(migration_test=test, sql_statement=sql)
list_to_add.append(err)
else:
logger.debug("Testing %s -- PASSED", sql)
@@ -21,4 +21,11 @@ class PostgresqlAnalyser(BaseAnalyser):
"mode": "one_liner",
"type": "warning",
},
{
"code": "REINDEX",
"fn": lambda sql, **kw: sql.startswith("REINDEX"),
"msg": "REINDEX locks table",
"mode": "one_liner",
"type": "warning",
},
]
+3 -2
View File
@@ -39,5 +39,6 @@ You can ignore check through the `--exclude-migration-test` option and specifyin
|`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)
|`CREATE_INDEX` | Creating an index without the concurrent keyword will lock the table and may generate downtime
|`DROP_INDEX` | Dropping an index without the concurrent keyword will lock the table and may generate downtime
|`CREATE_INDEX` | (Postgresql specific) Creating an index without the concurrent keyword will lock the table and may generate downtime
|`DROP_INDEX` | (Postgresql specific) Dropping an index without the concurrent keyword will lock the table and may generate downtime
|`REINDEX` | (Postgresql specific) Reindexing will lock the table and may generate downtime
+8 -2
View File
@@ -213,13 +213,13 @@ class PostgresqlAnalyserTestCase(SqlAnalyserTestCase):
self.assertValidSql(sql)
def test_create_index_non_concurrently(self):
sql = "CREATE INDEX ON films ((lower(titre)));"
sql = "CREATE INDEX ON films ((lower(title)));"
self.assertWarningSql(sql)
sql = "CREATE UNIQUE INDEX title_idx ON films (title);"
self.assertWarningSql(sql)
def test_create_index_concurrently(self):
sql = "CREATE INDEX CONCURRENTLY ON films ((lower(titre)));"
sql = "CREATE INDEX CONCURRENTLY ON films (lower(title));"
self.assertValidSql(sql)
sql = "CREATE UNIQUE INDEX CONCURRENTLY title_idx ON films (title);"
self.assertValidSql(sql)
@@ -231,3 +231,9 @@ class PostgresqlAnalyserTestCase(SqlAnalyserTestCase):
def test_drop_index_concurrently(self):
sql = "DROP INDEX CONCURRENTLY ON films;"
self.assertValidSql(sql)
def test_reindex(self):
sql = "REINDEX INDEX my_index;"
self.assertWarningSql(sql)
sql = "REINDEX TABLE my_table;"
self.assertWarningSql(sql)