import db
import sys

def cleanup():
    print("Starting database cleanup...")
    
    tables_to_drop = [
        "email_verification_tokens",
        "password_reset_tokens"
    ]
    
    try:
        # Check if tables exist before dropping (optional but safer)
        for table in tables_to_drop:
            print(f"Dropping table: {table}...")
            db.execute_commit(f"DROP TABLE IF EXISTS {table}")
            print(f"Successfully dropped {table}.")
            
        print("\nDatabase cleanup completed successfully!")
        print("All temporary tokens are now managed by Redis.")
        
    except Exception as e:
        print(f"Error during cleanup: {e}", file=sys.stderr)
        sys.exit(1)

if __name__ == "__main__":
    confirm = input("This will permanently delete token tables from MySQL. Are you sure? (y/N): ")
    if confirm.lower() == 'y':
        cleanup()
    else:
        print("Cleanup cancelled.")
