完成評審評分機制
This commit is contained in:
66
scripts/create-team-scores-table.js
Normal file
66
scripts/create-team-scores-table.js
Normal file
@@ -0,0 +1,66 @@
|
||||
// =====================================================
|
||||
// 創建團隊評分表
|
||||
// =====================================================
|
||||
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
async function createTeamScoresTable() {
|
||||
console.log('🔧 創建團隊評分表...\n');
|
||||
|
||||
try {
|
||||
// 連接資料庫
|
||||
const connection = await mysql.createConnection({
|
||||
host: process.env.DB_HOST || '122.100.99.161',
|
||||
port: parseInt(process.env.DB_PORT || '43306'),
|
||||
user: process.env.DB_USER || 'AI_Platform',
|
||||
password: process.env.DB_PASSWORD || 'Aa123456',
|
||||
database: process.env.DB_NAME || 'db_AI_Platform'
|
||||
});
|
||||
|
||||
console.log('✅ 資料庫連接成功');
|
||||
|
||||
// 創建團隊評分表
|
||||
const createTableSQL = `
|
||||
CREATE TABLE IF NOT EXISTS team_judge_scores (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
judge_id VARCHAR(36) NOT NULL,
|
||||
team_id VARCHAR(36) NOT NULL,
|
||||
innovation_score INT NOT NULL CHECK (innovation_score >= 1 AND innovation_score <= 10),
|
||||
technical_score INT NOT NULL CHECK (technical_score >= 1 AND technical_score <= 10),
|
||||
usability_score INT NOT NULL CHECK (usability_score >= 1 AND usability_score <= 10),
|
||||
presentation_score INT NOT NULL CHECK (presentation_score >= 1 AND presentation_score <= 10),
|
||||
impact_score INT NOT NULL CHECK (impact_score >= 1 AND impact_score <= 10),
|
||||
total_score DECIMAL(5,2) NOT NULL,
|
||||
comments TEXT,
|
||||
submitted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
FOREIGN KEY (judge_id) REFERENCES judges(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE,
|
||||
UNIQUE KEY unique_judge_team (judge_id, team_id),
|
||||
INDEX idx_judge (judge_id),
|
||||
INDEX idx_team (team_id),
|
||||
INDEX idx_total_score (total_score)
|
||||
)
|
||||
`;
|
||||
|
||||
await connection.execute(createTableSQL);
|
||||
console.log('✅ 團隊評分表創建成功');
|
||||
|
||||
// 檢查表是否創建成功
|
||||
const [tables] = await connection.execute("SHOW TABLES LIKE 'team_judge_scores'");
|
||||
if (tables.length > 0) {
|
||||
console.log('✅ 表存在確認成功');
|
||||
} else {
|
||||
console.log('❌ 表創建失敗');
|
||||
}
|
||||
|
||||
await connection.end();
|
||||
console.log('\n✅ 團隊評分表創建完成!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 創建表失敗:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 執行創建
|
||||
createTeamScoresTable();
|
Reference in New Issue
Block a user