整合資料庫、完成登入註冊忘記密碼功能
This commit is contained in:
106
scripts/migrate-data.js
Normal file
106
scripts/migrate-data.js
Normal file
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// =====================================================
|
||||
// 初始數據遷移腳本
|
||||
// =====================================================
|
||||
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
// 資料庫配置
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST || 'mysql.theaken.com',
|
||||
port: parseInt(process.env.DB_PORT || '33306'),
|
||||
user: process.env.DB_USER || 'AI_Platform',
|
||||
password: process.env.DB_PASSWORD || 'Aa123456',
|
||||
database: process.env.DB_NAME || 'db_AI_Platform',
|
||||
charset: 'utf8mb4',
|
||||
timezone: '+08:00',
|
||||
acquireTimeout: 60000,
|
||||
timeout: 60000,
|
||||
reconnect: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
};
|
||||
|
||||
async function migrateData() {
|
||||
let connection;
|
||||
|
||||
try {
|
||||
console.log('🚀 開始初始數據遷移...');
|
||||
|
||||
// 創建連接
|
||||
connection = await mysql.createConnection({
|
||||
...dbConfig,
|
||||
multipleStatements: true
|
||||
});
|
||||
|
||||
console.log('✅ 資料庫連接成功');
|
||||
|
||||
// 系統設定數據
|
||||
const systemSettingsSQL = `
|
||||
INSERT INTO system_settings (id, \`key\`, value, description, category, is_public) VALUES
|
||||
(UUID(), 'site_name', '強茂集團 AI 展示平台', '網站名稱', 'general', TRUE),
|
||||
(UUID(), 'site_description', '企業內部 AI 應用展示與競賽管理系統', '網站描述', 'general', TRUE),
|
||||
(UUID(), 'max_team_size', '5', '最大團隊人數', 'competition', FALSE),
|
||||
(UUID(), 'max_file_size', '10485760', '最大文件上傳大小(字節)', 'upload', FALSE),
|
||||
(UUID(), 'allowed_file_types', 'jpg,jpeg,png,gif,pdf,doc,docx,ppt,pptx', '允許上傳的文件類型', 'upload', FALSE)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
value = VALUES(value),
|
||||
description = VALUES(description),
|
||||
category = VALUES(category),
|
||||
is_public = VALUES(is_public),
|
||||
updated_at = CURRENT_TIMESTAMP;
|
||||
`;
|
||||
|
||||
console.log('⚡ 插入系統設定...');
|
||||
await connection.execute(systemSettingsSQL);
|
||||
console.log('✅ 系統設定插入成功');
|
||||
|
||||
// AI 助手配置數據
|
||||
const aiConfigSQL = `
|
||||
INSERT INTO ai_assistant_configs (id, api_key, api_url, model, max_tokens, temperature, system_prompt, is_active) VALUES
|
||||
(UUID(), 'sk-3640dcff23fe4a069a64f536ac538d75', 'https://api.deepseek.com/v1/chat/completions', 'deepseek-chat', 200, 0.70, '你是一個競賽管理系統的AI助手,專門幫助用戶了解如何使用這個系統。請用友善、專業的語氣回答用戶問題,並提供具體的操作步驟。回答要簡潔明瞭,避免過長的文字。重要:請不要使用任何Markdown格式,只使用純文字回答。回答時請使用繁體中文。', TRUE)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
api_key = VALUES(api_key),
|
||||
api_url = VALUES(api_url),
|
||||
model = VALUES(model),
|
||||
max_tokens = VALUES(max_tokens),
|
||||
temperature = VALUES(temperature),
|
||||
system_prompt = VALUES(system_prompt),
|
||||
is_active = VALUES(is_active),
|
||||
updated_at = CURRENT_TIMESTAMP;
|
||||
`;
|
||||
|
||||
console.log('⚡ 插入 AI 助手配置...');
|
||||
await connection.execute(aiConfigSQL);
|
||||
console.log('✅ AI 助手配置插入成功');
|
||||
|
||||
// 檢查插入的數據
|
||||
console.log('🔍 檢查插入的數據...');
|
||||
|
||||
const [settings] = await connection.execute('SELECT COUNT(*) as count FROM system_settings');
|
||||
console.log(`⚙️ 系統設定數量: ${settings[0].count}`);
|
||||
|
||||
const [aiConfigs] = await connection.execute('SELECT COUNT(*) as count FROM ai_assistant_configs');
|
||||
console.log(`🤖 AI 助手配置數量: ${aiConfigs[0].count}`);
|
||||
|
||||
console.log('🎉 初始數據遷移完成!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 數據遷移失敗:', error.message);
|
||||
console.error('詳細錯誤:', error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
if (connection) {
|
||||
await connection.end();
|
||||
console.log('🔌 資料庫連接已關閉');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 執行遷移
|
||||
if (require.main === module) {
|
||||
migrateData().catch(console.error);
|
||||
}
|
||||
|
||||
module.exports = { migrateData };
|
Reference in New Issue
Block a user