سامانه صدور فاکتور و حسابداری

test: add free PostgreSQL harness for C8 policy SQL

davoodmehraban89 committed Oct 1, 2026 at 21:06 UTC 6404f2abfb003402192a886064f69a6cf6954347
1 file changed +34
supabase/tests/office_c8_bootstrap.sql new
+34
@@ -0,0 +1,34 @@
1 +-- Minimal zero-cost PostgreSQL harness for C8 task-1 migration tests.
2 +-- This is test-only scaffolding; production authorization helpers are not replaced.
3 +create extension if not exists pgcrypto;
4 +create schema if not exists auth;
5 +create schema if not exists private;
6 +do $$ begin create role anon nologin; exception when duplicate_object then null; end $$;
7 +do $$ begin create role authenticated nologin; exception when duplicate_object then null; end $$;
8 +
9 +create table if not exists public.profiles(id uuid primary key);
10 +create table if not exists public.organizations(id uuid primary key, owner_user_id uuid references public.profiles(id));
11 +
12 +create or replace function auth.uid() returns uuid
13 +language sql stable set search_path=''
14 +as $$ select nullif(current_setting('request.jwt.claim.sub',true),'')::uuid $$;
15 +
16 +create or replace function private.current_organization_ids() returns setof uuid
17 +language sql stable security definer set search_path=''
18 +as $$ select nullif(current_setting('request.jwt.claim.org',true),'')::uuid where (select auth.uid()) is not null $$;
19 +
20 +create or replace function private.organization_has_module_entitlement(p_organization_id uuid,p_module_key text,p_require_active boolean default false)
21 +returns boolean language sql stable security definer set search_path=''
22 +as $$
23 + select p_module_key='office_automation'
24 + and p_organization_id=nullif(current_setting('request.jwt.claim.org',true),'')::uuid
25 + and (not p_require_active or coalesce(nullif(current_setting('request.jwt.claim.write',true),''),'true')='true')
26 +$$;
27 +
28 +create or replace function private.has_org_capability(p_organization_id uuid,p_module_key text,p_capability text)
29 +returns boolean language sql stable security definer set search_path=''
30 +as $$
31 + select p_module_key='office_automation'
32 + and p_organization_id=nullif(current_setting('request.jwt.claim.org',true),'')::uuid
33 + and p_capability=any(string_to_array(coalesce(current_setting('request.jwt.claim.capabilities',true),''),','))
34 +$$;