move product_id to medusa_product_id, make all product relations one-to-one (#30)

Co-authored-by: Helena <helena@Helenas-MacBook-Pro.local>
This commit is contained in:
Helena
2025-07-04 14:33:23 +03:00
committed by GitHub
parent ad08155063
commit 848dbb1618
2 changed files with 343 additions and 1 deletions

View File

@@ -0,0 +1,342 @@
drop trigger if exists "check_not_already_tied_to_connected_online" on "public"."medreport_products_analyses_relations";
drop trigger if exists "check_not_already_tied_to_analysis" on "public"."medreport_products_external_services_relations";
drop policy "read_all" on "public"."medreport_product_groups";
drop policy "Enable read access for all users" on "public"."medreport_products_analyses_relations";
revoke delete on table "public"."medreport_product_groups" from "anon";
revoke insert on table "public"."medreport_product_groups" from "anon";
revoke references on table "public"."medreport_product_groups" from "anon";
revoke select on table "public"."medreport_product_groups" from "anon";
revoke trigger on table "public"."medreport_product_groups" from "anon";
revoke truncate on table "public"."medreport_product_groups" from "anon";
revoke update on table "public"."medreport_product_groups" from "anon";
revoke delete on table "public"."medreport_product_groups" from "authenticated";
revoke insert on table "public"."medreport_product_groups" from "authenticated";
revoke references on table "public"."medreport_product_groups" from "authenticated";
revoke select on table "public"."medreport_product_groups" from "authenticated";
revoke trigger on table "public"."medreport_product_groups" from "authenticated";
revoke truncate on table "public"."medreport_product_groups" from "authenticated";
revoke update on table "public"."medreport_product_groups" from "authenticated";
revoke delete on table "public"."medreport_product_groups" from "service_role";
revoke insert on table "public"."medreport_product_groups" from "service_role";
revoke references on table "public"."medreport_product_groups" from "service_role";
revoke select on table "public"."medreport_product_groups" from "service_role";
revoke trigger on table "public"."medreport_product_groups" from "service_role";
revoke truncate on table "public"."medreport_product_groups" from "service_role";
revoke update on table "public"."medreport_product_groups" from "service_role";
revoke delete on table "public"."medreport_products_analyses_relations" from "anon";
revoke insert on table "public"."medreport_products_analyses_relations" from "anon";
revoke references on table "public"."medreport_products_analyses_relations" from "anon";
revoke select on table "public"."medreport_products_analyses_relations" from "anon";
revoke trigger on table "public"."medreport_products_analyses_relations" from "anon";
revoke truncate on table "public"."medreport_products_analyses_relations" from "anon";
revoke update on table "public"."medreport_products_analyses_relations" from "anon";
revoke delete on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke insert on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke references on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke select on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke trigger on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke truncate on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke update on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke delete on table "public"."medreport_products_analyses_relations" from "service_role";
revoke insert on table "public"."medreport_products_analyses_relations" from "service_role";
revoke references on table "public"."medreport_products_analyses_relations" from "service_role";
revoke select on table "public"."medreport_products_analyses_relations" from "service_role";
revoke trigger on table "public"."medreport_products_analyses_relations" from "service_role";
revoke truncate on table "public"."medreport_products_analyses_relations" from "service_role";
revoke update on table "public"."medreport_products_analyses_relations" from "service_role";
revoke delete on table "public"."medreport_products_external_services_relations" from "anon";
revoke insert on table "public"."medreport_products_external_services_relations" from "anon";
revoke references on table "public"."medreport_products_external_services_relations" from "anon";
revoke select on table "public"."medreport_products_external_services_relations" from "anon";
revoke trigger on table "public"."medreport_products_external_services_relations" from "anon";
revoke truncate on table "public"."medreport_products_external_services_relations" from "anon";
revoke update on table "public"."medreport_products_external_services_relations" from "anon";
revoke delete on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke insert on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke references on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke select on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke trigger on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke truncate on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke update on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke delete on table "public"."medreport_products_external_services_relations" from "service_role";
revoke insert on table "public"."medreport_products_external_services_relations" from "service_role";
revoke references on table "public"."medreport_products_external_services_relations" from "service_role";
revoke select on table "public"."medreport_products_external_services_relations" from "service_role";
revoke trigger on table "public"."medreport_products_external_services_relations" from "service_role";
revoke truncate on table "public"."medreport_products_external_services_relations" from "service_role";
revoke update on table "public"."medreport_products_external_services_relations" from "service_role";
alter table "public"."medreport_product_groups" drop constraint "medreport_product_groups_name_key";
alter table "public"."medreport_products" drop constraint "medreport_products_product_groups_id_fkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_analysis_element_id_fkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_analysis_element_id_key";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_analysis_id_fkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_analysis_id_key";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_product_id_fkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "product_can_be_tied_to_only_one_analysis_item";
alter table "public"."medreport_products_analyses_relations" drop constraint "product_can_be_tied_to_only_one_external_item";
alter table "public"."medreport_products_external_services_relations" drop constraint "medreport_products_connected_online_services_id_fkey";
alter table "public"."medreport_products_external_services_relations" drop constraint "medreport_products_connected_online_services_id_key";
alter table "public"."medreport_products_external_services_relations" drop constraint "medreport_products_connected_online_services_product_id_fkey";
alter table "public"."medreport_product_groups" drop constraint "medreport_product_groups_pkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_pkey";
alter table "public"."medreport_products_external_services_relations" drop constraint "medreport_products_connected_online_services_pkey";
drop index if exists "public"."medreport_product_groups_name_key";
drop index if exists "public"."medreport_product_groups_pkey";
drop index if exists "public"."medreport_products_analyses_pkey";
drop index if exists "public"."medreport_products_analyses_analysis_element_id_key";
drop index if exists "public"."medreport_products_analyses_analysis_id_key";
drop index if exists "public"."medreport_products_connected_online_services_id_key";
drop index if exists "public"."medreport_products_connected_online_services_pkey";
drop table "public"."medreport_product_groups";
drop table "public"."medreport_products_analyses_relations";
drop table "public"."medreport_products_external_services_relations";
create table "public"."medusa_products_analyses_relations" (
"medusa_product_id" bigint not null,
"analysis_element_id" bigint,
"analysis_id" bigint
);
alter table "public"."medusa_products_analyses_relations" enable row level security;
create table "public"."medusa_products_external_services_relations" (
"medusa_product_id" bigint not null,
"connected_online_service_id" bigint not null
);
alter table "public"."medusa_products_external_services_relations" enable row level security;
CREATE UNIQUE INDEX medusa_products_analyses_relations_pkey ON public.medusa_products_analyses_relations USING btree (medusa_product_id);
CREATE UNIQUE INDEX medusa_products_external_services_relations_product_id_key ON public.medusa_products_external_services_relations USING btree (medusa_product_id);
CREATE UNIQUE INDEX medreport_products_analyses_analysis_element_id_key ON public.medusa_products_analyses_relations USING btree (analysis_element_id);
CREATE UNIQUE INDEX medreport_products_analyses_analysis_id_key ON public.medusa_products_analyses_relations USING btree (analysis_id);
CREATE UNIQUE INDEX medreport_products_connected_online_services_id_key ON public.medusa_products_external_services_relations USING btree (connected_online_service_id);
CREATE UNIQUE INDEX medreport_products_connected_online_services_pkey ON public.medusa_products_external_services_relations USING btree (connected_online_service_id);
alter table "public"."medusa_products_analyses_relations" add constraint "medusa_products_analyses_relations_pkey" PRIMARY KEY using index "medusa_products_analyses_relations_pkey";
alter table "public"."medusa_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"."medusa_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"."medusa_products_analyses_relations" validate constraint "medreport_products_analyses_analysis_element_id_fkey";
alter table "public"."medusa_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"."medusa_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"."medusa_products_analyses_relations" validate constraint "medreport_products_analyses_analysis_id_fkey";
alter table "public"."medusa_products_analyses_relations" add constraint "medreport_products_analyses_analysis_id_key" UNIQUE using index "medreport_products_analyses_analysis_id_key";
alter table "public"."medusa_products_analyses_relations" add constraint "medreport_products_analyses_product_id_fkey" FOREIGN KEY (medusa_product_id) REFERENCES medreport_products(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."medusa_products_analyses_relations" validate constraint "medreport_products_analyses_product_id_fkey";
alter table "public"."medusa_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))) not valid;
alter table "public"."medusa_products_analyses_relations" validate constraint "product_can_be_tied_to_only_one_analysis_item";
alter table "public"."medusa_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"."medusa_products_analyses_relations" validate constraint "product_can_be_tied_to_only_one_external_item";
alter table "public"."medusa_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"."medusa_products_external_services_relations" validate constraint "medreport_products_connected_online_services_id_fkey";
alter table "public"."medusa_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"."medusa_products_external_services_relations" add constraint "medreport_products_connected_online_services_product_id_fkey" FOREIGN KEY (medusa_product_id) REFERENCES medreport_products(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."medusa_products_external_services_relations" validate constraint "medreport_products_connected_online_services_product_id_fkey";
alter table "public"."medusa_products_external_services_relations" add constraint "medusa_products_external_services_relations_product_id_key" UNIQUE using index "medusa_products_external_services_relations_product_id_key";
grant delete on table "public"."medusa_products_analyses_relations" to "service_role";
grant insert on table "public"."medusa_products_analyses_relations" to "service_role";
grant references on table "public"."medusa_products_analyses_relations" to "service_role";
grant select on table "public"."medusa_products_analyses_relations" to "service_role";
grant trigger on table "public"."medusa_products_analyses_relations" to "service_role";
grant truncate on table "public"."medusa_products_analyses_relations" to "service_role";
grant update on table "public"."medusa_products_analyses_relations" to "service_role";
grant delete on table "public"."medusa_products_external_services_relations" to "service_role";
grant insert on table "public"."medusa_products_external_services_relations" to "service_role";
grant references on table "public"."medusa_products_external_services_relations" to "service_role";
grant select on table "public"."medusa_products_external_services_relations" to "service_role";
grant trigger on table "public"."medusa_products_external_services_relations" to "service_role";
grant truncate on table "public"."medusa_products_external_services_relations" to "service_role";
grant update on table "public"."medusa_products_external_services_relations" to "service_role";
CREATE TRIGGER check_not_already_tied_to_connected_online BEFORE INSERT OR UPDATE ON public.medusa_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.medusa_products_external_services_relations FOR EACH ROW EXECUTE FUNCTION check_tied_to_analysis_item();
revoke delete on table "public"."medreport_products" from "anon";
revoke insert on table "public"."medreport_products" from "anon";
revoke references on table "public"."medreport_products" from "anon";
revoke select on table "public"."medreport_products" from "anon";
revoke trigger on table "public"."medreport_products" from "anon";
revoke truncate on table "public"."medreport_products" from "anon";
revoke update on table "public"."medreport_products" from "anon";
revoke delete on table "public"."medreport_products" from "authenticated";
revoke insert on table "public"."medreport_products" from "authenticated";
revoke references on table "public"."medreport_products" from "authenticated";
revoke select on table "public"."medreport_products" from "authenticated";
revoke trigger on table "public"."medreport_products" from "authenticated";
revoke truncate on table "public"."medreport_products" from "authenticated";
revoke update on table "public"."medreport_products" from "authenticated";
revoke delete on table "public"."medreport_products" from "service_role";
revoke insert on table "public"."medreport_products" from "service_role";
revoke references on table "public"."medreport_products" from "service_role";
revoke select on table "public"."medreport_products" from "service_role";
revoke trigger on table "public"."medreport_products" from "service_role";
revoke truncate on table "public"."medreport_products" from "service_role";
revoke update on table "public"."medreport_products" from "service_role";
alter table "public"."medreport_products" drop constraint "medreport_products_name_key";
alter table "public"."medusa_products_analyses_relations" drop constraint "medreport_products_analyses_product_id_fkey";
alter table "public"."medusa_products_external_services_relations" drop constraint "medreport_products_connected_online_services_product_id_fkey";
alter table "public"."medreport_products" drop constraint "medreport_products_pkey";
drop index if exists "public"."medreport_products_name_key";
drop index if exists "public"."medreport_products_pkey";
drop table "public"."medreport_products";