-- cohort_instructors — scopes the 'instructor' role to specific cohorts. 'owner' and 'admin' -- are never checked against this table (they have global teaching visibility by role alone, -- see src/rbac.js) — this only matters for the plain 'instructor' role. CREATE TABLE IF NOT EXISTS cohort_instructors ( cohort_id TEXT NOT NULL REFERENCES cohorts(cohort_id), instructor_id UUID NOT NULL REFERENCES instructors(instructor_id), role_in_cohort TEXT NOT NULL DEFAULT 'teacher', created_at TIMESTAMPTZ NOT NULL DEFAULT now(), PRIMARY KEY (cohort_id, instructor_id) ); CREATE INDEX IF NOT EXISTS idx_cohort_instructors_instructor ON cohort_instructors(instructor_id);