"""
FreeFlow DB 리셋 스크립트
모든 테이블을 삭제하고 Prisma로 재생성합니다.
⚠️ 개발 환경에서만 사용하세요!
"""
import mysql.connector
import subprocess
import sys

DB_CONFIG = {
    'host': 'officialsite.kr',
    'port': 23306,
    'user': 'admin',
    'password': 'dlgks~123',
    'database': 'freeflow',
}

def main():
    confirm = input("⚠️  This will DROP ALL TABLES in 'freeflow'. Type 'yes' to confirm: ")
    if confirm != 'yes':
        print("Cancelled.")
        return

    conn = mysql.connector.connect(**DB_CONFIG)
    cursor = conn.cursor()

    cursor.execute("SET FOREIGN_KEY_CHECKS = 0")
    cursor.execute("SHOW TABLES")
    tables = cursor.fetchall()

    for (table_name,) in tables:
        cursor.execute(f"DROP TABLE IF EXISTS `{table_name}`")
        print(f"  🗑️  Dropped {table_name}")

    cursor.execute("SET FOREIGN_KEY_CHECKS = 1")
    conn.commit()
    cursor.close()
    conn.close()

    print(f"\n✅ Dropped {len(tables)} tables")
    print("🔄 Run 'npx prisma db push' to recreate tables")

if __name__ == '__main__':
    main()
