Skip to content

fix(db): grant the seven tables migration 305 created - #558

Merged
thinkclay merged 1 commit into
mainfrom
claude/eeo-grants
Aug 11, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/eeo-grants

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Found while starting #535. That work is blocked on this, so this is the first step rather than the whole ticket.

Seven tables have been unreachable since they were created

Migration 305 created them with RLS enabled and zero GRANT statements. A missing GRANT fails before RLS is evaluated, so every access — including service_role — returns permission denied for table ....

Verified live via PostgREST, with core.application_activity as a 200 control:

core.privacy_data_requests      403
core.privacy_opt_outs           403
core.eeo_self_identification    403
core.eeo_reports                403
core.hiring_projects            403
core.hiring_project_roles       403
core.hiring_project_crew        403

Same class as 332_api_keys_grants and 335_scheduling_grants — the third time this has shipped, which points at how migrations get reviewed rather than at any one migration.

The deliberate asymmetry on EEO data

305's policy on eeo_self_identification is auth.uid() = user_id for SELECT and INSERT — an applicant may record and read their own protected-class data and nobody else's. That's the correct privacy posture and this migration does not widen it. Employers must never read individual rows; only aggregates computed server-side under service_role.

authenticated gets SELECT + INSERT and deliberately no UPDATE/DELETE: a voluntary self-identification is an audit record, not an editable field.

Not executed locally

The Docker CLI is unresponsive on this machine (docker version returns nothing), so I couldn't run DDL. The SQL mirrors 335 exactly, and the api-tests job starts Supabase and applies migrations — so CI executes it. I'd rather say that than imply I ran it.

Why #535 is bigger than filed

See the issue comment: beyond grants, nothing collects EEO data — no UI, no endpoint, only the generated types reference the table. Wiring the report to "real data" today would produce an all-zero report, which on a compliance screen reads as "no adverse impact" when it means "no data". That distinction needs a product decision.

🤖 Generated with Claude Code

Migration 305 created seven tables with RLS enabled and zero GRANT statements.
A missing GRANT fails before RLS is evaluated, so every access — including
service_role — returns "permission denied for table ...". All seven have been
unreachable since they were created:

  core.privacy_data_requests      403
  core.privacy_opt_outs           403
  core.eeo_self_identification    403
  core.eeo_reports                403
  core.hiring_projects            403
  core.hiring_project_roles       403
  core.hiring_project_crew        403

Verified live against the local database via PostgREST, alongside
core.application_activity returning 200 as a control.

Same class of bug as 332_api_keys_grants and 335_scheduling_grants — the third
time it has shipped, which suggests the gap is in how migrations are reviewed
rather than in any one migration.

Found while starting #535 (wire the EEO report to real data). That work is
blocked on this: the table holding the data cannot be read by anything.

## The deliberate asymmetry on EEO data

305's policy on eeo_self_identification is `auth.uid() = user_id` for SELECT and
INSERT — an applicant may record and read their own protected-class data and
nobody else's. That is the correct privacy posture and this migration does not
widen it. Employers must never read individual rows; only aggregates computed
server-side under service_role. authenticated gets SELECT + INSERT and no
UPDATE or DELETE, because a voluntary self-identification is an audit record
rather than an editable field.

Not executed locally: the Docker CLI is unresponsive on this machine, so DDL
cannot be run. The SQL mirrors 335 exactly, and the api-tests job starts
Supabase and applies migrations, so CI executes it.
@thinkclay

Copy link
Copy Markdown
Contributor Author

Correcting the PR description. I wrote that "the api-tests job starts Supabase and applies migrations, so CI executes it." That is wrong for this PR: api-tests.yml only triggers on packages/supabase/functions/api/**, not on packages/supabase/migrations/**. A migration-only change runs Unit tests and Lint/typecheck/build and nothing that touches a database.

So this migration is executed nowhere yet — not locally (the Docker CLI is hung on my machine), and not in CI.

What I did instead was verify the problem in the deployed environments, read-only via the Management API:

                              service_role has SELECT?
core.eeo_self_identification   prod: false   dev: false
core.eeo_reports               prod: false   dev: false
core.hiring_projects           prod: false   dev: false
core.privacy_opt_outs          prod: false   dev: false

So the gap is real in prod and dev, not a local artefact — which is stronger evidence than the local 403s I started from.

Merging this does not apply it; migrations go out separately via scripts/apply-migration.sh. That separation is why merging is still safe — but it does mean the first execution will be whenever you apply it, so it is worth applying to dev first and re-running the query above to confirm the flags flip to true.

Worth noting separately: a migration-only PR gets no database CI at all. That is how three grant-gap migrations (305, and the ones 332/335 fixed) shipped unnoticed. Adding packages/supabase/migrations/** to the api-tests trigger would have caught all three.

@thinkclay
thinkclay merged commit b4e5b8e into main Aug 11, 2026
6 of 7 checks passed
@thinkclay
thinkclay deleted the claude/eeo-grants branch August 11, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant