BE-M0-36 · Each organization's own system rows, phones, master data reads, gate:write
ID BE-M0-36 · Level L0 · Pack Pack G1 · The review's schema changes · Run order row 22b · Issue #150
Every row belongs to an organization: a new organization gets its own copy of the 11 system roles with their grants, the charge types and the lead sources, marked is_system and locked; only the permission catalogue is shared (R-TEN-03, R-ACC-21, R-MD-05). A phone is stored as 62 and the number with no plus (R-CONV-07), and the people's phones start 628 (R-CONV-16). Company bank accounts, contract templates and pricing groups need master_data:read; rental companies need master_data:read or payment:read; brands, models, garages, insurers and the lookups stay open to every member (R-MD-12, R-MD-08, R-MD-01). Recording a gate pass needs gate:write (R-GATE-04).
This step changes no file: the code arrived with pack G1's pull request. It proves the change on your Mac's local stack.
Before
Section titled “Before”- BE-M0-35 is Done, or you run this step on its own after the same block 1.
- You are in ~/opleet-v2/opleet on main and the local stack is running.
1 · Main, rebuilt from nothing
Section titled “1 · Main, rebuilt from nothing”The migration files were edited in place (D11), so the local database is rebuilt, never migrated.
git switch main && git pullpnpm supabase db reset2 · This part's tests
Section titled “2 · This part's tests”pnpm supabase test db supabase/tests/database/14_master_data.test.sql supabase/tests/database/16_drivers.test.sql supabase/tests/database/21_rls.test.sql supabase/tests/database/22_seed_system.test.sqlExpect
Section titled “Expect”- Block 1: "Finished supabase db reset".
- Block 2:
okon every line, thenFiles=4, Tests=136andResult: PASS.
pnpm supabase db query --local "select count(*) filter (where organization_id is null) as shared, count(*) as e2e_roles from public.roles"shared is 0 and e2e_roles is 11: the E2E organization's own copy.
If it fails
Section titled “If it fails”supabase db resetstops on a migration: paste the file name and the error into #150. Don't edit the file.- A test fails: paste the
not okline and the lines under it that start with#. The test's description starts with the rule it proves. - "permission denied" or "must be owner" on auth.sessions: stop and paste it. That means a migration can't end sessions on this stack (D37); BE says so on the issue before changing anything.
Nothing to undo: the step changes no file. pnpm supabase db reset rebuilds the local database from main at any time. Never run any part of it against staging or production.
Log each run as a comment on #150: the date, the last lines of block 2, and the check's output.