Files
ai-showcase-platform/scripts/insert-team-members.sql

51 lines
1.6 KiB
SQL

-- =====================================================
-- 插入團隊成員測試數據
-- =====================================================
-- 首先查看現有的團隊
SELECT '=== 現有團隊 ===' as info;
SELECT id, name, leader_id FROM teams WHERE is_active = 1;
-- 查看現有用戶
SELECT '=== 現有用戶 ===' as info;
SELECT id, name, department FROM users WHERE status = 'active' LIMIT 10;
-- 為每個團隊插入成員數據
-- 團隊 1: aaa (ID: t1757702332911zcl6iafq1)
INSERT IGNORE INTO team_members (id, team_id, user_id, role, joined_at) VALUES
('tm_1_1', 't1757702332911zcl6iafq1', 'db19b491-8f63-44b5-a28a-1f8eeb4fdd3c', '隊長', NOW()),
('tm_1_2', 't1757702332911zcl6iafq1', 'db19b491-8f63-44b5-a28a-1f8eeb4fdd3c', '成員', NOW());
-- 如果有其他團隊,請按照相同格式添加
-- 團隊 2: (如果有的話)
-- INSERT IGNORE INTO team_members (id, team_id, user_id, role, joined_at) VALUES
-- ('tm_2_1', 'team_id_2', 'user_id_2', '隊長', NOW()),
-- ('tm_2_2', 'team_id_2', 'user_id_3', '成員', NOW());
-- 驗證插入結果
SELECT '=== 團隊成員插入結果 ===' as info;
SELECT
tm.id,
tm.team_id,
t.name as team_name,
tm.user_id,
u.name as user_name,
tm.role,
tm.joined_at
FROM team_members tm
LEFT JOIN teams t ON tm.team_id = t.id
LEFT JOIN users u ON tm.user_id = u.id
ORDER BY tm.team_id, tm.role;
-- 檢查團隊成員統計
SELECT '=== 團隊成員統計 ===' as info;
SELECT
t.id,
t.name as team_name,
COUNT(tm.id) as member_count
FROM teams t
LEFT JOIN team_members tm ON t.id = tm.team_id
WHERE t.is_active = 1
GROUP BY t.id, t.name
ORDER BY t.name;