Supabase database query patterns, RLS policies, migration records, and nested join patterns. Use this skill when writing database queries, understanding RLS behavior, debugging query errors, or implementing new migrations.
Supabase 資料庫查詢模式、RLS 政策、Migration 記錄 Last Updated: 2026-01-02
相關 Skill: kcis-school-config - 學校專屬設定
# Staging Database (kqvpcoolgyhjqleekmee)
# Used by: lms-staging.zeabur.app
psql "postgresql://postgres.kqvpcoolgyhjqleekmee:[email protected]:6543/postgres"
# Production Database (piwbooidofbaqklhijup)
# Used by: lms.kcislk.ntpc.edu.tw (future)
psql "postgresql://postgres.piwbooidofbaqklhijup:[email protected]:6543/postgres"
Supabase 的 table!inner 語法是透過 外鍵(FK) 連接,不是透過查詢中選取的欄位。
scores → exam_id (FK) → exams → course_id (FK) → courses → class_id (FK) → classes
注意:exams 表沒有 class_id 欄位(Migration 035 已移除),只有 course_id。
const { data } = await supabase
.from('scores')
.select(`
student_id,
assessment_code,
score,
exam:exams!inner(
course_id, // ← 取得 FK 欄位
course:courses!inner(
id,
class_id, // ← 從 course 取得 class_id
course_type
)
)
`)
.in('student_id', studentIds) // ← 限制查詢範圍
.not('score', 'is', null);
// 過濾時使用 exam.course.class_id
const filtered = data.filter(s => {
const examData = s.exam as { course_id: string; course: { class_id: string; ... } };
return classIdSet.has(examData.course.class_id); // 正確
});