# Path: django_migration_linter/sql_analyser/analyser.py
# def analyse_sql_statements(
#     sql_analyser_class, sql_statements, exclude_migration_tests=None
# ):
#     sql_analyser = sql_analyser_class(exclude_migration_tests)
#     sql_analyser.analyse(sql_statements)
#     return sql_analyser.errors, sql_analyser.ignored, sql_analyser.warnings
# 
# def get_sql_analyser_class(database_vendor, analyser_string=None):
#     if analyser_string:
#         return get_sql_analyser_from_string(analyser_string)
#     return get_sql_analyser_class_from_db_vendor(database_vendor)


import unittest
from django_migration_linter.sql_analyser import (
    analyse_sql_statements,
    get_sql_analyser_class,
)
    database_vendor = "mysql"

    def test_alter_column(self):
        sql = "ALTER TABLE `app_alter_column_a` MODIFY `field` varchar(10) NULL;"
        self.assertValidSql(sql)

    def test_drop_not_null(self):
        sql = "ALTER TABLE `app_alter_column_drop_not_null_a` MODIFY `not_null_field` integer NULL;"
        self.assertValidSql(sql)

    def test_add_not_null(self):
        sql = [
            "ALTER TABLE `app_add_not_null_column_a` ADD COLUMN `new_not_null_field` integer DEFAULT 1 NOT NULL;",
            "ALTER TABLE `app_add_not_null_column_a` ALTER COLUMN `new_not_null_field` DROP DEFAULT;",
        ]
        self.assertBackwardIncompatibleSql(sql)

    def test_add_not_null_followed_by_default(self):
        sql = [
            "ALTER TABLE `app_add_not_null_column_followed_by_default_a` ADD COLUMN `new_not_null_field` integer DEFAULT 1 NOT NULL;",
            "ALTER TABLE `app_add_not_null_column_followed_by_default_a` ALTER COLUMN `new_not_null_field` DROP DEFAULT;",
            "ALTER TABLE `app_add_not_null_column_followed_by_default_a` ALTER COLUMN `new_not_null_field` SET DEFAULT '1';",
        ]
        self.assertValidSql(sql)

    def test_unique_together(self):
        sql = "ALTER TABLE `app_unique_together_a` ADD CONSTRAINT `app_unique_together_a_int_field_char_field_979ac7d8_uniq` UNIQUE (`int_field`, `char_field`);"
        self.assertBackwardIncompatibleSql(sql)

        sql = "ALTER TABLE `app_unique_together_a` DROP INDEX `app_unique_together_a_int_field_char_field_979ac7d8_uniq`;"

# Path: django_migration_linter/sql_analyser/analyser.py
# def analyse_sql_statements(
#     sql_analyser_class, sql_statements, exclude_migration_tests=None
# ):
#     sql_analyser = sql_analyser_class(exclude_migration_tests)
#     sql_analyser.analyse(sql_statements)
#     return sql_analyser.errors, sql_analyser.ignored, sql_analyser.warnings
# 
# def get_sql_analyser_class(database_vendor, analyser_string=None):
#     if analyser_string:
#         return get_sql_analyser_from_string(analyser_string)
#     return get_sql_analyser_class_from_db_vendor(database_vendor)


# Path: tests/unit/test_sql_analyser.py
import unittest
from django_migration_linter.sql_analyser import (
    analyse_sql_statements,
    get_sql_analyser_class,
)

    database_vendor = "mysql"

    def test_alter_column(self):
        sql = "ALTER TABLE `app_alter_column_a` MODIFY `field` varchar(10) NULL;"
        self.assertValidSql(sql)

    def test_drop_not_null(self):
        sql = "ALTER TABLE `app_alter_column_drop_not_null_a` MODIFY `not_null_field` integer NULL;"
        self.assertValidSql(sql)

    def test_add_not_null(self):
        sql = [
            "ALTER TABLE `app_add_not_null_column_a` ADD COLUMN `new_not_null_field` integer DEFAULT 1 NOT NULL;",
            "ALTER TABLE `app_add_not_null_column_a` ALTER COLUMN `new_not_null_field` DROP DEFAULT;",
        ]
        self.assertBackwardIncompatibleSql(sql)

    def test_add_not_null_followed_by_default(self):
        sql = [
            "ALTER TABLE `app_add_not_null_column_followed_by_default_a` ADD COLUMN `new_not_null_field` integer DEFAULT 1 NOT NULL;",
            "ALTER TABLE `app_add_not_null_column_followed_by_default_a` ALTER COLUMN `new_not_null_field` DROP DEFAULT;",
            "ALTER TABLE `app_add_not_null_column_followed_by_default_a` ALTER COLUMN `new_not_null_field` SET DEFAULT '1';",
        ]
        self.assertValidSql(sql)

    def test_unique_together(self):
        sql = "ALTER TABLE `app_unique_together_a` ADD CONSTRAINT `app_unique_together_a_int_field_char_field_979ac7d8_uniq` UNIQUE (`int_field`, `char_field`);"
        self.assertBackwardIncompatibleSql(sql)

        sql = "ALTER TABLE `app_unique_together_a` DROP INDEX `app_unique_together_a_int_field_char_field_979ac7d8_uniq`;"

        self.assertValidSql(sql)