import os
import django
from django.db import connection

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
django.setup()

tables_to_drop = [
    "payroll_settings",
    "salary_structures",
    "payroll_salary_components",
    "employee_payroll_salaries",
    "employee_salary_history",
    "payroll_periods",
    "payroll_runs",
    "payroll_processing_logs",
    "payroll_items",
    "payroll_overtime",
    "payroll_reimbursements",
    "payroll_payslips",
    "salary_components",
    "salary_structure_components",
    "employee_salaries",
    "payslips",
    "payslip_components",
    "bonuses"
]

with connection.cursor() as cursor:
    for table in tables_to_drop:
        print(f"Dropping table {table}...")
        cursor.execute(f"DROP TABLE IF EXISTS {table} CASCADE;")
    
    # Also delete the migration history for payroll
    cursor.execute("DELETE FROM django_migrations WHERE app='payroll';")

print("Done.")
