migrate_verification.py 796 B

12345678910111213141516171819202122
  1. import db
  2. def migrate():
  3. print("Starting migration: creating email_verification_tokens table...")
  4. query = """
  5. CREATE TABLE IF NOT EXISTS email_verification_tokens (
  6. id INT AUTO_INCREMENT PRIMARY KEY,
  7. user_id INT NOT NULL,
  8. token VARCHAR(255) NOT NULL UNIQUE,
  9. expires_at TIMESTAMP NOT NULL,
  10. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  11. FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
  12. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  13. """
  14. try:
  15. db.execute_commit(query)
  16. print("SUCCESS: Table 'email_verification_tokens' created successfully (or already exists).")
  17. except Exception as e:
  18. print(f"ERROR creating table: {e}")
  19. if __name__ == "__main__":
  20. migrate()