Mark migrations as ignored
This commit is contained in:
1 parent
357f0aebf4
commit
9e3dbf7778
22 files changed
+310
-12
No files matched your search
@@ -24,6 +24,11 @@ from .sql_analyser import analyse_sql_statements
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Can be used to mark ignored migrations.
|
||||
# This is a noop for SQL. Comments would be better.
|
||||
# But comments are stripped by RunSQL
|
||||
IGNORE_MIGRATION = "SELECT 'dml-ignore'"
|
||||
|
||||
|
||||
class MigrationLinter(object):
|
||||
MIGRATION_FOLDER_NAME = 'migrations'
|
||||
@@ -69,6 +74,12 @@ class MigrationLinter(object):
|
||||
analysis_result = analyse_sql_statements(
|
||||
sql_statements)
|
||||
errors = analysis_result['errors']
|
||||
|
||||
if analysis_result['ignored']:
|
||||
print('IGNORE')
|
||||
self.nb_ignored += 1
|
||||
return
|
||||
|
||||
if not errors:
|
||||
print('OK')
|
||||
self.nb_valid += 1
|
||||
|
||||
@@ -63,29 +63,45 @@ migration_tests = (
|
||||
'code': '',
|
||||
'fn': has_default,
|
||||
'err_msg': ''
|
||||
}, {
|
||||
'code': 'IGNORED_MIGRATION',
|
||||
'fn': lambda sql, **kw: re.search('dml-ignore', sql),
|
||||
'err_msg': '',
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def analyse_sql_statements(sql_statements):
|
||||
errors = []
|
||||
ignored = False
|
||||
for statement in sql_statements:
|
||||
for test in migration_tests:
|
||||
if test['fn'](statement, errors=errors):
|
||||
logger.info('Testing {0} -- ERROR'.format(statement))
|
||||
table_search = re.search(
|
||||
'TABLE `([^`]*)`', statement, re.IGNORECASE)
|
||||
col_search = re.search(
|
||||
'COLUMN `([^`]*)`', statement, re.IGNORECASE)
|
||||
err = {
|
||||
'err_msg': test['err_msg'],
|
||||
'code': test['code'],
|
||||
'table': table_search.group(1) if table_search else None,
|
||||
'column': col_search.group(1) if col_search else None
|
||||
}
|
||||
errors.append(err)
|
||||
if test['code'] == 'IGNORED_MIGRATION':
|
||||
logger.info(
|
||||
'Testing {0} -- IGNORING MIGRATION'.format(statement)
|
||||
)
|
||||
ignored = True
|
||||
else:
|
||||
logger.info('Testing {0} -- ERROR'.format(statement))
|
||||
table_search = re.search(
|
||||
'TABLE `([^`]*)`', statement, re.IGNORECASE)
|
||||
col_search = re.search(
|
||||
'COLUMN `([^`]*)`', statement, re.IGNORECASE)
|
||||
err = {
|
||||
'err_msg':
|
||||
test['err_msg'],
|
||||
'code':
|
||||
test['code'],
|
||||
'table':
|
||||
table_search.group(1) if table_search else None,
|
||||
'column':
|
||||
col_search.group(1) if col_search else None
|
||||
}
|
||||
errors.append(err)
|
||||
else:
|
||||
logger.info('Testing {0} -- PASSED'.format(statement))
|
||||
return {
|
||||
'errors': errors,
|
||||
'ignored': ignored
|
||||
}
|
||||
Reference in new issue
Block a user