feat(supabase): foundation migrations (audit, profiles, platform roles) + pgTAP suite
- schemas private/audit, set_updated_at, append-only audit.audit_logs, private.log_event - profiles created by auth.users trigger; own-row RLS; column-level UPDATE grant - platform_role enum (owner/admin/moderator/support), profile_roles history table, is_platform_* helpers, grant/revoke RPCs audited; writes only via RPC - config.toml (public schema only, strong passwords, no edge runtime), local seed - 79 pgTAP checks: allowed and denied paths for every policy
This commit is contained in:
1 parent
62c5a3ac86
commit
2d5ff0c33e
10 files changed
+1142
No files matched your search
@@ -0,0 +1,53 @@
|
||||
-- Schema contract: objects exist, RLS is on, API roles start from zero.
|
||||
begin;
|
||||
select plan(22);
|
||||
|
||||
-- Schemas
|
||||
select has_schema('private', 'schema private exists');
|
||||
select has_schema('audit', 'schema audit exists');
|
||||
|
||||
-- Tables
|
||||
select has_table('public', 'profiles', 'table public.profiles exists');
|
||||
select has_table('public', 'profile_roles', 'table public.profile_roles exists');
|
||||
select has_table('audit', 'audit_logs', 'table audit.audit_logs exists');
|
||||
|
||||
-- RLS enabled everywhere (pgTAP has no helper: read pg_class)
|
||||
select ok(
|
||||
(select relrowsecurity from pg_class where oid = 'public.profiles'::regclass),
|
||||
'RLS enabled on profiles'
|
||||
);
|
||||
select ok(
|
||||
(select relrowsecurity from pg_class where oid = 'public.profile_roles'::regclass),
|
||||
'RLS enabled on profile_roles'
|
||||
);
|
||||
select ok(
|
||||
(select relrowsecurity from pg_class where oid = 'audit.audit_logs'::regclass),
|
||||
'RLS enabled on audit_logs'
|
||||
);
|
||||
|
||||
-- Enum
|
||||
select enum_has_labels(
|
||||
'public', 'platform_role',
|
||||
array['owner', 'admin', 'moderator', 'support'],
|
||||
'platform_role has exactly the four platform roles (no professional status)'
|
||||
);
|
||||
|
||||
-- Functions
|
||||
select has_function('private', 'log_event', 'private.log_event exists');
|
||||
select has_function('private', 'is_platform_owner', array['uuid'], 'private.is_platform_owner exists');
|
||||
select has_function('private', 'is_platform_admin', array['uuid'], 'private.is_platform_admin exists');
|
||||
select has_function('private', 'is_platform_moderator', array['uuid'], 'private.is_platform_moderator exists');
|
||||
select has_function('private', 'is_support', array['uuid'], 'private.is_support exists');
|
||||
select has_function('public', 'grant_platform_role', array['uuid', 'platform_role'], 'public.grant_platform_role exists');
|
||||
select has_function('public', 'revoke_platform_role', array['uuid', 'platform_role', 'text'], 'public.revoke_platform_role exists');
|
||||
|
||||
-- Privileges: anon has nothing, authenticated has only what RLS then filters
|
||||
select ok(not has_table_privilege('anon', 'public.profiles', 'select'), 'anon cannot select profiles');
|
||||
select ok(not has_table_privilege('anon', 'public.profile_roles', 'select'), 'anon cannot select profile_roles');
|
||||
select ok(not has_table_privilege('authenticated', 'public.profiles', 'insert'), 'authenticated cannot insert profiles');
|
||||
select ok(not has_table_privilege('authenticated', 'public.profiles', 'delete'), 'authenticated cannot delete profiles');
|
||||
select ok(not has_table_privilege('authenticated', 'public.profile_roles', 'insert'), 'authenticated cannot insert profile_roles');
|
||||
select ok(not has_column_privilege('authenticated', 'public.profiles', 'active', 'update'), 'authenticated cannot update profiles.active');
|
||||
|
||||
select * from finish();
|
||||
rollback;
|
||||
Reference in new issue
Block a user