Chapter 1 · Session 8
Rules inside the database, generated from the matrix
Your tables have had row-level security on with no policies since Session 5: closed to everyone. This session opens exactly what the matrix allows and nothing more, with rules the database itself enforces, written by a generator rather than by hand, and tests that prove every cell.
35 min1 stepOne prompt: generator, migration, tests, check
By the end of this chapter you can
- Say what a row-level security policy does, and what a refusal looks like.
- Name the logins that skip the rules, and why the app's own login must not.
- Have Claude Code write the generator, the migration it produces, the access tests and the CI check in one pull request.
The lock that holds whatever sends the query
Postgres, the database inside Supabase, can carry row-level security: policies on each table that decide, for each row and each person, whether that row can be seen, added or changed [1]. Supabase passes each signed-in person's identity to the database, so a policy can ask who is asking [2]. Because the rule runs inside the database, it holds for your screens, a script someone writes next year, the plant connector and every AI agent.
A policy has two halves [3]. USING decides which existing rows a command can see or touch; rows that fail it are simply invisible. WITH CHECK decides which new or changed rows are allowed; a row that fails it is refused with an error.
What a refusal looks like
Row-level security usually says no quietly. A read outside your rows returns nothing, with no error. An update aimed at a row you cannot see changes nothing, with no error. Only a write that fails WITH CHECK, or an action nobody was granted at all, raises error 42501 [1]. That is why every test in this session counts rows: "no error" proves nothing.
Who skips the rules
Some logins are not bound by row-level security. A table's owner skips it unless the table is set to force row-level security; roles with the BYPASSRLS attribute skip it always [1]. In Supabase the service role (the secret key) bypasses every policy, and Supabase says it must never reach a browser [4]. We hit this: every rule passed in the database editor, yet the app showed data it should not, because the app connected with a login that skipped the rules (edge case 7.4).
| Key or secret | What it unlocks | Where it lives | Who holds it | Never |
|---|---|---|---|---|
| Publishable key (anon) | Visitors and signed-in people, through the browser. Bound by every policy | Vercel, put there by the integration (Session 1); it is meant to be public | The integration | Mistaken for protection: the rules, not the key, protect the data |
| Secret key (service role) | Everything, skipping every policy | Vercel server settings only, put there by the integration | The integration; owners can rotate it | In a browser, a prompt, Claude Code, a file, an agent or the connector |
| Development database password | The whole development project, as its owner | Password manager: Supabase: acme-platform-dev database password | Both owners | In Claude Code, a file or a chat |
| Production database password | The whole live database, as its owner | Password manager: Supabase: acme-platform-prod database password | Both owners, typed only for supabase link | In Claude Code, a file or a chat |
What the generator writes
Every policy asks the same question: does the signed-in person hold this role at this row's site? The generator writes that once, as a helper the policies call. It runs with its owner's rights so it can read memberships, which ordinary users cannot, and it answers only yes or no about the person asking. Its search path is fixed to nothing, so every name is written in full and nothing can be substituted, as Postgres recommends for such functions [5].
-- Generated from docs/matrix.json by scripts/gen-policies.mjs. Do not edit by hand.
create or replace function private.has_role(want text, row_site bigint)
returns boolean language sql stable
security definer set search_path = ''
as $$
select exists (
select 1 from public.memberships m
where m.user_id = (select auth.uid())
and m.role = want and m.site_id = row_site);
$$;
alter table public.holds enable row level security;
alter table public.holds force row level security;
revoke all on public.holds from anon, authenticated;
grant select, insert on public.holds to authenticated;
create policy matrix_holds_operator_read on public.holds
for select to authenticated
using (private.has_role('operator', site_id));
create policy matrix_holds_quality_lead_insert on public.holds
for insert to authenticated
with check (private.has_role('quality_lead', site_id)
and decided_by = (select auth.uid()));Read the last policy aloud: a signed-in person may record a hold only if they are a quality lead at that lot's site, and only in their own name. (select auth.uid()) is the signed-in person; wrapping it in a select lets Postgres work it out once per query instead of once per row, as Supabase recommends [2].
The access testing protocol
These tests run on every pull request, on a database built from nothing, with two made-up sites. Each one is here because of something we hit:
| Test | What it proves | Why it is here |
|---|---|---|
| Every cell, both ways | Each right a role has works at its own site; each right it lacks is refused | A rule nobody tests is a rule an agent can quietly remove later |
| Cross-site, every table | A person at site A reads, inserts, updates and deletes nothing at site B | On our platform, any signed-in user could open another company's batch by changing the number in the address. The fix had to be added lookup by lookup (edge case 7.1) |
| Signed in is not allowed | A signed-in person with no membership sees and writes nothing; visitors who are not signed in get nothing | An operator account could delete a whole site, because the only check was "is someone signed in" (edge case 7.2) |
| Update really changed | Every allowed update is read back to prove the row changed | In Postgres an update only finds rows you can read; without the read right a Save reports success and nothing changes (edge case 7.3) |
| Forced, and no bypass | Every table has row-level security enabled and forced; the app's logins (anon, authenticated) cannot bypass it | Every rule passed in the editor while the app, connected with a login that skipped them, leaked data (edge case 7.4) |
| No hand-written policy | Every policy's name starts with matrix_; delete is granted only where the matrix says | A policy added in the dashboard is a rule nobody reviewed, outside the files that rebuild the database |
| Generated output is current | The newest generated migration matches what the matrix generates today | A matrix change without regenerating would leave the database on yesterday's rules |
One prompt: the generator, the migration, the tests and the check
20 minutesWhy
Writing the generator, the migration it produces, the tests that prove it and the check that it is current in one pull request means the access rules never exist without their proof, and nobody can hand-edit a rule without CI noticing. One complete prompt also replaces the dozen rounds it takes to add each test as you think of it.
Do this
cd ~/code/acme-platform && git switch main && git pull && claudeRead docs/matrix.json (signed off), scripts/check-matrix.mjs, every file in supabase/migrations and supabase/tests, and Supabase's guide to row-level security. Do not connect to or change any Supabase project.
On a new branch access/rls:
1. Write scripts/gen-policies.mjs (Node, no new dependencies). It runs scripts/check-matrix.mjs first and stops if that fails. Then it writes a NEW migration, supabase/migrations/<UTC timestamp>_policies_from_matrix.sql, that starts with the comment "Generated from docs/matrix.json by scripts/gen-policies.mjs. Do not edit by hand." It never edits an existing migration. The migration:
- creates a schema private that the API does not expose, and one helper, private.has_role(want text, row_site bigint) returns boolean, language sql, stable, security definer, set search_path = '', true when the signed-in person, (select auth.uid()), has that role at that site in public.memberships; execute granted to authenticated only;
- for every table in the matrix: enable row level security and force row level security; drop every existing policy on it whose name starts with matrix_; revoke all privileges from anon and authenticated; grant to authenticated only the privileges some role has on it in the matrix;
- one policy per role and right, named matrix_<table>_<role>_<right>, for authenticated, limited to the row's site (for the sites table, its id):
read: for select using has_role;
insert: for insert with check has_role and, when the table has a "by" column, that column = (select auth.uid());
update: for update using and with check has_role;
delete: for delete using has_role;
- nothing at all for a role missing from a table: no policy is the refusal.
The same matrix must always give the same file contents (sorted, no dates inside the file), so it can be compared.
With --check it writes nothing, and fails if the newest *_policies_from_matrix.sql differs from what it would generate now, saying "run node scripts/gen-policies.mjs".
2. Have the same script write supabase/tests/access.test.sql (pgTAP, inside begin and rollback). As the database owner, create the fixture: two made-up sites with codes zz-a and zz-b (never the real site cle), one user per role at zz-a, one signed-in user with no membership, and at least one row in every table at each site. Then act as each user (set local role authenticated, and request.jwt.claims with their id) and test every cell of the matrix:
- each right the role has: allowed at zz-a (a read returns rows; an insert succeeds; an update really changes the row, proven by reading it back as the owner) and refused at zz-b (a read returns zero rows; an insert fails with 42501; an update or delete changes zero rows);
- each right the role does not have: refused at zz-a (zero rows, or error 42501).
Also test: the user with no membership reads zero rows from every table and cannot insert into any; anon is refused on every table; every public table has row level security enabled and forced; the roles anon and authenticated do not have BYPASSRLS; every policy on a public table is named matrix_...; authenticated has delete only where the matrix grants it.
Count rows: a refused read returns zero rows without an error, so "no error" never passes a test.
3. Add a step to .github/workflows/ci.yml that runs node scripts/gen-policies.mjs --check. The schema workflow from Session 5 already runs supabase test db on a fresh database, so access.test.sql runs there with the seed.
4. Run the generator once, so the branch has the migration and the tests.
Push, open a pull request titled "Access rules from the matrix", wait for every check to finish, and tell me in plain words: how many policies were generated, how many access tests ran, and how many prove a refusal. If a check fails, fix the cause and wait again before reporting. Never loosen a test or a check, never remove force row level security, and never edit the generated files by hand.You will see recreated screen
- One new migration with a time in its name, and the tests, both written by the generator from the matrix.
- Both ways: rows at your own site, zero at the other. A count, not "no error".
- Counts you can compare with the matrix: one policy per right granted. Far more refusals than permissions is what least privilege looks like.
Check it worked
Pull request Access rules from the matrix is green on GitHub. Its Files changed tab shows scripts/gen-policies.mjs, one new migration ending _policies_from_matrix.sql, supabase/tests/access.test.sql and one new step in ci.yml, and no change to any older migration or to docs/matrix.json.
Fastest path
"Wait for every check and fix the cause before reporting" means Claude Code reads the failure and fixes it while you do something else. The database tests take a few minutes; that is the time to read Chapter 2.
If it goes wrong
Every allowed test fails too: even the quality lead reads zero holds
The helper cannot read memberships, so it answers no for everyone. Say: Every allowed test fails. Show me which role owns private.has_role, whether that role is bound by the policies on memberships now that it is forced, and fix the helper so it can read memberships. Do not remove force row level security.
The seed or the fixture fails with "new row violates row-level security policy"
Something that ran as the owner is now bound by the forced rules. Say: Show me which login ran the failing statement, and whether it has BYPASSRLS. Explain the options before changing anything; do not remove force row level security. Then decide with owner two.
Claude Code made the tests pass by weakening them (a refused test that now expects rows, or a test removed)
Say: Undo that. Never change a test to get to green. Tell me which cell failed and why, and I will decide. We had an agent go round a check it was refused; read the Files changed tab before the summary.
It reports success but a check on GitHub is red
Say: A check on pull request #20 is red. Run gh pr checks, read the failed log, fix the cause and wait for green before you report. We once saw a run print "npm: not found" and, ten minutes later, the same job reported 1,326 tests passing. The check on GitHub is the evidence.
Claude Code edited an existing migration, or the tables from Session 5
Say: Revert every change to existing migrations. The generator only adds a new file. Applied migrations are history (Session 5).
Claude Code tries to run supabase db push or link a project
The deny rule from Session 1 stops it. Say: Do not touch any Supabase project. I apply migrations myself after merge.
Knowledge check
A test signs in as the site A operator, reads site B's results, and checks only that no error occurred. Is it a good test?
Knowledge check
Which login skips every row-level security policy in Supabase?
References
- PostgreSQL Documentation: Row Security Policies. https://www.postgresql.org/docs/current/ddl-rowsecurity.html
- Supabase Docs: Row Level Security. https://supabase.com/docs/guides/database/postgres/row-level-security
- PostgreSQL Documentation: CREATE POLICY. https://www.postgresql.org/docs/current/sql-createpolicy.html
- Supabase Docs: Understanding API keys. https://supabase.com/docs/guides/api/api-keys
- PostgreSQL Documentation: CREATE FUNCTION (writing SECURITY DEFINER functions safely). https://www.postgresql.org/docs/current/sql-createfunction.html
Chapter 2 · Session 8
Read it, then watch it fail on purpose
You do not need to read SQL to review access rules. Claude Code checks the generated migration and tests against the matrix and answers nine questions with the line that proves each. Then you plant two mistakes and watch the tests catch them, before anything reaches a database people use.
30 min2 stepsShow it red first
By the end of this chapter you can
- Review the generated rules against the matrix through nine yes-or-no questions.
- Know which logins skip the rules and confirm no app code uses them.
- See the access tests and the generated-output check fail on planted mistakes.
Proof, not a summary
Supabase runs database tests written with pgTAP through its command line tool, on a database built from your migrations [1] [2]. Session 5 made that run on every pull request; this session's tests join it. A test acts as a person by setting the database role to authenticated and their id in the request settings, exactly as Supabase does for a real signed-in request, inside a transaction that is rolled back so it leaves nothing behind [1].
Read the rules through Claude Code's eyes
15 minutesWhy
The generated migration is long, and you do not need to read it line by line. You need to know that it does what the matrix says and nothing more, that nothing skips it, and that the tests cover the problems we hit. Nine fixed questions with line numbers turn a page of SQL into answers you can check in the Files changed tab.
Do this
Explain pull request "Access rules from the matrix" to me in plain English, as if to the quality lead: what each role can now do, table by table, compared with docs/matrix.json. Then answer each question with Yes or No and the file and line that show it:
1. Does every table in the matrix get enable and force row level security?
2. Is there exactly one policy per right granted in the matrix, and none where a role is missing? Give both counts.
3. Does every policy limit rows to the row's site through private.has_role?
4. Does every insert on a table with a "by" column require that column to be the signed-in person?
5. Is delete granted only where the matrix grants it?
6. Is the helper security definer with search_path '', in a schema the API does not expose, executable only by authenticated?
7. Does the migration change anything the matrix does not mention (other tables, functions, grants to other roles)?
8. Do the tests cover: every cell both ways, the other site for every table, a signed-in person with no role, visitors not signed in, updates read back, forced security, no BYPASSRLS for anon and authenticated, and no policy outside matrix_?
9. Which logins on our Supabase projects skip these rules, and does any code in app/, lib/ or scripts/ use one of them? Search for the service role key's variable name and list every use.
Do not change anything. If any answer is No, say what you would change and wait.You will see recreated screen
- Counts you can compare with the matrix yourself: rights granted and policies must match.
- The answer for edge case 7.4: the app's own login cannot skip the rules. If any code uses the service role key, stop and ask why before merging.
Check it worked
All nine answers are Yes (question 7: nothing outside the matrix), the policy count equals the rights granted in docs/matrix.json, and no app code uses the service role key.
If it goes wrong
Question 9 finds the service role key in app code
Stop. That code reads past every rule, so the tests in this session do not protect it. Ask: For each use of the service role key, what does it do, and can it use the signed-in person's session instead? If it must stay, it moves to reviewed server code only, with its own check that the person may do this; Session 9 adds the route checks.
The counts do not match (more policies than filled cells)
Ask: List every policy that does not come from a right in docs/matrix.json, and where it came from. A policy from somewhere else is a hand-written rule; it goes, or it becomes a cell in the matrix through Session 7's review.
Claude Code groups the refusals as "all fine" without detail
Ask for one example per group: Show me one cross-site test and one no-role test exactly as written, and what each counts. Tests that check a word is present rather than what the database returns have passed while the feature was broken.
Plant two mistakes and watch the tests catch them
15 minutesWhy
A test that has never failed may be unable to fail. We had checks green for weeks while the thing they guarded was broken. Planting the two mistakes this session exists to stop, a rule that ignores the site and a hand-granted delete, and seeing the checks go red on GitHub, proves the tests guard what you think they guard.
Do this
Prove the access tests work, without merging anything. On a new branch access/prove-tests, starting from the branch of pull request "Access rules from the matrix", edit the generated migration by hand to make two deliberate mistakes:
1. change the operator's read policy on holds to using (true), so it ignores the site;
2. add: grant delete on public.inspections to authenticated;
Push, open a draft pull request titled "DO NOT MERGE: the access tests must fail", wait for every check, and show me the exact failing test names and messages. Then close that pull request without merging and delete the branch.Then owner two reads pull request Access rules from the matrix (Files changed first, then the summary), approves it, and you merge it.
https://github.com/acme-ops/acme-platform/pulls
Owner two opens Access rules from the matrix, reads Files changed, and approves; then merge.
You will see recreated screen
gen-policies --check: the newest policies migration differs from docs/matrix.json. Run node scripts/gen-policies.mjs. Never edit it by hand. not ok 37 - operator reads no holds at the other site # have: 3 want: 0 not ok 205 - authenticated has delete only where the matrix grants it # inspections: delete granted, matrix grants none
- Both workflows red: the hand edit is caught as hand-written, and each mistake is caught by the test written for it.
- Closed, never merged.
Check it worked
You saw the draft pull request fail with the cross-site test and the delete test named, and the generated-output check refusing the hand edit; it is closed unmerged. Access rules from the matrix is merged on main with green checks.
If it goes wrong
The schema check is green on the draft
The access tests did not catch the planted mistakes, so they are not protecting you. Say: The planted mistakes passed. Find why each was not caught, add or fix the test for each in the generator, push to the access/rls branch, and plant them again. Do not merge until they go red.
Only the generated-output check is red
That proves hand edits are caught, but not that the tests themselves work. Ask: Did the database tests run on the draft? Show me their result for the two planted mistakes. If they did not run, find out why before merging.
The red check is for a different commit
Ask: Which commit did each check run on? Is it the draft's latest? A verdict about an old commit says nothing about this one.
Knowledge check
A new rule appears in the access migration that no cell in the matrix produces. What do you do?
Knowledge check
Why edit the generated migration by hand in the planted-mistakes branch?
References
- Supabase Docs: Testing your database (pgTAP and supabase test db). https://supabase.com/docs/guides/database/testing
- pgTAP: unit testing for PostgreSQL. https://pgtap.org/
- PostgreSQL Documentation: Privileges. https://www.postgresql.org/docs/current/ddl-priv.html
Chapter 3 · Session 8
Apply it: development first, then production
A person, not an agent, applies the merged migration: to the development project first, where only made-up data can be affected, then to production. Supabase's own Security Advisor checks each. Last, you change one cell the only way access ever changes: in the matrix, regenerated.
40 min4 stepsEnds with a gate
By the end of this chapter you can
- Apply the access migration to the development project, then production, typing each password yourself.
- Check each project with one SQL query and the Security Advisor.
- Change one cell: the matrix, a new generated migration, the same checks.
Apply it to the development project
10 minutesWhy
Access rules change who can see what in every screen. Applying them to the development project first, where every row is made up, shows you the real effect on a real Supabase project before the plant's records are involved. Doing it yourself after merge keeps the rule from Session 5: the live databases always match main, and no agent changes them.
Do this
In a terminal, not inside Claude Code:
cd ~/code/acme-platform && git switch main && git pullnpx supabase link --project-ref tsrqponmlkjihgfedcbaIt asks for the database password: copy it from the password manager entry Supabase: acme-platform-dev database password. Nothing shows as you paste; press Enter. Then see what will be applied, and apply it:
npx supabase migration listnpx supabase db pushYou will see recreated screen
- The reference must be the development project's, tsrqponmlkjihgfedcba. If it is abcdefghijklmnopqrst, stop: that is production.
- Only the access rules are new. If older files show only under Local, earlier sessions were never applied here: apply them in order (this push does).
Check it worked
Run npx supabase migration list again: every file has the same time under Local and Remote.
If it goes wrong
You are not sure which project is linked
Run npx supabase projects list: the linked project is marked. If it is acme-platform-prod, link to tsrqponmlkjihgfedcba again before pushing anything.
Remote migration versions not found in local migrations directory
Someone changed this project outside the files. Do not force anything. In Claude Code: supabase db push says remote migration versions are not in the local directory. Explain in plain words which versions differ and what each did, without changing any project. Then decide with owner two.
password authentication failed
Copy the development project's password again (not production's) from the password manager, with no spaces at either end. If it still fails, reset it in that project's database settings and save the new one in the password manager.
Screens on the development preview now show nothing
Expected: visitors who are not signed in get nothing, and sign-in comes in Session 9. The access tests, not the screens, are the proof this session.
Check it in the development project
10 minutesWhy
The tests proved the rules on a fresh database in CI. Checking the real project proves it got the same thing: every table forced, the number of rules you expect, and Supabase's Security Advisor, an independent check, finding no table open and no function that could be hijacked. Two checks that agree are worth more than one.
Do this
https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/sql/new
Open a new query in the development project, paste the text below, and press Run.
-- Every public table: row-level security on and forced, and its number of rules.
select c.relname as table_name,
c.relrowsecurity as rls_on,
c.relforcerowsecurity as forced,
(select count(*) from pg_policies p
where p.schemaname = 'public' and p.tablename = c.relname) as rules
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind = 'r'
order by 1;https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/advisors/security
The Security Advisor for the development project: choose Rerun linter.
You will see recreated screen
| table_name | rls_on | forced | rules |
|---|---|---|---|
| characteristics | true | true | 9 |
| equipment | true | true | 7 |
| holds | true | true | 6 |
| inspections | true | true | 11 |
| lots | true | true | 10 |
| memberships | true | true | 4 |
| parts | true | true | 9 |
| sites | true | true | 8 |
- Every row true and true. The rules add up to the policy count Claude Code reported (64 here).
You will see recreated screen
- An error here (RLS disabled, security definer view, function search path) means stop and fix before production.
- If a table still shows it, the matrix gives that table to nobody. That is allowed, but ask whether it is intended.
Check it worked
Every row is true, true; the rules add up to the policy count from Step 1; the Security Advisor shows no errors.
If it goes wrong
A table shows forced = false or rls_on = false
It is not in the matrix, or it was created outside the migrations. Ask Claude Code: Table
The Advisor shows a policy or table that no migration created
Someone clicked it into the dashboard. The no-hand-written-policy test only sees databases built from the files, so it cannot see this. Ask Claude Code for a new migration that removes it (or, if it is needed, a matrix change that generates it), and remove it from the project only through that migration.
The Advisor warns: Function Search Path Mutable for has_role
The helper was written without a fixed search path. In Claude Code: Fix the generator so private.has_role has set search_path = '', regenerate as a new migration, and add a test for it.
Apply it to production, and check it the same way
10 minutesWhy
Production holds the plant's records. Applying the same reviewed file that development already accepted, the same way, means there is nothing new to discover here. Checking production with the same query and the Advisor confirms it, and checking the migration list afterwards stops production quietly falling behind main.
Do this
npx supabase link --project-ref abcdefghijklmnopqrstThis time the password is production's: Supabase: acme-platform-prod database password.
npx supabase migration listnpx supabase db pushhttps://supabase.com/dashboard/project/abcdefghijklmnopqrst/sql/new
Run the same query as in Step 5, in production.
https://supabase.com/dashboard/project/abcdefghijklmnopqrst/advisors/security
The Security Advisor for production: choose Rerun linter.
You will see recreated screen
- Production's reference, abcdefghijklmnopqrst, typed from the course, not remembered.
- The same single file as development. Anything else in the list: answer n and find out why.
Check it worked
Production's migration list matches main, the query shows every table on and forced with the same rule counts as development, and the Security Advisor shows no errors.
Fastest path
Do Steps 4 to 6 in one sitting, straight after the merge. A migration merged but not applied is how production drifts behind main.
If it goes wrong
A page fails on the live site with "permission denied" or shows nothing after this push
Expected until Session 9 adds sign-in: visitors get nothing. If a page that should be public breaks, it was reading plant data without a signed-in person, which is what this session closes on purpose. Note it for Session 9.
Production's list shows older migrations under Local only
Production was already behind main. We once found ours nine migrations behind, the oldest seven weeks old. Push applies them in order; read the list before answering y, and ask Claude Code what each one does if you do not recognise it. Session 11 makes the deploy apply migrations and adds a daily check.
You want to go back to development work after this
The command line tool is now linked to production. Before any later supabase command meant for development, run npx supabase link --project-ref tsrqponmlkjihgfedcba again.
Change one cell the only way access ever changes
10 minutesWhy
Access will change: a new job, a new need. Doing one small change now, the right way, sets the habit before there is pressure to click something in the dashboard. It also shows the whole safety net at once: the matrix check, a new generated migration, new tests both ways, the old tests still passing, and a history that answers who changed access, when and why.
Do this
The quality lead agreed: maintenance may read holds, so they know which press's lot is held before they work on it.
On a new branch access/maintenance-reads-holds: change that one cell in docs/matrix.json and set "checked_with" to "quality lead, <today's date>". Then run node scripts/gen-policies.mjs. It must write a NEW migration; do not edit any existing migration or any generated file by hand. Push, open a pull request titled "Maintenance may read holds", wait for every check, and tell me: which files changed, what the new migration adds compared with the last one, and which new tests prove the change both ways.Review it with the nine questions (Step 2), have owner two approve, merge, then apply it to development and production as in Steps 4 to 6.
You will see recreated screen
- The only line a person changed.
- A new file with a later time. The first access migration is untouched.
- The refusal test became an allowed test and a cross-site test: the proof changed with the rule.
Check it worked
npx supabase migration list, linked to each project in turn, shows both access migrations under Local and Remote, and the history of docs/matrix.json on GitHub shows who changed the cell, when, and the pull request that explains why.
If it goes wrong
Claude Code edited the earlier access migration instead
Say: Revert the change to the applied migration and run the generator so it writes a new file. The first file is already applied to both projects; editing it changes nothing there and makes a fresh database differ from them.
Someone asks you to just add the policy in the dashboard because it is urgent
The proper change takes about ten minutes of your time plus the checks. A dashboard policy is not in the files, not tested, and would be reported by the no-hand-written-policy test only on a fresh database. Make the matrix change; that is the fast path that does not come back.
Two access branches each generated a migration and CI fails after merging both
The newer branch's migration was generated from an older matrix. Say: Merge main into this branch, delete this branch's generated migration (it was never applied), run node scripts/gen-policies.mjs again, and push. Only for a migration that has not been applied to any project.
Knowledge check
In which order are the access rules applied?
Knowledge check
Maintenance now needs to read holds. What goes into the pull request?
References
- Supabase CLI reference: supabase db push. https://supabase.com/docs/reference/cli/supabase-db-push
- Supabase Docs: Database advisors. https://supabase.com/docs/guides/database/database-advisors
- Supabase Docs: Database migrations. https://supabase.com/docs/guides/deployment/database-migrations
Chapter 4 · 12 questions · 80% passes
Final assessment
Twelve questions across the element. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.
15 min12 questions≈ 15 minutesRetake allowed
Your result
CivOps AI Academy
Access Rules from the Matrix: Row-Level Security on Every Table, Proven by Tests
Element F07 complete · Learner
Your LMS records this completion. For the CivOps Foundation certificate, finish the Foundation Course at https://civops.io/learn.