Add warnings type to SQL analyser
This commit is contained in:
1 parent
a119b4ba1f
commit
9ea8872a29
3 files changed
+27
-5
No files matched your search
@@ -48,24 +48,28 @@ class BaseAnalyser(object):
|
|||||||
or re.search("ALTER TABLE .* RENAME TO", sql),
|
or re.search("ALTER TABLE .* RENAME TO", sql),
|
||||||
"msg": "RENAMING tables",
|
"msg": "RENAMING tables",
|
||||||
"mode": "one_liner",
|
"mode": "one_liner",
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": "NOT_NULL",
|
"code": "NOT_NULL",
|
||||||
"fn": has_not_null_column,
|
"fn": has_not_null_column,
|
||||||
"msg": "NOT NULL constraint on columns",
|
"msg": "NOT NULL constraint on columns",
|
||||||
"mode": "transaction",
|
"mode": "transaction",
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": "DROP_COLUMN",
|
"code": "DROP_COLUMN",
|
||||||
"fn": lambda sql, **kw: re.search("DROP COLUMN", sql),
|
"fn": lambda sql, **kw: re.search("DROP COLUMN", sql),
|
||||||
"msg": "DROPPING columns",
|
"msg": "DROPPING columns",
|
||||||
"mode": "one_liner",
|
"mode": "one_liner",
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": "DROP_TABLE",
|
"code": "DROP_TABLE",
|
||||||
"fn": lambda sql, **kw: sql.startswith("DROP TABLE"),
|
"fn": lambda sql, **kw: sql.startswith("DROP TABLE"),
|
||||||
"msg": "DROPPING table",
|
"msg": "DROPPING table",
|
||||||
"mode": "one_liner",
|
"mode": "one_liner",
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": "RENAME_COLUMN",
|
"code": "RENAME_COLUMN",
|
||||||
@@ -73,6 +77,7 @@ class BaseAnalyser(object):
|
|||||||
or re.search("ALTER TABLE .* RENAME COLUMN", sql),
|
or re.search("ALTER TABLE .* RENAME COLUMN", sql),
|
||||||
"msg": "RENAMING columns",
|
"msg": "RENAMING columns",
|
||||||
"mode": "one_liner",
|
"mode": "one_liner",
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": "ALTER_COLUMN",
|
"code": "ALTER_COLUMN",
|
||||||
@@ -84,12 +89,14 @@ class BaseAnalyser(object):
|
|||||||
"You may ignore this migration.)"
|
"You may ignore this migration.)"
|
||||||
),
|
),
|
||||||
"mode": "one_liner",
|
"mode": "one_liner",
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": "ADD_UNIQUE",
|
"code": "ADD_UNIQUE",
|
||||||
"fn": has_add_unique,
|
"fn": has_add_unique,
|
||||||
"msg": "ADDING unique constraint",
|
"msg": "ADDING unique constraint",
|
||||||
"mode": "transaction",
|
"mode": "transaction",
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -98,6 +105,7 @@ class BaseAnalyser(object):
|
|||||||
def __init__(self, exclude_migration_tests):
|
def __init__(self, exclude_migration_tests):
|
||||||
self.exclude_migration_tests = exclude_migration_tests or []
|
self.exclude_migration_tests = exclude_migration_tests or []
|
||||||
self.errors = []
|
self.errors = []
|
||||||
|
self.warnings = []
|
||||||
self.ignored = []
|
self.ignored = []
|
||||||
self.migration_tests = update_migration_tests(
|
self.migration_tests = update_migration_tests(
|
||||||
self.base_migration_tests, self.migration_tests
|
self.base_migration_tests, self.migration_tests
|
||||||
@@ -123,11 +131,16 @@ class BaseAnalyser(object):
|
|||||||
if test["fn"](sql, errors=self.errors):
|
if test["fn"](sql, errors=self.errors):
|
||||||
err = self.build_error_dict(migration_test=test, sql_statement=sql)
|
err = self.build_error_dict(migration_test=test, sql_statement=sql)
|
||||||
if test["code"] in self.exclude_migration_tests:
|
if test["code"] in self.exclude_migration_tests:
|
||||||
logger.debug("Testing %s -- IGNORED", sql)
|
action = "IGNORED"
|
||||||
self.ignored.append(err)
|
list_to_add = self.ignored
|
||||||
|
elif test["type"] == "warning":
|
||||||
|
action = "WARNING"
|
||||||
|
list_to_add = self.warnings
|
||||||
else:
|
else:
|
||||||
logger.debug("Testing %s -- ERROR", sql)
|
action = "ERROR"
|
||||||
self.errors.append(err)
|
list_to_add = self.errors
|
||||||
|
logger.debug("Testing %s -- %s", sql, action)
|
||||||
|
list_to_add.append(err)
|
||||||
else:
|
else:
|
||||||
logger.debug("Testing %s -- PASSED", sql)
|
logger.debug("Testing %s -- PASSED", sql)
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class MySqlAnalyser(BaseAnalyser):
|
|||||||
"ALTER TABLE .* MODIFY .* (?!NULL);?$", sql
|
"ALTER TABLE .* MODIFY .* (?!NULL);?$", sql
|
||||||
),
|
),
|
||||||
"mode": "one_liner",
|
"mode": "one_liner",
|
||||||
|
"type": "error",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class SqliteAnalyser(BaseAnalyser):
|
|||||||
"fn": lambda sql, **kw: re.search("ALTER TABLE .* RENAME TO", sql)
|
"fn": lambda sql, **kw: re.search("ALTER TABLE .* RENAME TO", sql)
|
||||||
and "__old" not in sql
|
and "__old" not in sql
|
||||||
and "new__" not in sql,
|
and "new__" not in sql,
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": "DROP_TABLE",
|
"code": "DROP_TABLE",
|
||||||
@@ -37,6 +38,7 @@ class SqliteAnalyser(BaseAnalyser):
|
|||||||
and not any(sql.startswith("CREATE TABLE") for sql in sql_statements),
|
and not any(sql.startswith("CREATE TABLE") for sql in sql_statements),
|
||||||
"msg": "DROPPING table",
|
"msg": "DROPPING table",
|
||||||
"mode": "transaction",
|
"mode": "transaction",
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code": "NOT_NULL",
|
"code": "NOT_NULL",
|
||||||
@@ -50,8 +52,14 @@ class SqliteAnalyser(BaseAnalyser):
|
|||||||
for sql in sql_statements
|
for sql in sql_statements
|
||||||
),
|
),
|
||||||
"mode": "transaction",
|
"mode": "transaction",
|
||||||
|
"type": "error",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": "ADD_UNIQUE",
|
||||||
|
"fn": has_add_unique,
|
||||||
|
"mode": "transaction",
|
||||||
|
"type": "error",
|
||||||
},
|
},
|
||||||
{"code": "ADD_UNIQUE", "fn": has_add_unique, "mode": "transaction"},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in new issue
Block a user