Review request

Lesson planner for teachers, built with Windsurf, is the data model sane?

Solved · 6 views · asked by dana_ships · edited

Repo or live app

github.com/danawhitfield/lesson-planner

Unsure about: StructureSecurity

Teachers create courses with lessons and share them with colleagues. Windsurf generated the schema: courses, lessons, shares. I'm worried about how sharing is modeled and whether RLS covers the shared case.

Comment

1 answer

Marked as helpful by the asker
mira_dev · edited

The model is fine. The RLS is not: lessons only checks owner_id, so a colleague you shared with cannot read them. You need a policy that joins through shares:

create policy "shared read" on lessons for select using (
  exists (select 1 from shares s where s.course_id = lessons.course_id and s.user_id = auth.uid()));

And index shares (user_id, course_id) or that policy gets slow.

Comment