Fix #178 -- Don't detect an index creation when the table is being created
This commit is contained in:
1 parent
888305caaf
commit
7674a51bc9
3 files changed
+40
-4
No files matched your search
@@ -3,14 +3,32 @@ import re
|
||||
from .base import BaseAnalyser
|
||||
|
||||
|
||||
def has_create_index(sql_statements, **kwargs):
|
||||
regex_result = None
|
||||
for sql in sql_statements:
|
||||
regex_result = re.search(r"CREATE (UNIQUE )?INDEX.*ON (.*) \(", sql)
|
||||
if re.search("INDEX CONCURRENTLY", sql):
|
||||
regex_result = None
|
||||
elif regex_result:
|
||||
break
|
||||
if not regex_result:
|
||||
return False
|
||||
|
||||
concerned_table = regex_result.group(2)
|
||||
table_is_added_in_transaction = any(
|
||||
sql.startswith("CREATE TABLE {}".format(concerned_table))
|
||||
for sql in sql_statements
|
||||
)
|
||||
return not table_is_added_in_transaction
|
||||
|
||||
|
||||
class PostgresqlAnalyser(BaseAnalyser):
|
||||
migration_tests = [
|
||||
{
|
||||
"code": "CREATE_INDEX",
|
||||
"fn": lambda sql, **kw: re.search("CREATE (UNIQUE )?INDEX", sql)
|
||||
and not re.search("INDEX CONCURRENTLY", sql),
|
||||
"fn": has_create_index,
|
||||
"msg": "CREATE INDEX locks table",
|
||||
"mode": "one_liner",
|
||||
"mode": "transaction",
|
||||
"type": "warning",
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user