浏览代码

chore: add db migration script for email verification

unknown 2 天之前
父节点
当前提交
fececd3c75
共有 1 个文件被更改,包括 22 次插入0 次删除
  1. 22 0
      backend/migrate_verification.py

+ 22 - 0
backend/migrate_verification.py

@@ -0,0 +1,22 @@
+import db
+
+def migrate():
+    print("Starting migration: creating email_verification_tokens table...")
+    query = """
+    CREATE TABLE IF NOT EXISTS email_verification_tokens (
+        id INT AUTO_INCREMENT PRIMARY KEY,
+        user_id INT NOT NULL,
+        token VARCHAR(255) NOT NULL UNIQUE,
+        expires_at TIMESTAMP NOT NULL,
+        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+        FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
+    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+    """
+    try:
+        db.execute_commit(query)
+        print("SUCCESS: Table 'email_verification_tokens' created successfully (or already exists).")
+    except Exception as e:
+        print(f"ERROR creating table: {e}")
+
+if __name__ == "__main__":
+    migrate()