- 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
55 lines
2.3 KiB
PL/PgSQL
55 lines
2.3 KiB
PL/PgSQL
-- Local development seed. Applied by `supabase db reset` / `supabase start`
|
|
-- on the LOCAL stack only (config.toml [db.seed]). Never run against a shared
|
|
-- or production database: it creates accounts with a known password.
|
|
--
|
|
-- Accounts (password for all three: LocalDev-only-password-1)
|
|
-- owner@faunosteo.local platform owner (bootstrapped below)
|
|
-- alice@faunosteo.local plain user
|
|
-- bob@faunosteo.local plain user
|
|
--
|
|
-- Needs the real auth schema (auth.identities, extensions.crypt): not part of
|
|
-- the PGlite harness, which only applies migrations.
|
|
|
|
create or replace function pg_temp.seed_user(p_id uuid, p_email text, p_display_name text)
|
|
returns void
|
|
language plpgsql
|
|
as $$
|
|
begin
|
|
insert into auth.users (
|
|
instance_id, id, aud, role, email, encrypted_password, email_confirmed_at,
|
|
raw_app_meta_data, raw_user_meta_data, created_at, updated_at,
|
|
confirmation_token, recovery_token, email_change_token_new, email_change
|
|
)
|
|
values (
|
|
'00000000-0000-0000-0000-000000000000', p_id, 'authenticated', 'authenticated',
|
|
p_email, extensions.crypt('LocalDev-only-password-1', extensions.gen_salt('bf')), now(),
|
|
'{"provider":"email","providers":["email"]}'::jsonb,
|
|
jsonb_build_object('display_name', p_display_name, 'locale', 'fr'),
|
|
now(), now(), '', '', '', ''
|
|
)
|
|
on conflict (id) do nothing;
|
|
|
|
insert into auth.identities (
|
|
id, user_id, provider_id, identity_data, provider,
|
|
last_sign_in_at, created_at, updated_at
|
|
)
|
|
values (
|
|
gen_random_uuid(), p_id, p_id::text,
|
|
jsonb_build_object('sub', p_id::text, 'email', p_email, 'email_verified', true),
|
|
'email', now(), now(), now()
|
|
)
|
|
on conflict (provider_id, provider) do nothing;
|
|
end;
|
|
$$;
|
|
|
|
select pg_temp.seed_user('10000000-0000-0000-0000-000000000001', 'owner@faunosteo.local', 'Owner Local');
|
|
select pg_temp.seed_user('10000000-0000-0000-0000-00000000000a', 'alice@faunosteo.local', 'Alice Local');
|
|
select pg_temp.seed_user('10000000-0000-0000-0000-00000000000b', 'bob@faunosteo.local', 'Bob Local');
|
|
|
|
-- First platform owner (system bootstrap, audited with a null actor).
|
|
select private.assign_platform_role(null, '10000000-0000-0000-0000-000000000001', 'owner')
|
|
where not exists (
|
|
select 1 from public.profile_roles
|
|
where user_id = '10000000-0000-0000-0000-000000000001' and role = 'owner' and revoked_at is null
|
|
);
|