49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
const mysql = require('mysql2/promise');
|
|
|
|
async function createPasswordResetTable() {
|
|
console.log('🚀 創建密碼重設 token 資料表...');
|
|
|
|
try {
|
|
const connection = await mysql.createConnection({
|
|
host: 'mysql.theaken.com',
|
|
port: 33306,
|
|
user: 'AI_Platform',
|
|
password: 'Aa123456',
|
|
database: 'db_AI_Platform',
|
|
charset: 'utf8mb4',
|
|
timezone: '+08:00'
|
|
});
|
|
|
|
console.log('✅ 資料庫連接成功');
|
|
|
|
// 創建密碼重設 tokens 表
|
|
const createTableSQL = `
|
|
CREATE TABLE IF NOT EXISTS password_reset_tokens (
|
|
id VARCHAR(36) PRIMARY KEY,
|
|
user_id VARCHAR(36) NOT NULL,
|
|
token VARCHAR(255) NOT NULL UNIQUE,
|
|
expires_at TIMESTAMP NOT NULL,
|
|
used_at TIMESTAMP NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
|
|
INDEX idx_user_id (user_id),
|
|
INDEX idx_token (token),
|
|
INDEX idx_expires_at (expires_at),
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
`;
|
|
|
|
await connection.execute(createTableSQL);
|
|
console.log('✅ 密碼重設 tokens 表創建成功');
|
|
|
|
await connection.end();
|
|
console.log('🎉 密碼重設表創建完成!');
|
|
|
|
} catch (error) {
|
|
console.error('❌ 創建表時發生錯誤:', error);
|
|
}
|
|
}
|
|
|
|
createPasswordResetTable();
|