# Path: django_migration_linter/sql_analyser/base.py
# class BaseAnalyser(object):
#     base_migration_tests = [
#         {
#             "code": "RENAME_TABLE",
#             "fn": lambda sql, **kw: re.search("RENAME TABLE", sql)
#             or re.search("ALTER TABLE .* RENAME TO", sql),
#             "msg": "RENAMING tables",
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "NOT_NULL",
#             "fn": has_not_null_column,
#             "msg": "NOT NULL constraint on columns",
#             "mode": "transaction",
#             "type": "error",
#         },
#         {
#             "code": "DROP_COLUMN",
#             "fn": lambda sql, **kw: re.search("DROP COLUMN", sql),
#             "msg": "DROPPING columns",
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "DROP_TABLE",
#             "fn": lambda sql, **kw: sql.startswith("DROP TABLE"),
#             "msg": "DROPPING table",
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "RENAME_COLUMN",
#             "fn": lambda sql, **kw: re.search("ALTER TABLE .* CHANGE", sql)
#             or re.search("ALTER TABLE .* RENAME COLUMN", sql),
#             "msg": "RENAMING columns",
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "ALTER_COLUMN",
#             "fn": lambda sql, **kw: re.search(
#                 "ALTER TABLE .* ALTER COLUMN .* TYPE", sql
#             ),
#             "msg": (
#                 "ALTERING columns (Could be backward compatible. "
#                 "You may ignore this migration.)"
#             ),
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "ADD_UNIQUE",
#             "fn": has_add_unique,
#             "msg": "ADDING unique constraint",
#             "mode": "transaction",
#             "type": "error",
#         },
#     ]
# 
#     migration_tests = []
# 
#     def __init__(self, exclude_migration_tests):
#         self.exclude_migration_tests = exclude_migration_tests or []
#         self.errors = []
#         self.warnings = []
#         self.ignored = []
#         self.migration_tests = update_migration_tests(
#             self.base_migration_tests, self.migration_tests
#         )
# 
#     def analyse(self, sql_statements):
#         for statement in sql_statements:
#             for test in self.one_line_migration_tests:
#                 self._test_sql(test, sql=statement)
# 
#         for test in self.transaction_migration_tests:
#             self._test_sql(test, sql=sql_statements)
# 
#     @property
#     def one_line_migration_tests(self):
#         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")
# 
#     def _test_sql(self, test, sql):
#         if test["fn"](sql, errors=self.errors):
#             if test["code"] in self.exclude_migration_tests:
#                 action = "IGNORED"
#                 list_to_add = self.ignored
#             elif test["type"] == "warning":
#                 action = "WARNING"
#                 list_to_add = self.warnings
#             else:
#                 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)
# 
#     def build_error_dict(self, migration_test, sql_statement):
#         table = self.detect_table(sql_statement)
#         col = self.detect_column(sql_statement)
#         return {
#             "msg": migration_test["msg"],
#             "code": migration_test["code"],
#             "table": table,
#             "column": col,
#         }
# 
#     @staticmethod
#     def detect_table(sql):
#         if isinstance(sql, str):
#             regex_result = re.search("TABLE [`\"'](.*?)[`\"']", sql, re.IGNORECASE)
#             if regex_result:
#                 return regex_result.group(1)
# 
#     @staticmethod
#     def detect_column(sql):
#         if isinstance(sql, str):
#             regex_result = re.search("COLUMN [`\"'](.*?)[`\"']", sql, re.IGNORECASE)
#             if regex_result:
#                 return regex_result.group(1)


import re
from .base import BaseAnalyser



class MySqlAnalyser(BaseAnalyser):
    migration_tests = [
        {
            "code": "ALTER_COLUMN",
            "fn": lambda sql, **kw: re.search(
                "ALTER TABLE .* MODIFY .* (?!NULL);?$", sql
            ),
            "mode": "one_liner",
            "type": "error",
        }
    ]

    @staticmethod

# Path: django_migration_linter/sql_analyser/base.py
# class BaseAnalyser(object):
#     base_migration_tests = [
#         {
#             "code": "RENAME_TABLE",
#             "fn": lambda sql, **kw: re.search("RENAME TABLE", sql)
#             or re.search("ALTER TABLE .* RENAME TO", sql),
#             "msg": "RENAMING tables",
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "NOT_NULL",
#             "fn": has_not_null_column,
#             "msg": "NOT NULL constraint on columns",
#             "mode": "transaction",
#             "type": "error",
#         },
#         {
#             "code": "DROP_COLUMN",
#             "fn": lambda sql, **kw: re.search("DROP COLUMN", sql),
#             "msg": "DROPPING columns",
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "DROP_TABLE",
#             "fn": lambda sql, **kw: sql.startswith("DROP TABLE"),
#             "msg": "DROPPING table",
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "RENAME_COLUMN",
#             "fn": lambda sql, **kw: re.search("ALTER TABLE .* CHANGE", sql)
#             or re.search("ALTER TABLE .* RENAME COLUMN", sql),
#             "msg": "RENAMING columns",
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "ALTER_COLUMN",
#             "fn": lambda sql, **kw: re.search(
#                 "ALTER TABLE .* ALTER COLUMN .* TYPE", sql
#             ),
#             "msg": (
#                 "ALTERING columns (Could be backward compatible. "
#                 "You may ignore this migration.)"
#             ),
#             "mode": "one_liner",
#             "type": "error",
#         },
#         {
#             "code": "ADD_UNIQUE",
#             "fn": has_add_unique,
#             "msg": "ADDING unique constraint",
#             "mode": "transaction",
#             "type": "error",
#         },
#     ]
# 
#     migration_tests = []
# 
#     def __init__(self, exclude_migration_tests):
#         self.exclude_migration_tests = exclude_migration_tests or []
#         self.errors = []
#         self.warnings = []
#         self.ignored = []
#         self.migration_tests = update_migration_tests(
#             self.base_migration_tests, self.migration_tests
#         )
# 
#     def analyse(self, sql_statements):
#         for statement in sql_statements:
#             for test in self.one_line_migration_tests:
#                 self._test_sql(test, sql=statement)
# 
#         for test in self.transaction_migration_tests:
#             self._test_sql(test, sql=sql_statements)
# 
#     @property
#     def one_line_migration_tests(self):
#         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")
# 
#     def _test_sql(self, test, sql):
#         if test["fn"](sql, errors=self.errors):
#             if test["code"] in self.exclude_migration_tests:
#                 action = "IGNORED"
#                 list_to_add = self.ignored
#             elif test["type"] == "warning":
#                 action = "WARNING"
#                 list_to_add = self.warnings
#             else:
#                 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)
# 
#     def build_error_dict(self, migration_test, sql_statement):
#         table = self.detect_table(sql_statement)
#         col = self.detect_column(sql_statement)
#         return {
#             "msg": migration_test["msg"],
#             "code": migration_test["code"],
#             "table": table,
#             "column": col,
#         }
# 
#     @staticmethod
#     def detect_table(sql):
#         if isinstance(sql, str):
#             regex_result = re.search("TABLE [`\"'](.*?)[`\"']", sql, re.IGNORECASE)
#             if regex_result:
#                 return regex_result.group(1)
# 
#     @staticmethod
#     def detect_column(sql):
#         if isinstance(sql, str):
#             regex_result = re.search("COLUMN [`\"'](.*?)[`\"']", sql, re.IGNORECASE)
#             if regex_result:
#                 return regex_result.group(1)


# Path: django_migration_linter/sql_analyser/mysql.py
import re
from .base import BaseAnalyser




class MySqlAnalyser(BaseAnalyser):
    migration_tests = [
        {
            "code": "ALTER_COLUMN",
            "fn": lambda sql, **kw: re.search(
                "ALTER TABLE .* MODIFY .* (?!NULL);?$", sql
            ),
            "mode": "one_liner",
            "type": "error",
        }
    ]

    @staticmethod

    def detect_column(sql):