Skip to content

fix(db): scope the service-role write policies to service_role - #1336

Merged
gkhngyk merged 1 commit into
mainfrom
fix/service-write-policies
Oct 22, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/service-write-policies

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Only the server (with the service role) writes these tables:

  • prompt_results
  • prompt_result_citations
  • prompt_result_shopping_cards
  • signals
  • ai_traffic_logs
  • citation_urls

Their "Service role can insert / delete …" policies were created without a role. Migration 00235 scopes the ten policies to service_role with alter policy … to service_role. The service role bypasses row security, so the server's writes don't change. Members' reads go through the select policies, which aren't touched.

Every writer in server/ uses supabaseAdmin. In web/, no code inserts into or deletes from these tables. The two SQL functions that do, delete_brand_results_batch and citation_url_ids, are service-role only.

It's applied on the hosted DB. Checked there in rolled-back transactions:

  • an insert into each of the six tables as anon is refused by row security;
  • the service role still bypasses row security.

Related issue

None.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. A tracking run still writes answers, citations and shopping cards.
  2. The nightly signals job still records signals.
  3. AI Traffic still records bot visits.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — web not touched
  • yarn typecheck passes (run from web/) — web not touched
  • yarn format:check passes (run from web/) — web not touched
  • Changes are focused — one concern per PR

schema.sql is rebuilt with build-schema.sh. SQL only.

🤖 Generated with Claude Code

https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A

The insert and delete policies the server's writes were written for on
prompt_results, prompt_result_citations, prompt_result_shopping_cards,
signals, ai_traffic_logs and citation_urls were created without a role.
00235 scopes them to service_role; service_role bypasses row security, so
the server's writes are unchanged. Applied on production.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
@gkhngyk
gkhngyk merged commit 9380c68 into main Oct 22, 2026
5 of 6 checks passed
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant