سامانه صدور فاکتور و حسابداری
test: add zero-cost D1 database harness
davoodmehraban89 committed
Oct 1, 2026 at 22:20 UTC
ff61c240a902353687fd55270506cb7f91200b5b
1 file changed
+13
supabase/tests/request_d1_bootstrap.sql
new
+13
@@ -0,0 +1,13 @@
1
+create extension if not exists pgcrypto;
2
+create schema if not exists auth;
3
+create schema if not exists private;
4
+do $$ begin create role anon nologin; exception when duplicate_object then null; end $$;
5
+do $$ begin create role authenticated nologin; exception when duplicate_object then null; end $$;
6
+grant usage on schema public,private to authenticated;
7
+create table if not exists public.profiles(id uuid primary key);
8
+create table if not exists public.organizations(id uuid primary key,owner_user_id uuid references public.profiles(id));
9
+create or replace function auth.uid() returns uuid language sql stable set search_path='' as $$ select nullif(current_setting('request.jwt.claim.sub',true),'')::uuid $$;
10
+create or replace function private.current_organization_ids() returns setof uuid language sql stable security definer set search_path='' as $$ select nullif(current_setting('request.jwt.claim.org',true),'')::uuid where (select auth.uid()) is not null and coalesce(nullif(current_setting('request.jwt.claim.member_active',true),''),'true')='true' $$;
11
+create or replace function private.organization_has_module_entitlement(p_organization_id uuid,p_module_key text,p_require_active boolean default false) returns boolean language sql stable security definer set search_path='' as $$ select p_module_key='requests_workflow' and p_organization_id=nullif(current_setting('request.jwt.claim.org',true),'')::uuid and coalesce(nullif(current_setting('request.jwt.claim.entitled',true),''),'true')='true' and (not p_require_active or coalesce(nullif(current_setting('request.jwt.claim.write',true),''),'true')='true') $$;
12
+create or replace function private.has_org_capability(p_organization_id uuid,p_module_key text,p_capability text) returns boolean language sql stable security definer set search_path='' as $$ select p_module_key='requests_workflow' and p_organization_id=nullif(current_setting('request.jwt.claim.org',true),'')::uuid and p_capability=any(string_to_array(coalesce(current_setting('request.jwt.claim.capabilities',true),''),',')) $$;
13
+revoke all on function private.current_organization_ids() from public,anon; revoke all on function private.organization_has_module_entitlement(uuid,text,boolean) from public,anon; revoke all on function private.has_org_capability(uuid,text,text) from public,anon; grant execute on function private.current_organization_ids() to authenticated; grant execute on function private.organization_has_module_entitlement(uuid,text,boolean) to authenticated; grant execute on function private.has_org_capability(uuid,text,text) to authenticated;