cleanup_obsolete_tables.py 942 B

12345678910111213141516171819202122232425262728293031
  1. import db
  2. import sys
  3. def cleanup():
  4. print("Starting database cleanup...")
  5. tables_to_drop = [
  6. "email_verification_tokens",
  7. "password_reset_tokens"
  8. ]
  9. try:
  10. # Check if tables exist before dropping (optional but safer)
  11. for table in tables_to_drop:
  12. print(f"Dropping table: {table}...")
  13. db.execute_commit(f"DROP TABLE IF EXISTS {table}")
  14. print(f"Successfully dropped {table}.")
  15. print("\nDatabase cleanup completed successfully!")
  16. print("All temporary tokens are now managed by Redis.")
  17. except Exception as e:
  18. print(f"Error during cleanup: {e}", file=sys.stderr)
  19. sys.exit(1)
  20. if __name__ == "__main__":
  21. confirm = input("This will permanently delete token tables from MySQL. Are you sure? (y/N): ")
  22. if confirm.lower() == 'y':
  23. cleanup()
  24. else:
  25. print("Cleanup cancelled.")