From 53e9349f37fd9e8555653c00d2ef8f06fb593e06 Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Tue, 15 Jul 2025 17:13:12 +0300 Subject: [PATCH 1/9] Update Supabase configuration in development and production environment files --- .env.development | 7 +++---- .env.production | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.env.development b/.env.development index c22cdb6..5d8bb47 100644 --- a/.env.development +++ b/.env.development @@ -1,10 +1,9 @@ # This file is used to define environment variables for the development environment. # These values are only used when running the app in development mode. -# SUPABASE -NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321 -NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0 -SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU +# SUPABASE DEVELOPMENT +NEXT_PUBLIC_SUPABASE_URL=https://oqsdacktkhmbylmzstjq.supabase.co +NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY1MjgxMjMsImV4cCI6MjA2MjEwNDEyM30.LdHCTWxijFmhXdnT9KVuLRAVbtSwY7OO-oLtpd8GmO0 ## THIS IS FOR DEVELOPMENT ONLY - DO NOT USE IN PRODUCTION SUPABASE_DB_WEBHOOK_SECRET=WEBHOOKSECRET diff --git a/.env.production b/.env.production index 417308e..ab3719d 100644 --- a/.env.production +++ b/.env.production @@ -6,7 +6,9 @@ ## PUBLIC KEYS OR CONFIGURATION ARE OKAY TO BE PLACED HERE. # SUPABASE -NEXT_PUBLIC_SUPABASE_URL= +NEXT_PUBLIC_SUPABASE_URL=https://oqsdacktkhmbylmzstjq.supabase.co +NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY1MjgxMjMsImV4cCI6MjA2MjEwNDEyM30.LdHCTWxijFmhXdnT9KVuLRAVbtSwY7OO-oLtpd8GmO0 +SUPABASE_SERVICE_ROLE_KEY= # STRIPE NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY= From 571637f96a0ff028a65ad58c32ebdd61ff1302a3 Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Wed, 16 Jul 2025 10:16:47 +0300 Subject: [PATCH 2/9] Add .env.production copy to Dockerfile for environment configuration --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index be22dd3..293cbe4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ RUN npm install -g pnpm@9 COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ COPY packages packages COPY tooling tooling +COPY .env.production .env # Install all dependencies RUN pnpm install --frozen-lockfile From 4e0ef7b9de44460197124b4b59efe80cd3999426 Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Wed, 16 Jul 2025 11:21:08 +0300 Subject: [PATCH 3/9] Fix environment variable configuration in .env and .env.production files --- .env | 5 +---- .env.production | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.env b/.env index d26da95..f279691 100644 --- a/.env +++ b/.env @@ -51,7 +51,4 @@ LOGGER=pino NEXT_PUBLIC_DEFAULT_LOCALE=et NEXT_PUBLIC_TEAM_NAVIGATION_STYLE=custom -NEXT_PUBLIC_USER_NAVIGATION_STYLE=custom - -# MEDUSA -NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY= \ No newline at end of file +NEXT_PUBLIC_USER_NAVIGATION_STYLE=custom \ No newline at end of file diff --git a/.env.production b/.env.production index ab3719d..12abfe6 100644 --- a/.env.production +++ b/.env.production @@ -8,7 +8,6 @@ # SUPABASE NEXT_PUBLIC_SUPABASE_URL=https://oqsdacktkhmbylmzstjq.supabase.co NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY1MjgxMjMsImV4cCI6MjA2MjEwNDEyM30.LdHCTWxijFmhXdnT9KVuLRAVbtSwY7OO-oLtpd8GmO0 -SUPABASE_SERVICE_ROLE_KEY= # STRIPE NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY= From d572ba52a8dba2e9bfa1e8a4350d037bec2d37b3 Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Wed, 16 Jul 2025 12:09:14 +0300 Subject: [PATCH 4/9] Refactor Dockerfile for improved build and runtime stages --- Dockerfile | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 293cbe4..e419ec3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,34 @@ +# --- Stage 1: Build --- FROM node:20-alpine as builder WORKDIR /app RUN npm install -g pnpm@9 -# Copy necessary files for workspace resolution COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ COPY packages packages COPY tooling tooling COPY .env.production .env -# Install all dependencies RUN pnpm install --frozen-lockfile COPY . . -RUN pnpm build \ No newline at end of file +RUN pnpm build + + +# --- Stage 2: Runtime --- +FROM node:20-alpine + +WORKDIR /app + +COPY --from=builder /app ./ + +RUN npm install -g pnpm@9 \ + && pnpm install --prod --frozen-lockfile + +ENV NODE_ENV=production + +EXPOSE 3000 + +CMD ["pnpm", "start"] From b028aae1ba3877700e01a4af26226f299d83f9d4 Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Wed, 16 Jul 2025 13:29:29 +0300 Subject: [PATCH 5/9] Fix environment variable copying in Dockerfile for runtime stage --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index e419ec3..5ce1781 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ FROM node:20-alpine WORKDIR /app COPY --from=builder /app ./ +COPY .env.production .env RUN npm install -g pnpm@9 \ && pnpm install --prod --frozen-lockfile From 6232ffc50d46fd785a4362117748c0e9ce759df4 Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Wed, 16 Jul 2025 13:35:01 +0300 Subject: [PATCH 6/9] Remove unused Stripe publishable key from development and production environment files --- .env.development | 2 -- .env.production | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.env.development b/.env.development index 5d8bb47..7599ba1 100644 --- a/.env.development +++ b/.env.development @@ -13,8 +13,6 @@ SUPABASE_DB_WEBHOOK_SECRET=WEBHOOKSECRET # CONTACT FORM CONTACT_EMAIL=test@makerkit.dev -# STRIPE -NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY= # MAILER MAILER_PROVIDER=nodemailer diff --git a/.env.production b/.env.production index 12abfe6..593d99f 100644 --- a/.env.production +++ b/.env.production @@ -9,5 +9,4 @@ NEXT_PUBLIC_SUPABASE_URL=https://oqsdacktkhmbylmzstjq.supabase.co NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY1MjgxMjMsImV4cCI6MjA2MjEwNDEyM30.LdHCTWxijFmhXdnT9KVuLRAVbtSwY7OO-oLtpd8GmO0 -# STRIPE -NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY= + From 2689b879773546d898770df9dfda928904e76092 Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Wed, 16 Jul 2025 14:48:18 +0300 Subject: [PATCH 7/9] add logs --- Dockerfile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5ce1781..c5ec454 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,16 +4,26 @@ FROM node:20-alpine as builder WORKDIR /app RUN npm install -g pnpm@9 +RUN npm install -g dotenv-cli COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ COPY packages packages COPY tooling tooling -COPY .env.production .env +COPY .env.production .env.production +# Load env file and echo a specific variable +# RUN dotenv -e .env -- printenv | grep 'SUPABASE' || true RUN pnpm install --frozen-lockfile COPY . . +ENV NODE_ENV=production + +# 🔍 Optional: Log key envs for debug +RUN echo "📄 .env.production contents:" && cat .env.production \ + && echo "🔧 Current ENV available to Next.js build:" && printenv | grep -E 'SUPABASE|STRIPE|NEXT|NODE_ENV' || true + + RUN pnpm build @@ -23,13 +33,17 @@ FROM node:20-alpine WORKDIR /app COPY --from=builder /app ./ -COPY .env.production .env RUN npm install -g pnpm@9 \ && pnpm install --prod --frozen-lockfile ENV NODE_ENV=production +# 🔍 Optional: Log key envs for debug +RUN echo "📄 .env.production contents:" && cat .env.production \ + && echo "🔧 Current ENV available to Next.js build:" && printenv | grep -E 'SUPABASE|STRIPE|NEXT|NODE_ENV' || true + + EXPOSE 3000 CMD ["pnpm", "start"] From 79b6652748ed85a13dddc293a731e5c6bddc8d35 Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Wed, 16 Jul 2025 16:07:27 +0300 Subject: [PATCH 8/9] Add missing .env file copy in Dockerfile for build stage --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index c5ec454..5ad66b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN npm install -g dotenv-cli COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ COPY packages packages COPY tooling tooling +COPY .env .env COPY .env.production .env.production # Load env file and echo a specific variable From dca5f047399c05a53dbea3968206130bd6d7ddfa Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Thu, 17 Jul 2025 12:39:21 +0300 Subject: [PATCH 9/9] add env logging --- Dockerfile | 2 +- check-env.js | 1 + .../medusa-storefront/src/lib/config.ts | 12 +- .../src/lib/data/collections.ts | 32 +- ...0616142604_add_connected_online_tables.sql | 310 +++++++++--------- ...619070038_add_medreport_product_tables.sql | 274 ++++++++-------- .../20250703145757_add_medreport_schema.sql | 84 ++--- 7 files changed, 359 insertions(+), 356 deletions(-) create mode 100644 check-env.js diff --git a/Dockerfile b/Dockerfile index 5ad66b0..ff86f18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,7 @@ ENV NODE_ENV=production # 🔍 Optional: Log key envs for debug RUN echo "📄 .env.production contents:" && cat .env.production \ && echo "🔧 Current ENV available to Next.js build:" && printenv | grep -E 'SUPABASE|STRIPE|NEXT|NODE_ENV' || true - +RUN node check-env.js RUN pnpm build diff --git a/check-env.js b/check-env.js new file mode 100644 index 0000000..140854c --- /dev/null +++ b/check-env.js @@ -0,0 +1 @@ +console.log('ENV =', process.env.MEDUSA_BACKEND_URL); diff --git a/packages/features/medusa-storefront/src/lib/config.ts b/packages/features/medusa-storefront/src/lib/config.ts index 47c46b1..f48be4b 100644 --- a/packages/features/medusa-storefront/src/lib/config.ts +++ b/packages/features/medusa-storefront/src/lib/config.ts @@ -1,14 +1,16 @@ -import Medusa from "@medusajs/js-sdk" +import Medusa from "@medusajs/js-sdk"; // Defaults to standard port for Medusa server -let MEDUSA_BACKEND_URL = "http://localhost:9000" +let MEDUSA_BACKEND_URL = "http://localhost:9000"; if (process.env.MEDUSA_BACKEND_URL) { - MEDUSA_BACKEND_URL = process.env.MEDUSA_BACKEND_URL + MEDUSA_BACKEND_URL = process.env.MEDUSA_BACKEND_URL; } -export const sdk = new Medusa({ +export const SDK_CONFIG = { baseUrl: MEDUSA_BACKEND_URL, debug: process.env.NODE_ENV === "development", publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY, -}) +}; + +export const sdk = new Medusa(SDK_CONFIG); diff --git a/packages/features/medusa-storefront/src/lib/data/collections.ts b/packages/features/medusa-storefront/src/lib/data/collections.ts index cb403ee..ce3b4d6 100644 --- a/packages/features/medusa-storefront/src/lib/data/collections.ts +++ b/packages/features/medusa-storefront/src/lib/data/collections.ts @@ -1,13 +1,13 @@ -"use server" +"use server"; -import { sdk } from "@lib/config" -import { HttpTypes } from "@medusajs/types" -import { getCacheOptions } from "./cookies" +import { sdk, SDK_CONFIG } from "@lib/config"; +import { HttpTypes } from "@medusajs/types"; +import { getCacheOptions } from "./cookies"; export const retrieveCollection = async (id: string) => { const next = { ...(await getCacheOptions("collections")), - } + }; return sdk.client .fetch<{ collection: HttpTypes.StoreCollection }>( @@ -17,19 +17,19 @@ export const retrieveCollection = async (id: string) => { cache: "force-cache", } ) - .then(({ collection }) => collection) -} + .then(({ collection }) => collection); +}; export const listCollections = async ( queryParams: Record = {} ): Promise<{ collections: HttpTypes.StoreCollection[]; count: number }> => { const next = { ...(await getCacheOptions("collections")), - } - - queryParams.limit = queryParams.limit || "100" - queryParams.offset = queryParams.offset || "0" + }; + queryParams.limit = queryParams.limit || "100"; + queryParams.offset = queryParams.offset || "0"; + console.log("SDK_CONFIG: ", SDK_CONFIG.baseUrl); return sdk.client .fetch<{ collections: HttpTypes.StoreCollection[]; count: number }>( "/store/collections", @@ -39,15 +39,15 @@ export const listCollections = async ( cache: "force-cache", } ) - .then(({ collections }) => ({ collections, count: collections.length })) -} + .then(({ collections }) => ({ collections, count: collections.length })); +}; export const getCollectionByHandle = async ( handle: string ): Promise => { const next = { ...(await getCacheOptions("collections")), - } + }; return sdk.client .fetch(`/store/collections`, { @@ -55,5 +55,5 @@ export const getCollectionByHandle = async ( next, cache: "force-cache", }) - .then(({ collections }) => collections[0]) -} + .then(({ collections }) => collections[0]); +}; diff --git a/supabase/migrations/20250616142604_add_connected_online_tables.sql b/supabase/migrations/20250616142604_add_connected_online_tables.sql index 74f701a..890eb2b 100644 --- a/supabase/migrations/20250616142604_add_connected_online_tables.sql +++ b/supabase/migrations/20250616142604_add_connected_online_tables.sql @@ -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)); \ No newline at end of file +-- create policy "own_all" +-- on "public"."connected_online_reservation" +-- as permissive +-- for all +-- to authenticated +-- using ((( SELECT auth.uid() AS uid) = user_id)); \ No newline at end of file diff --git a/supabase/migrations/20250619070038_add_medreport_product_tables.sql b/supabase/migrations/20250619070038_add_medreport_product_tables.sql index 938fe6e..d861040 100644 --- a/supabase/migrations/20250619070038_add_medreport_product_tables.sql +++ b/supabase/migrations/20250619070038_add_medreport_product_tables.sql @@ -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); diff --git a/supabase/migrations/20250703145757_add_medreport_schema.sql b/supabase/migrations/20250703145757_add_medreport_schema.sql index 8e66630..7b7ac0e 100644 --- a/supabase/migrations/20250703145757_add_medreport_schema.sql +++ b/supabase/migrations/20250703145757_add_medreport_schema.sql @@ -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"; @@ -5160,47 +5160,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 +5410,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";