A full-featured CRM built with React, shadcn/ui, and Supabase.
Require explicit grants in deploy-time migrations
fzaninottoa05a4b859505
diff --git a/.claude/agents/quality-reviewer.md b/.claude/agents/quality-reviewer.mdindex 319e7302..b8a3a3d7 100644--- a/.claude/agents/quality-reviewer.md+++ b/.claude/agents/quality-reviewer.md@@ -146,11 +146,16 @@ Migration checklist (BLOCKING):- Idempotent (`IF [NOT] EXISTS`), no destructive change without intent.- Column types/constraints/FKs match the TS types the migration is derived from.- RLS enabled + real policies on every new table (never `USING (true)`).+- Explicit `GRANT`s to `anon`/`authenticated`/`service_role` for every new+ table, view and `serial` sequence, in the migration itself (Supabase no+ longer auto-exposes new `public` objects; a missing grant passes locally+ and fails with 42501 in production).- View-recreation rule respected: `CREATE OR REPLACE VIEW` with the new columnas the LAST item in the SELECT list (after every existing column AND everyexisting computed `AS` alias). `DROP VIEW … CASCADE; CREATE VIEW …` only- for column removal/rename, with dropped dependents re-created in the same- migration. Column order in `03_views.sql` must mirror the deployed view.+ for column removal/rename, with the view's `GRANT`s re-declared right after+ the `CREATE VIEW` and dropped dependents re-created (with their grants) in+ the same migration. Column order in `03_views.sql` must mirror the deployed view.- No data loss on existing tables; reversible where feasible.Files to review are listed in the spawn prompt. Read them in@@ -170,7 +175,7 @@ Detection: your spawn prompt contains `ROLE: quality-reviewer (SIMPLE mode — sgit -C <WORKTREE_PATH> diff "session-base/$SHORT"..HEAD```2. **Apply the scope-relevant rubric only** — SIMPLE diffs are small and schema-focused:- - **A.6b (schema changes)** — no `supabase/migrations/*.sql` in the diff (off-limits to SIMPLE); schema files in `supabase/schemas/*.sql` only; new column appended at the end of the `03_views.sql` SELECT, no ordinal shift.+ - **A.6b (schema changes)** — no `supabase/migrations/*.sql` in the diff (off-limits to SIMPLE); schema files in `supabase/schemas/*.sql` only; new column appended at the end of the `03_views.sql` SELECT, no ordinal shift; every new table, view and `serial` sequence declared in `06_grants.sql` (no default privileges, so a missing grant means `permission denied`).- **B.1 (RLS)** — RLS enabled, policies cover required ops, no `USING (true)`.- **B.3 (injection)** — no string-concatenated SQL, no `||` of user input.- **A.6 (backend patterns)** — input validation, no unbounded queries.diff --git a/.claude/skills/writing-migrations/SKILL.md b/.claude/skills/writing-migrations/SKILL.mdindex 80bf8e44..d444085e 100644--- a/.claude/skills/writing-migrations/SKILL.md+++ b/.claude/skills/writing-migrations/SKILL.md@@ -100,8 +100,15 @@ Write to `supabase/migrations/<YYYYMMDDHHMMSS>_<SESSION_SHORT_ID>_migration_<slucorrect column types matching the TS types, FKs, and RLS for new tables (RLSenabled + policies, never `USING (true)`).+Every new table, view and `serial` sequence needs explicit `GRANT`s to `anon`,+`authenticated` and `service_role` in the same migration, mirroring the+declarations in `supabase/schemas/06_grants.sql`. Supabase no longer exposes new+`public` objects to the Data API automatically, and the schema declares no+default privileges: without the grants the object answers `permission denied`+(42501) on a fresh or post-2026-10-30 project, even if it works locally.+**Checkpoint:** re-running the migration on an already-migrated database is a-no-op (every statement is guarded), and every new table has RLS enabled with at least one non-`USING (true)` policy.+no-op (every statement is guarded), every new table has RLS enabled with at least one non-`USING (true)` policy, and every new table, view and `serial` sequence has its `GRANT`s in the migration and in `06_grants.sql`.### 5. View-recreation rule (BLOCKING correctness)@@ -118,12 +125,13 @@ exceptions. The mechanical rule is: positions 1..N of the new view must beidentical to positions 1..N of the old view; the new column is position N+1.Why not `DROP VIEW … CASCADE; CREATE VIEW …`? It silently drops dependent-views/materialized views/rules, loses any explicit `REVOKE`s on the view-(re-granted by default privileges at the next deploy without warning), and-reads as a destructive operation in audit. Reserve it for cases `CREATE OR-REPLACE` genuinely can't handle (column **removal** or **rename**). If you-use it, enumerate dropped dependents in a SQL comment and re-create them in-the same migration.+views/materialized views/rules, drops every grant on the view (nothing+re-grants it: the rebuilt view answers `permission denied`), and reads as a+destructive operation in audit. Reserve it for cases `CREATE OR REPLACE`+genuinely can't handle (column **removal** or **rename**). If you use it,+re-declare the view's `GRANT`s (from `06_grants.sql`) right after the+`CREATE VIEW`, enumerate dropped dependents in a SQL comment and re-create them+(with their grants) in the same migration.PostgREST queries the view, not the table — a missing update makes thecolumn invisible to the app. The view's column order doesn't matter to API