修正時間到上船數據問題
This commit is contained in:
71
lib/database/migrations/add-timeout-columns.ts
Normal file
71
lib/database/migrations/add-timeout-columns.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { executeQuery } from '../connection'
|
||||
|
||||
// 添加 is_timeout 欄位到現有資料庫表
|
||||
export async function addTimeoutColumns(): Promise<void> {
|
||||
try {
|
||||
console.log('🔄 開始添加 is_timeout 欄位...')
|
||||
|
||||
// 檢查並添加 test_results 表的 is_timeout 欄位
|
||||
try {
|
||||
// 先檢查欄位是否已存在
|
||||
const checkColumnQuery = `
|
||||
SELECT COUNT(*) as count
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'test_results'
|
||||
AND COLUMN_NAME = 'is_timeout'
|
||||
`
|
||||
const result = await executeQuery(checkColumnQuery)
|
||||
const columnExists = result[0]?.count > 0
|
||||
|
||||
if (!columnExists) {
|
||||
await executeQuery(`
|
||||
ALTER TABLE test_results
|
||||
ADD COLUMN is_timeout BOOLEAN DEFAULT FALSE
|
||||
`)
|
||||
console.log('✅ test_results 表已添加 is_timeout 欄位')
|
||||
} else {
|
||||
console.log('ℹ️ test_results 表的 is_timeout 欄位已存在,跳過')
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('❌ 檢查/添加 test_results 表 is_timeout 欄位失敗:', error.message)
|
||||
}
|
||||
|
||||
// 檢查並添加 combined_test_results 表的 is_timeout 欄位
|
||||
try {
|
||||
// 先檢查欄位是否已存在
|
||||
const checkColumnQuery = `
|
||||
SELECT COUNT(*) as count
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'combined_test_results'
|
||||
AND COLUMN_NAME = 'is_timeout'
|
||||
`
|
||||
const result = await executeQuery(checkColumnQuery)
|
||||
const columnExists = result[0]?.count > 0
|
||||
|
||||
if (!columnExists) {
|
||||
await executeQuery(`
|
||||
ALTER TABLE combined_test_results
|
||||
ADD COLUMN is_timeout BOOLEAN DEFAULT FALSE
|
||||
`)
|
||||
console.log('✅ combined_test_results 表已添加 is_timeout 欄位')
|
||||
} else {
|
||||
console.log('ℹ️ combined_test_results 表的 is_timeout 欄位已存在,跳過')
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('❌ 檢查/添加 combined_test_results 表 is_timeout 欄位失敗:', error.message)
|
||||
}
|
||||
|
||||
console.log('✅ is_timeout 欄位添加完成')
|
||||
} catch (error) {
|
||||
console.error('❌ 添加 is_timeout 欄位失敗:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 執行遷移
|
||||
if (typeof window === 'undefined') {
|
||||
// 只在伺服器端執行
|
||||
addTimeoutColumns().catch(console.error)
|
||||
}
|
Reference in New Issue
Block a user