add health benefit form
fix super admin
This commit is contained in:
@@ -1,227 +1,227 @@
|
||||
-- create table "public"."connected_online_providers" (
|
||||
-- "id" bigint not null,
|
||||
-- "name" text not null,
|
||||
-- "email" text,
|
||||
-- "phone_number" text,
|
||||
-- "can_select_worker" boolean not null,
|
||||
-- "personal_code_required" boolean not null,
|
||||
-- "created_at" timestamp with time zone not null default now(),
|
||||
-- "updated_at" timestamp without time zone default now()
|
||||
-- );
|
||||
create table "public"."connected_online_providers" (
|
||||
"id" bigint not null,
|
||||
"name" text not null,
|
||||
"email" text,
|
||||
"phone_number" text,
|
||||
"can_select_worker" boolean not null,
|
||||
"personal_code_required" boolean not null,
|
||||
"created_at" timestamp with time zone not null default now(),
|
||||
"updated_at" timestamp without time zone default now()
|
||||
);
|
||||
|
||||
|
||||
-- alter table "public"."connected_online_providers" enable row level security;
|
||||
alter table "public"."connected_online_providers" enable row level security;
|
||||
|
||||
-- create table "public"."connected_online_services" (
|
||||
-- "id" bigint not null,
|
||||
-- "clinic_id" bigint not null,
|
||||
-- "sync_id" bigint not null,
|
||||
-- "name" text not null,
|
||||
-- "description" text,
|
||||
-- "price" double precision not null,
|
||||
-- "requires_payment" boolean not null,
|
||||
-- "duration" bigint not null,
|
||||
-- "neto_duration" bigint,
|
||||
-- "display" text,
|
||||
-- "price_periods" text,
|
||||
-- "online_hide_duration" bigint,
|
||||
-- "online_hide_price" bigint,
|
||||
-- "code" text not null,
|
||||
-- "has_free_codes" boolean not null,
|
||||
-- "created_at" timestamp with time zone not null default now(),
|
||||
-- "updated_at" timestamp with time zone default now()
|
||||
-- );
|
||||
create table "public"."connected_online_services" (
|
||||
"id" bigint not null,
|
||||
"clinic_id" bigint not null,
|
||||
"sync_id" bigint not null,
|
||||
"name" text not null,
|
||||
"description" text,
|
||||
"price" double precision not null,
|
||||
"requires_payment" boolean not null,
|
||||
"duration" bigint not null,
|
||||
"neto_duration" bigint,
|
||||
"display" text,
|
||||
"price_periods" text,
|
||||
"online_hide_duration" bigint,
|
||||
"online_hide_price" bigint,
|
||||
"code" text not null,
|
||||
"has_free_codes" boolean not null,
|
||||
"created_at" timestamp with time zone not null default now(),
|
||||
"updated_at" timestamp with time zone default now()
|
||||
);
|
||||
|
||||
|
||||
-- alter table "public"."connected_online_services" enable row level security;
|
||||
alter table "public"."connected_online_services" enable row level security;
|
||||
|
||||
-- CREATE UNIQUE INDEX connected_online_providers_id_key ON public.connected_online_providers USING btree (id);
|
||||
CREATE UNIQUE INDEX connected_online_providers_id_key ON public.connected_online_providers USING btree (id);
|
||||
|
||||
-- CREATE UNIQUE INDEX connected_online_providers_pkey ON public.connected_online_providers USING btree (id);
|
||||
CREATE UNIQUE INDEX connected_online_providers_pkey ON public.connected_online_providers USING btree (id);
|
||||
|
||||
-- CREATE UNIQUE INDEX connected_online_services_id_key ON public.connected_online_services USING btree (id);
|
||||
CREATE UNIQUE INDEX connected_online_services_id_key ON public.connected_online_services USING btree (id);
|
||||
|
||||
-- CREATE UNIQUE INDEX connected_online_services_pkey ON public.connected_online_services USING btree (id);
|
||||
CREATE UNIQUE INDEX connected_online_services_pkey ON public.connected_online_services USING btree (id);
|
||||
|
||||
-- alter table "public"."connected_online_providers" add constraint "connected_online_providers_pkey" PRIMARY KEY using index "connected_online_providers_pkey";
|
||||
alter table "public"."connected_online_providers" add constraint "connected_online_providers_pkey" PRIMARY KEY using index "connected_online_providers_pkey";
|
||||
|
||||
-- alter table "public"."connected_online_services" add constraint "connected_online_services_pkey" PRIMARY KEY using index "connected_online_services_pkey";
|
||||
alter table "public"."connected_online_services" add constraint "connected_online_services_pkey" PRIMARY KEY using index "connected_online_services_pkey";
|
||||
|
||||
-- alter table "public"."connected_online_providers" add constraint "connected_online_providers_id_key" UNIQUE using index "connected_online_providers_id_key";
|
||||
alter table "public"."connected_online_providers" add constraint "connected_online_providers_id_key" UNIQUE using index "connected_online_providers_id_key";
|
||||
|
||||
-- alter table "public"."connected_online_services" add constraint "connected_online_services_clinic_id_fkey" FOREIGN KEY (clinic_id) REFERENCES connected_online_providers(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
alter table "public"."connected_online_services" add constraint "connected_online_services_clinic_id_fkey" FOREIGN KEY (clinic_id) REFERENCES connected_online_providers(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
|
||||
-- alter table "public"."connected_online_services" validate constraint "connected_online_services_clinic_id_fkey";
|
||||
alter table "public"."connected_online_services" validate constraint "connected_online_services_clinic_id_fkey";
|
||||
|
||||
-- alter table "public"."connected_online_services" add constraint "connected_online_services_id_key" UNIQUE using index "connected_online_services_id_key";
|
||||
alter table "public"."connected_online_services" add constraint "connected_online_services_id_key" UNIQUE using index "connected_online_services_id_key";
|
||||
|
||||
-- grant delete on table "public"."connected_online_providers" to "service_role";
|
||||
grant delete on table "public"."connected_online_providers" to "service_role";
|
||||
|
||||
-- grant insert on table "public"."connected_online_providers" to "service_role";
|
||||
grant insert on table "public"."connected_online_providers" to "service_role";
|
||||
|
||||
-- grant references on table "public"."connected_online_providers" to "service_role";
|
||||
grant references on table "public"."connected_online_providers" to "service_role";
|
||||
|
||||
-- grant select on table "public"."connected_online_providers" to "service_role";
|
||||
grant select on table "public"."connected_online_providers" to "service_role";
|
||||
|
||||
-- grant trigger on table "public"."connected_online_providers" to "service_role";
|
||||
grant trigger on table "public"."connected_online_providers" to "service_role";
|
||||
|
||||
-- grant truncate on table "public"."connected_online_providers" to "service_role";
|
||||
grant truncate on table "public"."connected_online_providers" to "service_role";
|
||||
|
||||
-- grant update on table "public"."connected_online_providers" to "service_role";
|
||||
grant update on table "public"."connected_online_providers" to "service_role";
|
||||
|
||||
-- grant select on table "public"."connected_online_providers" to "authenticated";
|
||||
grant select on table "public"."connected_online_providers" to "authenticated";
|
||||
|
||||
-- grant delete on table "public"."connected_online_services" to "service_role";
|
||||
grant delete on table "public"."connected_online_services" to "service_role";
|
||||
|
||||
-- grant insert on table "public"."connected_online_services" to "service_role";
|
||||
grant insert on table "public"."connected_online_services" to "service_role";
|
||||
|
||||
-- grant references on table "public"."connected_online_services" to "service_role";
|
||||
grant references on table "public"."connected_online_services" to "service_role";
|
||||
|
||||
-- grant select on table "public"."connected_online_services" to "service_role";
|
||||
grant select on table "public"."connected_online_services" to "service_role";
|
||||
|
||||
-- grant trigger on table "public"."connected_online_services" to "service_role";
|
||||
grant trigger on table "public"."connected_online_services" to "service_role";
|
||||
|
||||
-- grant truncate on table "public"."connected_online_services" to "service_role";
|
||||
grant truncate on table "public"."connected_online_services" to "service_role";
|
||||
|
||||
-- grant update on table "public"."connected_online_services" to "service_role";
|
||||
grant update on table "public"."connected_online_services" to "service_role";
|
||||
|
||||
-- grant select on table "public"."connected_online_services" to "authenticated";
|
||||
grant select on table "public"."connected_online_services" to "authenticated";
|
||||
|
||||
-- create type "audit"."request_status" as enum ('SUCCESS', 'FAIL');
|
||||
create type "audit"."request_status" as enum ('SUCCESS', 'FAIL');
|
||||
|
||||
-- create table "audit"."request_entries" (
|
||||
-- "id" bigint generated by default as identity not null,
|
||||
-- "personal_code" bigint,
|
||||
-- "request_api" text not null,
|
||||
-- "request_api_method" text not null,
|
||||
-- "status" audit.request_status not null,
|
||||
-- "comment" text,
|
||||
-- "service_provider_id" bigint,
|
||||
-- "service_id" bigint,
|
||||
-- "requested_start_date" timestamp with time zone,
|
||||
-- "requested_end_date" timestamp with time zone,
|
||||
-- "created_at" timestamp with time zone not null default now()
|
||||
-- );
|
||||
create table "audit"."request_entries" (
|
||||
"id" bigint generated by default as identity not null,
|
||||
"personal_code" bigint,
|
||||
"request_api" text not null,
|
||||
"request_api_method" text not null,
|
||||
"status" audit.request_status not null,
|
||||
"comment" text,
|
||||
"service_provider_id" bigint,
|
||||
"service_id" bigint,
|
||||
"requested_start_date" timestamp with time zone,
|
||||
"requested_end_date" timestamp with time zone,
|
||||
"created_at" timestamp with time zone not null default now()
|
||||
);
|
||||
|
||||
|
||||
-- alter table "audit"."request_entries" enable row level security;
|
||||
alter table "audit"."request_entries" enable row level security;
|
||||
|
||||
-- CREATE UNIQUE INDEX request_entries_pkey ON audit.request_entries USING btree (id);
|
||||
CREATE UNIQUE INDEX request_entries_pkey ON audit.request_entries USING btree (id);
|
||||
|
||||
-- alter table "audit"."request_entries" add constraint "request_entries_pkey" PRIMARY KEY using index "request_entries_pkey";
|
||||
alter table "audit"."request_entries" add constraint "request_entries_pkey" PRIMARY KEY using index "request_entries_pkey";
|
||||
|
||||
-- grant delete on table "audit"."request_entries" to "service_role";
|
||||
grant delete on table "audit"."request_entries" to "service_role";
|
||||
|
||||
-- grant insert on table "audit"."request_entries" to "service_role";
|
||||
grant insert on table "audit"."request_entries" to "service_role";
|
||||
|
||||
-- grant references on table "audit"."request_entries" to "service_role";
|
||||
grant references on table "audit"."request_entries" to "service_role";
|
||||
|
||||
-- grant select on table "audit"."request_entries" to "service_role";
|
||||
grant select on table "audit"."request_entries" to "service_role";
|
||||
|
||||
-- grant trigger on table "audit"."request_entries" to "service_role";
|
||||
grant trigger on table "audit"."request_entries" to "service_role";
|
||||
|
||||
-- grant truncate on table "audit"."request_entries" to "service_role";
|
||||
grant truncate on table "audit"."request_entries" to "service_role";
|
||||
|
||||
-- grant update on table "audit"."request_entries" to "service_role";
|
||||
grant update on table "audit"."request_entries" to "service_role";
|
||||
|
||||
-- create policy "service_role_all"
|
||||
-- on "audit"."request_entries"
|
||||
-- as permissive
|
||||
-- for all
|
||||
-- to service_role
|
||||
-- using (true);
|
||||
create policy "service_role_all"
|
||||
on "audit"."request_entries"
|
||||
as permissive
|
||||
for all
|
||||
to service_role
|
||||
using (true);
|
||||
|
||||
-- create table "public"."connected_online_reservation" (
|
||||
-- "id" bigint generated by default as identity not null,
|
||||
-- "user_id" uuid not null,
|
||||
-- "booking_code" text not null,
|
||||
-- "service_id" bigint not null,
|
||||
-- "clinic_id" bigint not null,
|
||||
-- "service_user_id" bigint,
|
||||
-- "sync_user_id" bigint not null,
|
||||
-- "requires_payment" boolean not null,
|
||||
-- "comments" text,
|
||||
-- "start_time" timestamp with time zone not null,
|
||||
-- "lang" text not null,
|
||||
-- "discount_code" text,
|
||||
-- "created_at" timestamp with time zone not null default now(),
|
||||
-- "updated_at" timestamp with time zone default now()
|
||||
-- );
|
||||
create table "public"."connected_online_reservation" (
|
||||
"id" bigint generated by default as identity not null,
|
||||
"user_id" uuid not null,
|
||||
"booking_code" text not null,
|
||||
"service_id" bigint not null,
|
||||
"clinic_id" bigint not null,
|
||||
"service_user_id" bigint,
|
||||
"sync_user_id" bigint not null,
|
||||
"requires_payment" boolean not null,
|
||||
"comments" text,
|
||||
"start_time" timestamp with time zone not null,
|
||||
"lang" text not null,
|
||||
"discount_code" text,
|
||||
"created_at" timestamp with time zone not null default now(),
|
||||
"updated_at" timestamp with time zone default now()
|
||||
);
|
||||
|
||||
|
||||
-- alter table "public"."connected_online_reservation" enable row level security;
|
||||
alter table "public"."connected_online_reservation" enable row level security;
|
||||
|
||||
-- CREATE UNIQUE INDEX connected_online_reservation_booking_code_key ON public.connected_online_reservation USING btree (booking_code);
|
||||
CREATE UNIQUE INDEX connected_online_reservation_booking_code_key ON public.connected_online_reservation USING btree (booking_code);
|
||||
|
||||
-- CREATE UNIQUE INDEX connected_online_reservation_pkey ON public.connected_online_reservation USING btree (id);
|
||||
CREATE UNIQUE INDEX connected_online_reservation_pkey ON public.connected_online_reservation USING btree (id);
|
||||
|
||||
-- alter table "public"."connected_online_reservation" add constraint "connected_online_reservation_pkey" PRIMARY KEY using index "connected_online_reservation_pkey";
|
||||
alter table "public"."connected_online_reservation" add constraint "connected_online_reservation_pkey" PRIMARY KEY using index "connected_online_reservation_pkey";
|
||||
|
||||
-- alter table "public"."connected_online_reservation" add constraint "connected_online_reservation_booking_code_key" UNIQUE using index "connected_online_reservation_booking_code_key";
|
||||
alter table "public"."connected_online_reservation" add constraint "connected_online_reservation_booking_code_key" UNIQUE using index "connected_online_reservation_booking_code_key";
|
||||
|
||||
-- alter table "public"."connected_online_reservation" add constraint "connected_online_reservation_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth.users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
alter table "public"."connected_online_reservation" add constraint "connected_online_reservation_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth.users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
|
||||
-- alter table "public"."connected_online_reservation" validate constraint "connected_online_reservation_user_id_fkey";
|
||||
alter table "public"."connected_online_reservation" validate constraint "connected_online_reservation_user_id_fkey";
|
||||
|
||||
-- grant delete on table "public"."connected_online_reservation" to "service_role";
|
||||
grant delete on table "public"."connected_online_reservation" to "service_role";
|
||||
|
||||
-- grant insert on table "public"."connected_online_reservation" to "service_role";
|
||||
grant insert on table "public"."connected_online_reservation" to "service_role";
|
||||
|
||||
-- grant references on table "public"."connected_online_reservation" to "service_role";
|
||||
grant references on table "public"."connected_online_reservation" to "service_role";
|
||||
|
||||
-- grant select on table "public"."connected_online_reservation" to "service_role";
|
||||
grant select on table "public"."connected_online_reservation" to "service_role";
|
||||
|
||||
-- grant trigger on table "public"."connected_online_reservation" to "service_role";
|
||||
grant trigger on table "public"."connected_online_reservation" to "service_role";
|
||||
|
||||
-- grant truncate on table "public"."connected_online_reservation" to "service_role";
|
||||
grant truncate on table "public"."connected_online_reservation" to "service_role";
|
||||
|
||||
-- grant update on table "public"."connected_online_reservation" to "service_role";
|
||||
grant update on table "public"."connected_online_reservation" to "service_role";
|
||||
|
||||
-- create policy "service_role_all"
|
||||
-- on "public"."connected_online_reservation"
|
||||
-- as permissive
|
||||
-- for all
|
||||
-- to service_role
|
||||
-- using (true);
|
||||
create policy "service_role_all"
|
||||
on "public"."connected_online_reservation"
|
||||
as permissive
|
||||
for all
|
||||
to service_role
|
||||
using (true);
|
||||
|
||||
|
||||
-- CREATE TRIGGER connected_online_providers_change_record_timestamps AFTER INSERT OR UPDATE ON public.connected_online_providers FOR EACH ROW EXECUTE FUNCTION trigger_set_timestamps();
|
||||
CREATE TRIGGER connected_online_providers_change_record_timestamps AFTER INSERT OR UPDATE ON public.connected_online_providers FOR EACH ROW EXECUTE FUNCTION trigger_set_timestamps();
|
||||
|
||||
-- CREATE TRIGGER connected_online_services_change_record_timestamps AFTER INSERT OR UPDATE ON public.connected_online_services FOR EACH ROW EXECUTE FUNCTION trigger_set_timestamps();
|
||||
CREATE TRIGGER connected_online_services_change_record_timestamps AFTER INSERT OR UPDATE ON public.connected_online_services FOR EACH ROW EXECUTE FUNCTION trigger_set_timestamps();
|
||||
|
||||
-- create policy "service_role_all"
|
||||
-- on "public"."connected_online_providers"
|
||||
-- as permissive
|
||||
-- for all
|
||||
-- to service_role
|
||||
-- using (true);
|
||||
create policy "service_role_all"
|
||||
on "public"."connected_online_providers"
|
||||
as permissive
|
||||
for all
|
||||
to service_role
|
||||
using (true);
|
||||
|
||||
|
||||
-- create policy "service_role_all"
|
||||
-- on "public"."connected_online_services"
|
||||
-- as permissive
|
||||
-- for all
|
||||
-- to service_role
|
||||
-- using (true);
|
||||
create policy "service_role_all"
|
||||
on "public"."connected_online_services"
|
||||
as permissive
|
||||
for all
|
||||
to service_role
|
||||
using (true);
|
||||
|
||||
-- create policy "authenticated_select"
|
||||
-- on "public"."connected_online_providers"
|
||||
-- as permissive
|
||||
-- for select
|
||||
-- to authenticated
|
||||
-- using (true);
|
||||
create policy "authenticated_select"
|
||||
on "public"."connected_online_providers"
|
||||
as permissive
|
||||
for select
|
||||
to authenticated
|
||||
using (true);
|
||||
|
||||
-- create policy "authenticated_select"
|
||||
-- on "public"."connected_online_services"
|
||||
-- as permissive
|
||||
-- for select
|
||||
-- to authenticated
|
||||
-- using (true);
|
||||
create policy "authenticated_select"
|
||||
on "public"."connected_online_services"
|
||||
as permissive
|
||||
for select
|
||||
to authenticated
|
||||
using (true);
|
||||
|
||||
|
||||
-- create policy "own_all"
|
||||
-- on "public"."connected_online_reservation"
|
||||
-- as permissive
|
||||
-- for all
|
||||
-- to authenticated
|
||||
-- using ((( SELECT auth.uid() AS uid) = user_id));
|
||||
create policy "own_all"
|
||||
on "public"."connected_online_reservation"
|
||||
as permissive
|
||||
for all
|
||||
to authenticated
|
||||
using ((( SELECT auth.uid() AS uid) = user_id));
|
||||
@@ -1,225 +1,225 @@
|
||||
|
||||
-- create table "public"."medreport_product_groups" (
|
||||
-- "id" bigint generated by default as identity not null,
|
||||
-- "name" text not null,
|
||||
-- "created_at" timestamp with time zone not null default now(),
|
||||
-- "updated_at" timestamp with time zone
|
||||
-- );
|
||||
create table "public"."medreport_product_groups" (
|
||||
"id" bigint generated by default as identity not null,
|
||||
"name" text not null,
|
||||
"created_at" timestamp with time zone not null default now(),
|
||||
"updated_at" timestamp with time zone
|
||||
);
|
||||
|
||||
-- create table "public"."medreport_products" (
|
||||
-- "id" bigint generated by default as identity not null,
|
||||
-- "name" text not null,
|
||||
-- "product_group_id" bigint,
|
||||
-- "created_at" timestamp with time zone not null default now(),
|
||||
-- "updated_at" timestamp with time zone default now()
|
||||
-- );
|
||||
create table "public"."medreport_products" (
|
||||
"id" bigint generated by default as identity not null,
|
||||
"name" text not null,
|
||||
"product_group_id" bigint,
|
||||
"created_at" timestamp with time zone not null default now(),
|
||||
"updated_at" timestamp with time zone default now()
|
||||
);
|
||||
|
||||
|
||||
-- alter table "public"."medreport_products" enable row level security;
|
||||
alter table "public"."medreport_products" enable row level security;
|
||||
|
||||
-- create table "public"."medreport_products_analyses_relations" (
|
||||
-- "product_id" bigint not null,
|
||||
-- "analysis_element_id" bigint,
|
||||
-- "analysis_id" bigint
|
||||
-- );
|
||||
create table "public"."medreport_products_analyses_relations" (
|
||||
"product_id" bigint not null,
|
||||
"analysis_element_id" bigint,
|
||||
"analysis_id" bigint
|
||||
);
|
||||
|
||||
-- alter table "public"."medreport_product_groups" enable row level security;
|
||||
alter table "public"."medreport_product_groups" enable row level security;
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" enable row level security;
|
||||
alter table "public"."medreport_products_analyses_relations" enable row level security;
|
||||
|
||||
-- CREATE UNIQUE INDEX medreport_product_groups_name_key ON public.medreport_product_groups USING btree (name);
|
||||
CREATE UNIQUE INDEX medreport_product_groups_name_key ON public.medreport_product_groups USING btree (name);
|
||||
|
||||
-- CREATE UNIQUE INDEX medreport_product_groups_pkey ON public.medreport_product_groups USING btree (id);
|
||||
CREATE UNIQUE INDEX medreport_product_groups_pkey ON public.medreport_product_groups USING btree (id);
|
||||
|
||||
-- alter table "public"."medreport_product_groups" add constraint "medreport_product_groups_pkey" PRIMARY KEY using index "medreport_product_groups_pkey";
|
||||
alter table "public"."medreport_product_groups" add constraint "medreport_product_groups_pkey" PRIMARY KEY using index "medreport_product_groups_pkey";
|
||||
|
||||
-- alter table "public"."medreport_product_groups" add constraint "medreport_product_groups_name_key" UNIQUE using index "medreport_product_groups_name_key";
|
||||
alter table "public"."medreport_product_groups" add constraint "medreport_product_groups_name_key" UNIQUE using index "medreport_product_groups_name_key";
|
||||
|
||||
-- alter table "public"."medreport_products" add constraint "medreport_products_product_groups_id_fkey" FOREIGN KEY (product_group_id) REFERENCES medreport_product_groups(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
alter table "public"."medreport_products" add constraint "medreport_products_product_groups_id_fkey" FOREIGN KEY (product_group_id) REFERENCES medreport_product_groups(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
|
||||
-- alter table "public"."medreport_products" validate constraint "medreport_products_product_groups_id_fkey";
|
||||
alter table "public"."medreport_products" validate constraint "medreport_products_product_groups_id_fkey";
|
||||
|
||||
-- grant select on table "public"."medreport_product_groups" to "anon";
|
||||
grant select on table "public"."medreport_product_groups" to "anon";
|
||||
|
||||
-- grant select on table "public"."medreport_product_groups" to "authenticated";
|
||||
grant select on table "public"."medreport_product_groups" to "authenticated";
|
||||
|
||||
-- grant delete on table "public"."medreport_product_groups" to "service_role";
|
||||
grant delete on table "public"."medreport_product_groups" to "service_role";
|
||||
|
||||
-- grant insert on table "public"."medreport_product_groups" to "service_role";
|
||||
grant insert on table "public"."medreport_product_groups" to "service_role";
|
||||
|
||||
-- grant references on table "public"."medreport_product_groups" to "service_role";
|
||||
grant references on table "public"."medreport_product_groups" to "service_role";
|
||||
|
||||
-- grant select on table "public"."medreport_product_groups" to "service_role";
|
||||
grant select on table "public"."medreport_product_groups" to "service_role";
|
||||
|
||||
-- grant trigger on table "public"."medreport_product_groups" to "service_role";
|
||||
grant trigger on table "public"."medreport_product_groups" to "service_role";
|
||||
|
||||
-- grant truncate on table "public"."medreport_product_groups" to "service_role";
|
||||
grant truncate on table "public"."medreport_product_groups" to "service_role";
|
||||
|
||||
-- grant update on table "public"."medreport_product_groups" to "service_role";
|
||||
grant update on table "public"."medreport_product_groups" to "service_role";
|
||||
|
||||
-- CREATE UNIQUE INDEX medreport_products_analyses_analysis_element_id_key ON public.medreport_products_analyses_relations USING btree (analysis_element_id);
|
||||
CREATE UNIQUE INDEX medreport_products_analyses_analysis_element_id_key ON public.medreport_products_analyses_relations USING btree (analysis_element_id);
|
||||
|
||||
-- CREATE UNIQUE INDEX medreport_products_analyses_analysis_id_key ON public.medreport_products_analyses_relations USING btree (analysis_id);
|
||||
CREATE UNIQUE INDEX medreport_products_analyses_analysis_id_key ON public.medreport_products_analyses_relations USING btree (analysis_id);
|
||||
|
||||
-- CREATE UNIQUE INDEX medreport_products_analyses_pkey ON public.medreport_products_analyses_relations USING btree (product_id);
|
||||
CREATE UNIQUE INDEX medreport_products_analyses_pkey ON public.medreport_products_analyses_relations USING btree (product_id);
|
||||
|
||||
-- CREATE UNIQUE INDEX medreport_products_name_key ON public.medreport_products USING btree (name);
|
||||
CREATE UNIQUE INDEX medreport_products_name_key ON public.medreport_products USING btree (name);
|
||||
|
||||
-- CREATE UNIQUE INDEX medreport_products_pkey ON public.medreport_products USING btree (id);
|
||||
CREATE UNIQUE INDEX medreport_products_pkey ON public.medreport_products USING btree (id);
|
||||
|
||||
-- alter table "public"."medreport_products" add constraint "medreport_products_pkey" PRIMARY KEY using index "medreport_products_pkey";
|
||||
alter table "public"."medreport_products" add constraint "medreport_products_pkey" PRIMARY KEY using index "medreport_products_pkey";
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_pkey" PRIMARY KEY using index "medreport_products_analyses_pkey";
|
||||
alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_pkey" PRIMARY KEY using index "medreport_products_analyses_pkey";
|
||||
|
||||
-- alter table "public"."medreport_products" add constraint "medreport_products_name_key" UNIQUE using index "medreport_products_name_key";
|
||||
alter table "public"."medreport_products" add constraint "medreport_products_name_key" UNIQUE using index "medreport_products_name_key";
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_analysis_element_id_fkey" FOREIGN KEY (analysis_element_id) REFERENCES analysis_elements(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_analysis_element_id_fkey" FOREIGN KEY (analysis_element_id) REFERENCES analysis_elements(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" validate constraint "medreport_products_analyses_analysis_element_id_fkey";
|
||||
alter table "public"."medreport_products_analyses_relations" validate constraint "medreport_products_analyses_analysis_element_id_fkey";
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_analysis_element_id_key" UNIQUE using index "medreport_products_analyses_analysis_element_id_key";
|
||||
alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_analysis_element_id_key" UNIQUE using index "medreport_products_analyses_analysis_element_id_key";
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_analysis_id_fkey" FOREIGN KEY (analysis_id) REFERENCES analyses(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_analysis_id_fkey" FOREIGN KEY (analysis_id) REFERENCES analyses(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" validate constraint "medreport_products_analyses_analysis_id_fkey";
|
||||
alter table "public"."medreport_products_analyses_relations" validate constraint "medreport_products_analyses_analysis_id_fkey";
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_analysis_id_key" UNIQUE using index "medreport_products_analyses_analysis_id_key";
|
||||
alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_analysis_id_key" UNIQUE using index "medreport_products_analyses_analysis_id_key";
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_product_id_fkey" FOREIGN KEY (product_id) REFERENCES medreport_products(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
alter table "public"."medreport_products_analyses_relations" add constraint "medreport_products_analyses_product_id_fkey" FOREIGN KEY (product_id) REFERENCES medreport_products(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" validate constraint "medreport_products_analyses_product_id_fkey";
|
||||
alter table "public"."medreport_products_analyses_relations" validate constraint "medreport_products_analyses_product_id_fkey";
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" add constraint "product_can_be_tied_to_only_one_external_item" CHECK (((analysis_id IS NULL) OR (analysis_element_id IS NULL))) not valid;
|
||||
alter table "public"."medreport_products_analyses_relations" add constraint "product_can_be_tied_to_only_one_external_item" CHECK (((analysis_id IS NULL) OR (analysis_element_id IS NULL))) not valid;
|
||||
|
||||
-- alter table "public"."medreport_products_analyses_relations" validate constraint "product_can_be_tied_to_only_one_external_item";
|
||||
alter table "public"."medreport_products_analyses_relations" validate constraint "product_can_be_tied_to_only_one_external_item";
|
||||
|
||||
-- grant select on table "public"."medreport_products" to "anon";
|
||||
grant select on table "public"."medreport_products" to "anon";
|
||||
|
||||
-- grant select on table "public"."medreport_products" to "authenticated";
|
||||
grant select on table "public"."medreport_products" to "authenticated";
|
||||
|
||||
-- grant delete on table "public"."medreport_products" to "service_role";
|
||||
grant delete on table "public"."medreport_products" to "service_role";
|
||||
|
||||
-- grant insert on table "public"."medreport_products" to "service_role";
|
||||
grant insert on table "public"."medreport_products" to "service_role";
|
||||
|
||||
-- grant references on table "public"."medreport_products" to "service_role";
|
||||
grant references on table "public"."medreport_products" to "service_role";
|
||||
|
||||
-- grant select on table "public"."medreport_products" to "service_role";
|
||||
grant select on table "public"."medreport_products" to "service_role";
|
||||
|
||||
-- grant trigger on table "public"."medreport_products" to "service_role";
|
||||
grant trigger on table "public"."medreport_products" to "service_role";
|
||||
|
||||
-- grant truncate on table "public"."medreport_products" to "service_role";
|
||||
grant truncate on table "public"."medreport_products" to "service_role";
|
||||
|
||||
-- grant update on table "public"."medreport_products" to "service_role";
|
||||
grant update on table "public"."medreport_products" to "service_role";
|
||||
|
||||
-- grant select on table "public"."medreport_products_analyses_relations" to "anon";
|
||||
grant select on table "public"."medreport_products_analyses_relations" to "anon";
|
||||
|
||||
-- grant select on table "public"."medreport_products_analyses_relations" to "authenticated";
|
||||
grant select on table "public"."medreport_products_analyses_relations" to "authenticated";
|
||||
|
||||
-- grant delete on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
grant delete on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
|
||||
-- grant insert on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
grant insert on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
|
||||
-- grant references on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
grant references on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
|
||||
-- grant select on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
grant select on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
|
||||
-- grant trigger on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
grant trigger on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
|
||||
-- grant truncate on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
grant truncate on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
|
||||
-- grant update on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
grant update on table "public"."medreport_products_analyses_relations" to "service_role";
|
||||
|
||||
-- create policy "Enable read access for all users"
|
||||
-- on "public"."medreport_products_analyses_relations"
|
||||
-- as permissive
|
||||
-- for select
|
||||
-- to public
|
||||
-- using (true);
|
||||
create policy "Enable read access for all users"
|
||||
on "public"."medreport_products_analyses_relations"
|
||||
as permissive
|
||||
for select
|
||||
to public
|
||||
using (true);
|
||||
|
||||
|
||||
-- ALTER TABLE medreport_products_analyses_relations
|
||||
-- ADD CONSTRAINT product_can_be_tied_to_only_one_analysis_item
|
||||
-- CHECK (analysis_id IS NULL OR analysis_element_id IS NULL);
|
||||
ALTER TABLE medreport_products_analyses_relations
|
||||
ADD CONSTRAINT product_can_be_tied_to_only_one_analysis_item
|
||||
CHECK (analysis_id IS NULL OR analysis_element_id IS NULL);
|
||||
|
||||
|
||||
-- create table "public"."medreport_products_external_services_relations" (
|
||||
-- "product_id" bigint not null,
|
||||
-- "connected_online_service_id" bigint not null
|
||||
-- );
|
||||
create table "public"."medreport_products_external_services_relations" (
|
||||
"product_id" bigint not null,
|
||||
"connected_online_service_id" bigint not null
|
||||
);
|
||||
|
||||
-- alter table "public"."medreport_products_external_services_relations" enable row level security;
|
||||
alter table "public"."medreport_products_external_services_relations" enable row level security;
|
||||
|
||||
-- CREATE UNIQUE INDEX medreport_products_connected_online_services_id_key ON public.medreport_products_external_services_relations USING btree (connected_online_service_id);
|
||||
CREATE UNIQUE INDEX medreport_products_connected_online_services_id_key ON public.medreport_products_external_services_relations USING btree (connected_online_service_id);
|
||||
|
||||
-- CREATE UNIQUE INDEX medreport_products_connected_online_services_pkey ON public.medreport_products_external_services_relations USING btree (connected_online_service_id);
|
||||
CREATE UNIQUE INDEX medreport_products_connected_online_services_pkey ON public.medreport_products_external_services_relations USING btree (connected_online_service_id);
|
||||
|
||||
-- alter table "public"."medreport_products_external_services_relations" add constraint "medreport_products_connected_online_services_pkey" PRIMARY KEY using index "medreport_products_connected_online_services_pkey";
|
||||
alter table "public"."medreport_products_external_services_relations" add constraint "medreport_products_connected_online_services_pkey" PRIMARY KEY using index "medreport_products_connected_online_services_pkey";
|
||||
|
||||
-- alter table "public"."medreport_products_external_services_relations" add constraint "medreport_products_connected_online_services_id_fkey" FOREIGN KEY (connected_online_service_id) REFERENCES connected_online_services(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
alter table "public"."medreport_products_external_services_relations" add constraint "medreport_products_connected_online_services_id_fkey" FOREIGN KEY (connected_online_service_id) REFERENCES connected_online_services(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
|
||||
-- alter table "public"."medreport_products_external_services_relations" validate constraint "medreport_products_connected_online_services_id_fkey";
|
||||
alter table "public"."medreport_products_external_services_relations" validate constraint "medreport_products_connected_online_services_id_fkey";
|
||||
|
||||
-- alter table "public"."medreport_products_external_services_relations" add constraint "medreport_products_connected_online_services_id_key" UNIQUE using index "medreport_products_connected_online_services_id_key";
|
||||
alter table "public"."medreport_products_external_services_relations" add constraint "medreport_products_connected_online_services_id_key" UNIQUE using index "medreport_products_connected_online_services_id_key";
|
||||
|
||||
-- alter table "public"."medreport_products_external_services_relations" add constraint "medreport_products_connected_online_services_product_id_fkey" FOREIGN KEY (product_id) REFERENCES medreport_products(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
alter table "public"."medreport_products_external_services_relations" add constraint "medreport_products_connected_online_services_product_id_fkey" FOREIGN KEY (product_id) REFERENCES medreport_products(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
|
||||
|
||||
-- alter table "public"."medreport_products_external_services_relations" validate constraint "medreport_products_connected_online_services_product_id_fkey";
|
||||
alter table "public"."medreport_products_external_services_relations" validate constraint "medreport_products_connected_online_services_product_id_fkey";
|
||||
|
||||
-- grant select on table "public"."medreport_products_external_services_relations" to "anon";
|
||||
grant select on table "public"."medreport_products_external_services_relations" to "anon";
|
||||
|
||||
-- grant select on table "public"."medreport_products_external_services_relations" to "authenticated";
|
||||
grant select on table "public"."medreport_products_external_services_relations" to "authenticated";
|
||||
|
||||
-- grant delete on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
grant delete on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
|
||||
-- grant insert on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
grant insert on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
|
||||
-- grant references on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
grant references on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
|
||||
-- grant select on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
grant select on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
|
||||
-- grant trigger on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
grant trigger on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
|
||||
-- grant truncate on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
grant truncate on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
|
||||
-- grant update on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
grant update on table "public"."medreport_products_external_services_relations" to "service_role";
|
||||
|
||||
-- CREATE OR REPLACE FUNCTION check_tied_to_connected_online()
|
||||
-- RETURNS TRIGGER AS $$
|
||||
-- BEGIN
|
||||
-- IF EXISTS (
|
||||
-- SELECT 1
|
||||
-- FROM medreport_products_external_services_relations
|
||||
-- WHERE product_id = NEW.product_id
|
||||
-- ) THEN
|
||||
-- RAISE EXCEPTION 'Value "%" already exists in medreport_products_external_services_relations', NEW.product_id;
|
||||
-- END IF;
|
||||
CREATE OR REPLACE FUNCTION check_tied_to_connected_online()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM medreport_products_external_services_relations
|
||||
WHERE product_id = NEW.product_id
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Value "%" already exists in medreport_products_external_services_relations', NEW.product_id;
|
||||
END IF;
|
||||
|
||||
-- RETURN NEW;
|
||||
-- END;
|
||||
-- $$ LANGUAGE plpgsql;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- CREATE OR REPLACE FUNCTION check_tied_to_analysis_item()
|
||||
-- RETURNS TRIGGER AS $$
|
||||
-- BEGIN
|
||||
-- IF EXISTS (
|
||||
-- SELECT 1
|
||||
-- FROM medreport_products_analyses_relations
|
||||
-- WHERE product_id = NEW.product_id
|
||||
-- ) THEN
|
||||
-- RAISE EXCEPTION 'Value "%" already exists in medreport_products_analyses_relations', NEW.product_id;
|
||||
-- END IF;
|
||||
CREATE OR REPLACE FUNCTION check_tied_to_analysis_item()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM medreport_products_analyses_relations
|
||||
WHERE product_id = NEW.product_id
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Value "%" already exists in medreport_products_analyses_relations', NEW.product_id;
|
||||
END IF;
|
||||
|
||||
-- RETURN NEW;
|
||||
-- END;
|
||||
-- $$ LANGUAGE plpgsql;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- CREATE TRIGGER check_not_already_tied_to_connected_online BEFORE INSERT OR UPDATE ON public.medreport_products_analyses_relations FOR EACH ROW EXECUTE FUNCTION check_tied_to_connected_online();
|
||||
CREATE TRIGGER check_not_already_tied_to_connected_online BEFORE INSERT OR UPDATE ON public.medreport_products_analyses_relations FOR EACH ROW EXECUTE FUNCTION check_tied_to_connected_online();
|
||||
|
||||
-- CREATE TRIGGER check_not_already_tied_to_analysis BEFORE INSERT OR UPDATE ON public.medreport_products_external_services_relations FOR EACH ROW EXECUTE FUNCTION check_tied_to_analysis_item();
|
||||
CREATE TRIGGER check_not_already_tied_to_analysis BEFORE INSERT OR UPDATE ON public.medreport_products_external_services_relations FOR EACH ROW EXECUTE FUNCTION check_tied_to_analysis_item();
|
||||
|
||||
-- create policy "read_all"
|
||||
-- on "public"."medreport_product_groups"
|
||||
-- as permissive
|
||||
-- for select
|
||||
-- to public
|
||||
-- using (true);
|
||||
create policy "read_all"
|
||||
on "public"."medreport_product_groups"
|
||||
as permissive
|
||||
for select
|
||||
to public
|
||||
using (true);
|
||||
|
||||
@@ -680,17 +680,17 @@ drop policy "accounts_self_update" on "public"."accounts";
|
||||
|
||||
drop policy "create_org_account" on "public"."accounts";
|
||||
|
||||
-- drop policy "restrict_mfa_accounts" on "public"."accounts";
|
||||
drop policy "restrict_mfa_accounts" on "public"."accounts";
|
||||
|
||||
-- drop policy "super_admins_access_accounts" on "public"."accounts";
|
||||
drop policy "super_admins_access_accounts" on "public"."accounts";
|
||||
|
||||
drop policy "accounts_memberships_delete" on "public"."accounts_memberships";
|
||||
|
||||
drop policy "accounts_memberships_read" on "public"."accounts_memberships";
|
||||
|
||||
-- drop policy "restrict_mfa_accounts_memberships" on "public"."accounts_memberships";
|
||||
drop policy "restrict_mfa_accounts_memberships" on "public"."accounts_memberships";
|
||||
|
||||
-- drop policy "super_admins_access_accounts_memberships" on "public"."accounts_memberships";
|
||||
drop policy "super_admins_access_accounts_memberships" on "public"."accounts_memberships";
|
||||
|
||||
drop policy "analysis_all" on "public"."analyses";
|
||||
|
||||
@@ -742,53 +742,53 @@ drop policy "invitations_read_self" on "public"."invitations";
|
||||
|
||||
drop policy "invitations_update" on "public"."invitations";
|
||||
|
||||
-- drop policy "restrict_mfa_invitations" on "public"."invitations";
|
||||
drop policy "restrict_mfa_invitations" on "public"."invitations";
|
||||
|
||||
-- drop policy "super_admins_access_invitations" on "public"."invitations";
|
||||
drop policy "super_admins_access_invitations" on "public"."invitations";
|
||||
|
||||
drop policy "read_all" on "public"."medreport_product_groups";
|
||||
|
||||
drop policy "Enable read access for all users" on "public"."medreport_products_analyses_relations";
|
||||
|
||||
-- drop policy "Users can read their own nonces" on "public"."nonces";
|
||||
drop policy "Users can read their own nonces" on "public"."nonces";
|
||||
|
||||
drop policy "notifications_read_self" on "public"."notifications";
|
||||
|
||||
drop policy "notifications_update_self" on "public"."notifications";
|
||||
|
||||
-- drop policy "restrict_mfa_notifications" on "public"."notifications";
|
||||
drop policy "restrict_mfa_notifications" on "public"."notifications";
|
||||
|
||||
drop policy "order_items_read_self" on "public"."order_items";
|
||||
|
||||
-- drop policy "restrict_mfa_order_items" on "public"."order_items";
|
||||
drop policy "restrict_mfa_order_items" on "public"."order_items";
|
||||
|
||||
-- drop policy "super_admins_access_order_items" on "public"."order_items";
|
||||
drop policy "super_admins_access_order_items" on "public"."order_items";
|
||||
|
||||
drop policy "orders_read_self" on "public"."orders";
|
||||
|
||||
-- drop policy "restrict_mfa_orders" on "public"."orders";
|
||||
drop policy "restrict_mfa_orders" on "public"."orders";
|
||||
|
||||
-- drop policy "super_admins_access_orders" on "public"."orders";
|
||||
drop policy "super_admins_access_orders" on "public"."orders";
|
||||
|
||||
-- drop policy "restrict_mfa_role_permissions" on "public"."role_permissions";
|
||||
drop policy "restrict_mfa_role_permissions" on "public"."role_permissions";
|
||||
|
||||
drop policy "role_permissions_read" on "public"."role_permissions";
|
||||
|
||||
-- drop policy "super_admins_access_role_permissions" on "public"."role_permissions";
|
||||
drop policy "super_admins_access_role_permissions" on "public"."role_permissions";
|
||||
|
||||
drop policy "roles_read" on "public"."roles";
|
||||
|
||||
-- drop policy "restrict_mfa_subscription_items" on "public"."subscription_items";
|
||||
drop policy "restrict_mfa_subscription_items" on "public"."subscription_items";
|
||||
|
||||
drop policy "subscription_items_read_self" on "public"."subscription_items";
|
||||
|
||||
-- drop policy "super_admins_access_subscription_items" on "public"."subscription_items";
|
||||
drop policy "super_admins_access_subscription_items" on "public"."subscription_items";
|
||||
|
||||
-- drop policy "restrict_mfa_subscriptions" on "public"."subscriptions";
|
||||
drop policy "restrict_mfa_subscriptions" on "public"."subscriptions";
|
||||
|
||||
drop policy "subscriptions_read_self" on "public"."subscriptions";
|
||||
|
||||
-- drop policy "super_admins_access_subscriptions" on "public"."subscriptions";
|
||||
drop policy "super_admins_access_subscriptions" on "public"."subscriptions";
|
||||
|
||||
alter table "public"."accounts" drop constraint "accounts_created_by_fkey";
|
||||
|
||||
@@ -888,7 +888,7 @@ alter table "public"."medreport_products_analyses_relations" drop constraint "pr
|
||||
|
||||
alter table "public"."medreport_products_analyses_relations" drop constraint "product_can_be_tied_to_only_one_external_item";
|
||||
|
||||
-- alter table "public"."nonces" drop constraint "nonces_user_id_fkey";
|
||||
alter table "public"."nonces" drop constraint "nonces_user_id_fkey";
|
||||
|
||||
alter table "public"."notifications" drop constraint "notifications_account_id_fkey";
|
||||
|
||||
@@ -956,7 +956,7 @@ alter table "public"."medreport_products_analyses_relations" drop constraint "me
|
||||
|
||||
alter table "public"."medreport_products_external_services_relations" drop constraint "medreport_products_connected_online_services_pkey";
|
||||
|
||||
-- alter table "public"."nonces" drop constraint "nonces_pkey";
|
||||
alter table "public"."nonces" drop constraint "nonces_pkey";
|
||||
|
||||
alter table "public"."notifications" drop constraint "notifications_pkey";
|
||||
|
||||
@@ -1876,11 +1876,12 @@ BEGIN
|
||||
END;$function$
|
||||
;
|
||||
|
||||
CREATE OR REPLACE FUNCTION medreport.create_team_account(account_name text)
|
||||
RETURNS medreport.accounts
|
||||
LANGUAGE plpgsql
|
||||
SET search_path TO ''
|
||||
AS $function$declare
|
||||
create
|
||||
or replace function medreport.create_team_account (account_name text) returns medreport.accounts
|
||||
SECURITY DEFINER
|
||||
set
|
||||
search_path = '' as $$
|
||||
declare
|
||||
new_account medreport.accounts;
|
||||
begin
|
||||
if (not medreport.is_set('enable_team_accounts')) then
|
||||
@@ -1898,8 +1899,13 @@ begin
|
||||
|
||||
return new_account;
|
||||
|
||||
end;$function$
|
||||
;
|
||||
end;
|
||||
|
||||
$$ language plpgsql;
|
||||
|
||||
grant
|
||||
execute on function medreport.create_team_account (text) to authenticated,
|
||||
service_role;
|
||||
|
||||
CREATE OR REPLACE FUNCTION medreport.get_account_invitations(account_slug text)
|
||||
RETURNS TABLE(id integer, email character varying, account_id uuid, invited_by uuid, role character varying, created_at timestamp with time zone, updated_at timestamp with time zone, expires_at timestamp with time zone, inviter_name character varying, inviter_email character varying)
|
||||
@@ -3893,29 +3899,43 @@ to authenticated
|
||||
using ((account_id = auth.uid()));
|
||||
|
||||
|
||||
create policy "accounts_read"
|
||||
on "medreport"."accounts"
|
||||
as permissive
|
||||
for select
|
||||
to authenticated
|
||||
using (((( SELECT auth.uid() AS uid) = primary_owner_user_id) OR medreport.has_role_on_account(id) OR medreport.is_account_team_member(id)));
|
||||
create policy accounts_read on medreport.accounts for
|
||||
select
|
||||
to authenticated using (
|
||||
(
|
||||
(
|
||||
select
|
||||
auth.uid ()
|
||||
) = primary_owner_user_id
|
||||
)
|
||||
or medreport.has_role_on_account (id)
|
||||
or medreport.is_account_team_member (id)
|
||||
);
|
||||
|
||||
|
||||
create policy "accounts_self_update"
|
||||
on "medreport"."accounts"
|
||||
as permissive
|
||||
for update
|
||||
to authenticated
|
||||
using ((( SELECT auth.uid() AS uid) = primary_owner_user_id))
|
||||
with check ((( SELECT auth.uid() AS uid) = primary_owner_user_id));
|
||||
create policy accounts_self_update on medreport.accounts
|
||||
for update
|
||||
to authenticated using (
|
||||
(
|
||||
select
|
||||
auth.uid ()
|
||||
) = primary_owner_user_id
|
||||
)
|
||||
with
|
||||
check (
|
||||
(
|
||||
select
|
||||
auth.uid ()
|
||||
) = primary_owner_user_id
|
||||
);
|
||||
|
||||
|
||||
create policy "create_org_account"
|
||||
on "medreport"."accounts"
|
||||
as permissive
|
||||
for insert
|
||||
to authenticated
|
||||
with check ((medreport.is_set('enable_team_accounts'::text) AND (is_personal_account = false)));
|
||||
create policy create_org_account on medreport.accounts for insert to authenticated
|
||||
with
|
||||
check (
|
||||
medreport.is_set ('enable_team_accounts')
|
||||
and is_personal_account = false
|
||||
);
|
||||
|
||||
|
||||
create policy "restrict_mfa_accounts"
|
||||
@@ -5160,47 +5180,47 @@ revoke truncate on table "public"."medreport_products_external_services_relation
|
||||
|
||||
revoke update on table "public"."medreport_products_external_services_relations" from "service_role";
|
||||
|
||||
-- revoke delete on table "public"."nonces" from "anon";
|
||||
revoke delete on table "public"."nonces" from "anon";
|
||||
|
||||
-- revoke insert on table "public"."nonces" from "anon";
|
||||
revoke insert on table "public"."nonces" from "anon";
|
||||
|
||||
-- revoke references on table "public"."nonces" from "anon";
|
||||
revoke references on table "public"."nonces" from "anon";
|
||||
|
||||
-- revoke select on table "public"."nonces" from "anon";
|
||||
revoke select on table "public"."nonces" from "anon";
|
||||
|
||||
-- revoke trigger on table "public"."nonces" from "anon";
|
||||
revoke trigger on table "public"."nonces" from "anon";
|
||||
|
||||
-- revoke truncate on table "public"."nonces" from "anon";
|
||||
revoke truncate on table "public"."nonces" from "anon";
|
||||
|
||||
-- revoke update on table "public"."nonces" from "anon";
|
||||
revoke update on table "public"."nonces" from "anon";
|
||||
|
||||
-- revoke delete on table "public"."nonces" from "authenticated";
|
||||
revoke delete on table "public"."nonces" from "authenticated";
|
||||
|
||||
-- revoke insert on table "public"."nonces" from "authenticated";
|
||||
revoke insert on table "public"."nonces" from "authenticated";
|
||||
|
||||
-- revoke references on table "public"."nonces" from "authenticated";
|
||||
revoke references on table "public"."nonces" from "authenticated";
|
||||
|
||||
-- revoke select on table "public"."nonces" from "authenticated";
|
||||
revoke select on table "public"."nonces" from "authenticated";
|
||||
|
||||
-- revoke trigger on table "public"."nonces" from "authenticated";
|
||||
revoke trigger on table "public"."nonces" from "authenticated";
|
||||
|
||||
-- revoke truncate on table "public"."nonces" from "authenticated";
|
||||
revoke truncate on table "public"."nonces" from "authenticated";
|
||||
|
||||
-- revoke update on table "public"."nonces" from "authenticated";
|
||||
revoke update on table "public"."nonces" from "authenticated";
|
||||
|
||||
-- revoke delete on table "public"."nonces" from "service_role";
|
||||
revoke delete on table "public"."nonces" from "service_role";
|
||||
|
||||
-- revoke insert on table "public"."nonces" from "service_role";
|
||||
revoke insert on table "public"."nonces" from "service_role";
|
||||
|
||||
-- revoke references on table "public"."nonces" from "service_role";
|
||||
revoke references on table "public"."nonces" from "service_role";
|
||||
|
||||
-- revoke select on table "public"."nonces" from "service_role";
|
||||
revoke select on table "public"."nonces" from "service_role";
|
||||
|
||||
-- revoke trigger on table "public"."nonces" from "service_role";
|
||||
revoke trigger on table "public"."nonces" from "service_role";
|
||||
|
||||
-- revoke truncate on table "public"."nonces" from "service_role";
|
||||
revoke truncate on table "public"."nonces" from "service_role";
|
||||
|
||||
-- revoke update on table "public"."nonces" from "service_role";
|
||||
revoke update on table "public"."nonces" from "service_role";
|
||||
|
||||
revoke delete on table "public"."notifications" from "anon";
|
||||
|
||||
@@ -5410,7 +5430,7 @@ drop table "public"."medreport_products_analyses_relations";
|
||||
|
||||
drop table "public"."medreport_products_external_services_relations";
|
||||
|
||||
-- drop table "public"."nonces";
|
||||
drop table "public"."nonces";
|
||||
|
||||
drop table "public"."notifications";
|
||||
|
||||
|
||||
@@ -40,4 +40,8 @@ END;$function$
|
||||
grant execute on function medreport.has_consent_personal_data(uuid)
|
||||
to authenticated, anon;
|
||||
|
||||
-- we allow the authenticated role to execute functions in the medreport schema
|
||||
grant usage on schema medreport to authenticated;
|
||||
|
||||
-- we allow the service_role role to execute functions in the medreport schema
|
||||
grant usage on schema medreport to service_role;
|
||||
@@ -1 +1 @@
|
||||
alter type public.billing_provider add value 'montonio';
|
||||
alter type medreport.billing_provider add value 'montonio';
|
||||
|
||||
32
supabase/migrations/20250722110506_super_admin_fix.sql
Normal file
32
supabase/migrations/20250722110506_super_admin_fix.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
grant
|
||||
execute on function medreport.get_account_members (text) to authenticated,
|
||||
service_role;
|
||||
|
||||
create or replace function medreport.is_company_admin(account_slug text)
|
||||
returns boolean
|
||||
set search_path = ''
|
||||
language plpgsql
|
||||
as $$
|
||||
declare
|
||||
is_owner boolean;
|
||||
begin
|
||||
select exists (
|
||||
select 1
|
||||
from medreport.accounts_memberships am
|
||||
join medreport.accounts a on a.id = am.account_id
|
||||
where am.user_id = auth.uid()
|
||||
and am.account_role = 'owner'
|
||||
and a.slug = account_slug
|
||||
) into is_owner;
|
||||
|
||||
return is_owner;
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function medreport.is_company_admin(text) to authenticated, service_role;
|
||||
|
||||
grant
|
||||
execute on function medreport.team_account_workspace (text) to authenticated,
|
||||
service_role;
|
||||
|
||||
grant execute on function medreport.get_account_invitations(text) to authenticated, service_role;
|
||||
67
supabase/migrations/20250723114200_company_params.sql
Normal file
67
supabase/migrations/20250723114200_company_params.sql
Normal file
@@ -0,0 +1,67 @@
|
||||
create table "medreport"."company_params" (
|
||||
"id" uuid not null default gen_random_uuid(),
|
||||
"benefit_occurance" text,
|
||||
"benefit_amount" numeric,
|
||||
"account_id" uuid,
|
||||
"created_at" timestamp with time zone default now(),
|
||||
"updated_at" timestamp with time zone default now(),
|
||||
"slug" text
|
||||
);
|
||||
|
||||
alter table "medreport"."company_params" enable row level security;
|
||||
|
||||
CREATE UNIQUE INDEX company_params_pkey ON medreport.company_params USING btree (id);
|
||||
|
||||
alter table "medreport"."company_params" add constraint "company_params_pkey" PRIMARY KEY using index "company_params_pkey";
|
||||
|
||||
alter table "medreport"."company_params" add constraint "company_params_account_id_fkey" FOREIGN KEY (account_id) REFERENCES medreport.accounts(id) ON DELETE CASCADE not valid;
|
||||
|
||||
alter table "medreport"."company_params" validate constraint "company_params_account_id_fkey";
|
||||
|
||||
set check_function_bodies = off;
|
||||
|
||||
CREATE OR REPLACE FUNCTION medreport.insert_company_params_on_new_company()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$begin
|
||||
insert into medreport.company_params (
|
||||
account_id,
|
||||
slug,
|
||||
benefit_occurance,
|
||||
benefit_amount
|
||||
) values (
|
||||
new.id,
|
||||
new.slug,
|
||||
null, -- or a default value like 'monthly'
|
||||
null -- or a default numeric like 0
|
||||
);
|
||||
return new;
|
||||
end;$function$
|
||||
;
|
||||
|
||||
grant execute on function medreport.insert_company_params_on_new_company() to authenticated,
|
||||
service_role;
|
||||
|
||||
CREATE TRIGGER trigger_create_company_params AFTER INSERT ON medreport.accounts FOR EACH ROW EXECUTE FUNCTION medreport.insert_company_params_on_new_company();
|
||||
|
||||
create policy "Allow select and update if user is account's primary owner"
|
||||
on medreport.company_params
|
||||
for all
|
||||
using (
|
||||
exists (
|
||||
select 1 from medreport.accounts
|
||||
where
|
||||
accounts.id = company_params.account_id
|
||||
and accounts.primary_owner_user_id = auth.uid()
|
||||
)
|
||||
)
|
||||
with check (
|
||||
exists (
|
||||
select 1 from medreport.accounts
|
||||
where
|
||||
accounts.id = company_params.account_id
|
||||
and accounts.primary_owner_user_id = auth.uid()
|
||||
)
|
||||
);
|
||||
|
||||
grant select, update on medreport.company_params to authenticated;
|
||||
16
supabase/sql/super-admin.sql
Normal file
16
supabase/sql/super-admin.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
-- Update your user role to Super Admin
|
||||
update auth.users set raw_app_meta_data='{"provider": "email", "providers": ["email"], "role": "super-admin" }' where email='test2@test.ee';
|
||||
|
||||
-- To create a new company user you need rows in Roles table
|
||||
INSERT INTO medreport.roles (name, hierarchy_level)
|
||||
VALUES
|
||||
('owner', 1),
|
||||
('member', 2);
|
||||
|
||||
-- Add role permissions
|
||||
insert into medreport.role_permissions (role, permission) values
|
||||
('owner', 'roles.manage'),
|
||||
('owner', 'billing.manage'),
|
||||
('owner', 'settings.manage'),
|
||||
('owner', 'members.manage'),
|
||||
('owner', 'invites.manage');
|
||||
Reference in New Issue
Block a user