"""Shared legacy-MySQL connection config for all migrate_legacy_* commands.

Reads from environment variables so the same scripts work against any dump
without code changes:

    LEGACY_DB_HOST      default: host.docker.internal
    LEGACY_DB_PORT      default: 3306
    LEGACY_DB_USER      default: root
    LEGACY_DB_PASSWORD  default: Joshua..123
    LEGACY_DB_NAME      default: ruforum_rims_db

For the rims2 dump loaded into the migration container run:
    LEGACY_DB_NAME=rims2 LEGACY_DB_PORT=3307 LEGACY_DB_PASSWORD=migrate123 \
        docker compose run --rm web python manage.py migrate_legacy_rims2
"""
from __future__ import annotations
import os

# PyMySQL is a pure-Python MySQL driver that can masquerade as MySQLdb.
# This lets the migration scripts run in any environment without needing
# the native libmysqlclient C library.
try:
    import MySQLdb  # noqa: F401 — native driver already present
except ImportError:
    import pymysql
    pymysql.install_as_MySQLdb()

LEGACY_DB: dict = {
    "host":     os.environ.get("LEGACY_DB_HOST",     "host.docker.internal"),
    "port":     int(os.environ.get("LEGACY_DB_PORT", "3306")),
    "user":     os.environ.get("LEGACY_DB_USER",     "root"),
    "password": os.environ.get("LEGACY_DB_PASSWORD", "Joshua..123"),
    "db":       os.environ.get("LEGACY_DB_NAME",     "ruforum_rims_db"),
    "charset":  "utf8mb4",
    "use_unicode": True,
}
