import re

input_file = "dev_dump.sql"
output_file = "dev_dump_mysql.sql"

with open(input_file, "r", encoding="utf-8") as infile, open(output_file, "w", encoding="utf-8") as outfile:
    for line in infile:
        # Skip SQLite-specific commands
        if line.startswith("PRAGMA") or line.startswith("BEGIN TRANSACTION") or line.startswith("COMMIT"):
            continue
        # Replace double quotes with backticks for identifiers
        line = re.sub(r'"([^"]+)"', r'`\1`', line)
        # Replace AUTOINCREMENT
        line = line.replace("AUTOINCREMENT", "AUTO_INCREMENT")
        # Replace data types
        line = re.sub(r"\binteger\b", "int", line, flags=re.IGNORECASE)
        # Remove "WITHOUT ROWID"
        line = line.replace("WITHOUT ROWID", "")
        # Remove SQLite sequence table
        if "sqlite_sequence" in line:
            continue
        # Remove unnecessary semicolons
        if line.strip() == ";":
            continue
        outfile.write(line)

print("Conversion complete! Output written to", output_file)