import re
import sys

def convert(sql_file):
    with open(sql_file, 'r', encoding='utf-8') as f:
        content = f.read()

    # Remove PRAGMA
    content = re.sub(r'PRAGMA.*?;\n', '', content)
    # Remove BEGIN TRANSACTION and COMMIT
    content = re.sub(r'BEGIN TRANSACTION;\n', '', content)
    content = re.sub(r'COMMIT;\n', '', content)
    
    # Replace AUTOINCREMENT with AUTO_INCREMENT
    content = re.sub(r'AUTOINCREMENT', 'AUTO_INCREMENT', content)
    
    # Replace sqlite_sequence with nothing
    content = re.sub(r'DELETE FROM "sqlite_sequence";\n', '', content)
    content = re.sub(r'INSERT INTO "sqlite_sequence" .*?;\n', '', content)
    
    # Double quotes to backticks for table and column names
    content = re.sub(r'"([^"]+)"', r'`\1`', content)

    # Some basic type replacements if necessary, but usually MySQL accepts TEXT/INTEGER
    
    with open('database_dump_mysql.sql', 'w', encoding='utf-8') as f:
        f.write("SET FOREIGN_KEY_CHECKS=0;\n")
        f.write(content)
        f.write("\nSET FOREIGN_KEY_CHECKS=1;\n")

convert('database_dump.sql')
