108 lines
2.8 KiB
SQL
108 lines
2.8 KiB
SQL
-- =====================================================
|
||
-- 修復外鍵約束問題的 SQL 腳本
|
||
-- =====================================================
|
||
|
||
-- 問題:app_judge_scores 表的 app_id 外鍵約束失敗
|
||
-- 原因:團隊評分使用的 teamId 不存在於 apps 表中
|
||
|
||
-- 解決方案:為團隊創建對應的虛擬應用記錄
|
||
|
||
-- 1. 先查看現有的團隊數據
|
||
SELECT '=== 現有團隊 ===' as info;
|
||
SELECT id, name, department FROM teams WHERE is_active = TRUE;
|
||
|
||
-- 2. 為團隊 t1757702332911zcl6iafq1 (aaa) 創建虛擬應用
|
||
INSERT IGNORE INTO apps (
|
||
id,
|
||
name,
|
||
description,
|
||
creator_id,
|
||
category,
|
||
type,
|
||
app_url,
|
||
icon,
|
||
icon_color,
|
||
likes_count,
|
||
views_count,
|
||
rating,
|
||
is_active,
|
||
created_at,
|
||
updated_at
|
||
) VALUES (
|
||
'team_t1757702332911zcl6iafq1',
|
||
'[團隊評分] aaa',
|
||
'團隊 aaa 的評分記錄 - 用於存儲團隊評分數據',
|
||
'00000000-0000-0000-0000-000000000000',
|
||
'team_scoring',
|
||
'team',
|
||
NULL,
|
||
'Users',
|
||
'from-gray-500 to-gray-600',
|
||
0,
|
||
0,
|
||
0.00,
|
||
TRUE,
|
||
NOW(),
|
||
NOW()
|
||
);
|
||
|
||
-- 3. 驗證虛擬應用是否創建成功
|
||
SELECT '=== 虛擬應用創建結果 ===' as info;
|
||
SELECT id, name, type, category, is_active FROM apps WHERE id = 'team_t1757702332911zcl6iafq1';
|
||
|
||
-- 4. 現在可以插入團隊評分記錄了
|
||
-- 測試插入團隊評分(使用真實的評審ID)
|
||
INSERT INTO app_judge_scores (
|
||
id,
|
||
judge_id,
|
||
app_id,
|
||
innovation_score,
|
||
technical_score,
|
||
usability_score,
|
||
presentation_score,
|
||
impact_score,
|
||
total_score,
|
||
comments,
|
||
submitted_at
|
||
) VALUES (
|
||
UUID(),
|
||
'fed0a353-8ffe-11f0-bb38-4adff2d0e33e', -- 評審ID
|
||
'team_t1757702332911zcl6iafq1', -- 虛擬應用ID
|
||
8, -- innovation_score
|
||
7, -- technical_score
|
||
9, -- usability_score
|
||
8, -- presentation_score
|
||
7, -- impact_score
|
||
7.8, -- total_score (平均分)
|
||
'測試團隊評分記錄',
|
||
NOW()
|
||
);
|
||
|
||
-- 5. 驗證評分記錄是否插入成功
|
||
SELECT '=== 評分記錄插入結果 ===' as info;
|
||
SELECT
|
||
ajs.id,
|
||
ajs.judge_id,
|
||
ajs.app_id,
|
||
ajs.innovation_score,
|
||
ajs.technical_score,
|
||
ajs.usability_score,
|
||
ajs.presentation_score,
|
||
ajs.impact_score,
|
||
ajs.total_score,
|
||
ajs.comments,
|
||
ajs.submitted_at,
|
||
a.name as app_name
|
||
FROM app_judge_scores ajs
|
||
LEFT JOIN apps a ON ajs.app_id = a.id
|
||
WHERE ajs.app_id = 'team_t1757702332911zcl6iafq1'
|
||
ORDER BY ajs.submitted_at DESC;
|
||
|
||
-- 6. 如果有其他團隊,也需要創建對應的虛擬應用
|
||
-- 格式:team_{teamId}
|
||
-- 例如:team_另一個團隊ID
|
||
|
||
-- 7. 清理測試數據(可選)
|
||
-- DELETE FROM app_judge_scores WHERE app_id = 'team_t1757702332911zcl6iafq1';
|
||
-- DELETE FROM apps WHERE id = 'team_t1757702332911zcl6iafq1';
|