"""
Mark accounts.0001 as applied without CREATE (legacy DB already has those tables),
then run normal migrate to apply follow-ups (e.g. 0002_legacy_mysql_user_extras).

Usage (from repo root, DATABASE_URL set in .env):

  venv/bin/python backend/manage.py bootstrap_legacy_mysql
"""

from django.core.management import call_command
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = "Fake accounts.0001 on an existing FastAPI MySQL schema, then migrate forward."

    def handle(self, *args, **options):
        self.stdout.write("Faking accounts.0001_initial (tables already exist from legacy app)...")
        call_command("migrate", "accounts", "0001", fake=True, verbosity=1)
        self.stdout.write("Running full migrate...")
        call_command("migrate", verbosity=1)
        self.stdout.write(self.style.SUCCESS("Done. Run: python backend/manage.py migrate_legacy_auth"))
