add medreport schema

This commit is contained in:
Danel Kungla
2025-07-09 13:31:37 +03:00
parent 9371ff7710
commit d9198a8a12
73 changed files with 420 additions and 270 deletions

View File

@@ -2157,6 +2157,9 @@ AS $function$select
or has_role_on_account.account_role is null)));$function$
;
grant
execute on function medreport.has_role_on_account (uuid, varchar) to authenticated;
CREATE OR REPLACE FUNCTION medreport.has_same_role_hierarchy_level(target_user_id uuid, target_account_id uuid, role_name character varying)
RETURNS boolean
LANGUAGE plpgsql
@@ -2221,6 +2224,10 @@ begin
end;$function$
;
grant
execute on function medreport.has_same_role_hierarchy_level (uuid, uuid, varchar) to authenticated,
service_role;
CREATE OR REPLACE FUNCTION medreport.is_aal2()
RETURNS boolean
LANGUAGE plpgsql
@@ -2236,6 +2243,8 @@ end
$function$
;
grant execute on function medreport.is_aal2() to authenticated;
CREATE OR REPLACE FUNCTION medreport.is_account_owner(account_id uuid)
RETURNS boolean
LANGUAGE sql
@@ -2251,6 +2260,10 @@ AS $function$select
and primary_owner_user_id = auth.uid());$function$
;
grant
execute on function medreport.is_account_owner (uuid) to authenticated,
service_role;
CREATE OR REPLACE FUNCTION medreport.is_account_team_member(target_account_id uuid)
RETURNS boolean
LANGUAGE sql
@@ -2262,6 +2275,10 @@ AS $function$select exists(
);$function$
;
grant
execute on function medreport.is_account_team_member (uuid) to authenticated,
service_role;
CREATE OR REPLACE FUNCTION medreport.is_mfa_compliant()
RETURNS boolean
LANGUAGE plpgsql
@@ -2280,6 +2297,8 @@ AS $function$begin
end$function$
;
grant execute on function medreport.is_mfa_compliant() to authenticated;
CREATE OR REPLACE FUNCTION medreport.is_set(field_name text)
RETURNS boolean
LANGUAGE plpgsql
@@ -2294,6 +2313,9 @@ begin
end;$function$
;
grant
execute on function medreport.is_set (text) to authenticated;
CREATE OR REPLACE FUNCTION medreport.is_super_admin()
RETURNS boolean
LANGUAGE plpgsql
@@ -2311,6 +2333,8 @@ begin
end$function$
;
grant execute on function medreport.is_super_admin() to authenticated;
CREATE OR REPLACE FUNCTION medreport.is_team_member(account_id uuid, user_id uuid)
RETURNS boolean
LANGUAGE sql
@@ -2328,6 +2352,10 @@ AS $function$select
and membership.account_id = is_team_member.account_id);$function$
;
grant
execute on function medreport.is_team_member (uuid, uuid) to authenticated,
service_role;
CREATE OR REPLACE FUNCTION medreport.revoke_nonce(p_id uuid, p_reason text DEFAULT NULL::text)
RETURNS boolean
LANGUAGE plpgsql
@@ -2350,6 +2378,8 @@ BEGIN
END;$function$
;
grant execute on function medreport.revoke_nonce to service_role;
CREATE OR REPLACE FUNCTION medreport.team_account_workspace(account_slug text)
RETURNS TABLE(id uuid, name character varying, picture_url character varying, slug text, role character varying, role_hierarchy_level integer, primary_owner_user_id uuid, subscription_status medreport.subscription_status, permissions medreport.app_permissions[])
LANGUAGE plpgsql
@@ -2489,6 +2519,10 @@ AS $function$begin
end;$function$
;
grant
execute on function medreport.update_account(p_name character varying, p_last_name text, p_personal_code text, p_phone text, p_city text, p_has_consent_personal_data boolean, p_uid uuid) to authenticated,
service_role;
CREATE OR REPLACE FUNCTION medreport.upsert_order(target_account_id uuid, target_customer_id character varying, target_order_id text, status medreport.payment_status, billing_provider medreport.billing_provider, total_amount numeric, currency character varying, line_items jsonb)
RETURNS medreport.orders
LANGUAGE plpgsql
@@ -2589,6 +2623,18 @@ begin
end;$function$
;
grant
execute on function medreport.upsert_order (
uuid,
varchar,
text,
medreport.payment_status,
medreport.billing_provider,
numeric,
varchar,
jsonb
) to service_role;
CREATE OR REPLACE FUNCTION medreport.upsert_subscription(target_account_id uuid, target_customer_id character varying, target_subscription_id text, active boolean, status medreport.subscription_status, billing_provider medreport.billing_provider, cancel_at_period_end boolean, currency character varying, period_starts_at timestamp with time zone, period_ends_at timestamp with time zone, line_items jsonb, trial_starts_at timestamp with time zone DEFAULT NULL::timestamp with time zone, trial_ends_at timestamp with time zone DEFAULT NULL::timestamp with time zone)
RETURNS medreport.subscriptions
LANGUAGE plpgsql
@@ -2716,6 +2762,23 @@ begin
end;$function$
;
grant
execute on function medreport.upsert_subscription (
uuid,
varchar,
text,
bool,
medreport.subscription_status,
medreport.billing_provider,
bool,
varchar,
timestamptz,
timestamptz,
jsonb,
timestamptz,
timestamptz
) to service_role;
create or replace view "medreport"."user_account_workspace" as SELECT accounts.id,
accounts.name,
accounts.picture_url,
@@ -2727,6 +2790,10 @@ create or replace view "medreport"."user_account_workspace" as SELECT accounts.
WHERE ((accounts.primary_owner_user_id = ( SELECT auth.uid() AS uid)) AND (accounts.is_personal_account = true))
LIMIT 1;
grant
select
on medreport.user_account_workspace to authenticated,
service_role;
create or replace view "medreport"."user_accounts" as SELECT account.id,
account.name,
@@ -2739,6 +2806,10 @@ create or replace view "medreport"."user_accounts" as SELECT account.id,
FROM medreport.accounts_memberships
WHERE (accounts_memberships.user_id = ( SELECT auth.uid() AS uid)))));
grant
select
on medreport.user_accounts to authenticated,
service_role;
CREATE OR REPLACE FUNCTION medreport.verify_nonce(p_token text, p_purpose text, p_user_id uuid DEFAULT NULL::uuid, p_required_scopes text[] DEFAULT NULL::text[], p_max_verification_attempts integer DEFAULT 5, p_ip inet DEFAULT NULL::inet, p_user_agent text DEFAULT NULL::text)
RETURNS jsonb
@@ -2836,6 +2907,10 @@ BEGIN
END;$function$
;
grant
execute on function medreport.verify_nonce to authenticated,
service_role;
grant delete on table "medreport"."account_params" to "anon";
grant insert on table "medreport"."account_params" to "anon";

View File

@@ -39,3 +39,5 @@ END;$function$
grant execute on function medreport.has_consent_personal_data(uuid)
to authenticated, anon;
grant usage on schema medreport to authenticated;