Files
faunosteo/packages/supabase/tests/db/supabase-shim.sql
T
bchanot ce76c6597a feat(supabase): @faunosteo/supabase package with PGlite harness and typed client
- tests/db: PGlite (PostgreSQL 17 WASM) applies the Supabase shim + migrations and
  runs supabase/tests/*.sql through pgTAP without Docker
- schema-types test pins tables, columns, enums, RPC args, RLS-on, no using(true)
- database.types.ts in supabase gen types format; createBrowserClient (PKCE)
- Supabase CLI pinned as root devDependency; db:* root scripts
2026-10-08 22:20:54 +02:00

76 lines
2.4 KiB
PL/PgSQL

-- Minimal stand-in for the Supabase base schema, applied to a bare PGlite
-- database before the project migrations. Mirrors what the hosted/local stack
-- provides: API roles, auth schema with users table + JWT claim helpers, and
-- the permissive default privileges on public (ALL to the API roles), so a
-- migration that forgets to revoke is caught by the tests.
-- Test-only file: never applied to a real Supabase database.
create role anon nologin noinherit;
create role authenticated nologin noinherit;
create role service_role nologin noinherit bypassrls;
create schema auth;
create schema extensions;
create table auth.users (
instance_id uuid,
id uuid primary key default gen_random_uuid(),
aud varchar(255),
role varchar(255),
email varchar(255),
encrypted_password varchar(255),
email_confirmed_at timestamptz,
raw_app_meta_data jsonb,
raw_user_meta_data jsonb,
created_at timestamptz default now(),
updated_at timestamptz default now()
);
create or replace function auth.uid()
returns uuid
language sql
stable
as $$
select nullif(
coalesce(
current_setting('request.jwt.claim.sub', true),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'sub')
),
''
)::uuid
$$;
create or replace function auth.role()
returns text
language sql
stable
as $$
select nullif(
coalesce(
current_setting('request.jwt.claim.role', true),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'role')
),
''
)::text
$$;
create or replace function auth.jwt()
returns jsonb
language sql
stable
as $$
select coalesce(
nullif(current_setting('request.jwt.claim', true), ''),
nullif(current_setting('request.jwt.claims', true), '')
)::jsonb
$$;
grant usage on schema auth to anon, authenticated, service_role;
grant execute on function auth.uid(), auth.role(), auth.jwt() to anon, authenticated, service_role;
grant usage on schema public to anon, authenticated, service_role;
grant usage on schema extensions to anon, authenticated, service_role;
alter default privileges in schema public grant all on tables to anon, authenticated, service_role;
alter default privileges in schema public grant all on functions to anon, authenticated, service_role;
alter default privileges in schema public grant all on sequences to anon, authenticated, service_role;