From f55f6f7b000ccad1cb969ee1c4c33fd0010fa874 Mon Sep 17 00:00:00 2001 From: aburubiehjonas-design <245721399+aburubiehjonas-design@users.noreply.github.com> Date: Tue, 1 Dec 2026 16:35:15 +0000 Subject: [PATCH 1/6] =?UTF-8?q?Veille=20RappelConso=20:=20rappels=20alimen?= =?UTF-8?q?taires=20crois=C3=A9s=20avec=20les=20produits,=20action=20corre?= =?UTF-8?q?ctive=20et=20notification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LkF13NQ4MesYzqDvqcsjqH --- drizzle/0124_hygiene_rappels_nuisibles.sql | 132 + drizzle/meta/0124_snapshot.json | 40726 +++++++++++++++++++ drizzle/meta/_journal.json | 7 + src/app/(app)/haccp/hygiene-actions.ts | 23 + src/app/(app)/haccp/rappels/page.tsx | 111 + src/lib/db/schema.ts | 143 +- src/lib/haccp/automation.ts | 2 + src/lib/haccp/recalls.ts | 135 + src/lib/notify/catalog.ts | 3 + src/lib/scheduler.ts | 7 + src/lib/services/product-recalls.ts | 184 + tests/integration/product-recalls.test.ts | 83 + tests/unit/recalls.test.ts | 62 + 13 files changed, 41617 insertions(+), 1 deletion(-) create mode 100644 drizzle/0124_hygiene_rappels_nuisibles.sql create mode 100644 drizzle/meta/0124_snapshot.json create mode 100644 src/app/(app)/haccp/hygiene-actions.ts create mode 100644 src/app/(app)/haccp/rappels/page.tsx create mode 100644 src/lib/haccp/recalls.ts create mode 100644 src/lib/services/product-recalls.ts create mode 100644 tests/integration/product-recalls.test.ts create mode 100644 tests/unit/recalls.test.ts diff --git a/drizzle/0124_hygiene_rappels_nuisibles.sql b/drizzle/0124_hygiene_rappels_nuisibles.sql new file mode 100644 index 00000000..e28b4b41 --- /dev/null +++ b/drizzle/0124_hygiene_rappels_nuisibles.sql @@ -0,0 +1,132 @@ +CREATE TABLE "allergen_pages" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "organization_id" uuid NOT NULL, + "establishment_id" uuid NOT NULL, + "token" text NOT NULL, + "enabled" boolean DEFAULT true NOT NULL, + "created_by" uuid NOT NULL, + "updated_at" timestamp with time zone, + "created_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +CREATE TABLE "haccp_sealed_exports" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "organization_id" uuid NOT NULL, + "establishment_id" uuid NOT NULL, + "kind" text DEFAULT 'dossier' NOT NULL, + "period_from" date NOT NULL, + "period_to" date NOT NULL, + "verify_token" text NOT NULL, + "sha256" text, + "bytes" integer, + "created_by" uuid NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT "haccp_sealed_exports_kind_ck" CHECK ("haccp_sealed_exports"."kind" IN ('dossier')) +); +--> statement-breakpoint +CREATE TABLE "pest_control_contracts" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "organization_id" uuid NOT NULL, + "establishment_id" uuid NOT NULL, + "provider_name" text NOT NULL, + "certibiocide_number" text, + "contact_phone" text, + "contact_email" text, + "starts_on" date, + "ends_on" date, + "visits_per_year" integer, + "trap_plan" "bytea", + "trap_plan_mime" text, + "trap_plan_size" integer, + "notes" text, + "archived_at" timestamp with time zone, + "created_by" uuid NOT NULL, + "updated_at" timestamp with time zone, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT "pest_control_contracts_visits_ck" CHECK ("pest_control_contracts"."visits_per_year" IS NULL OR ("pest_control_contracts"."visits_per_year" BETWEEN 1 AND 52)), + CONSTRAINT "pest_control_contracts_plan_ck" CHECK ("pest_control_contracts"."trap_plan_size" IS NULL OR "pest_control_contracts"."trap_plan_size" <= 5242880) +); +--> statement-breakpoint +CREATE TABLE "pest_control_visits" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "organization_id" uuid NOT NULL, + "establishment_id" uuid NOT NULL, + "contract_id" uuid, + "visit_on" date NOT NULL, + "kind" text DEFAULT 'contrat' NOT NULL, + "technician_name" text, + "activity" text, + "pests" text[] DEFAULT '{}'::text[] NOT NULL, + "findings" text, + "actions" text, + "recommendations" text, + "products" text, + "sign_token_hash" text, + "sign_token_expires_at" timestamp with time zone, + "signed_at" timestamp with time zone, + "signer_name" text, + "signature" "bytea", + "corrective_action_id" uuid, + "recorded_by" uuid NOT NULL, + "cancelled_at" timestamp with time zone, + "cancelled_by" uuid, + "cancel_reason" text, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT "pest_control_visits_kind_ck" CHECK ("pest_control_visits"."kind" IN ('contrat', 'curatif')), + CONSTRAINT "pest_control_visits_activity_ck" CHECK ("pest_control_visits"."activity" IS NULL OR "pest_control_visits"."activity" IN ('aucune', 'faible', 'forte')), + CONSTRAINT "pest_control_visits_signed_ck" CHECK (("pest_control_visits"."signed_at" IS NULL) = ("pest_control_visits"."signature" IS NULL)) +); +--> statement-breakpoint +CREATE TABLE "product_recalls" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "source_id" integer NOT NULL, + "fiche_number" text, + "version" integer, + "published_at" timestamp with time zone NOT NULL, + "label" text NOT NULL, + "brand" text, + "subcategory" text, + "references" text, + "gtins" text[] DEFAULT '{}'::text[] NOT NULL, + "lots" text[] DEFAULT '{}'::text[] NOT NULL, + "reason" text, + "risks" text, + "consumer_actions" text, + "sale_area" text, + "distributors" text, + "fiche_url" text, + "image_url" text, + "ends_on" date, + "fetched_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +ALTER TABLE "haccp_corrective_actions" DROP CONSTRAINT "haccp_corrective_actions_source_ck";--> statement-breakpoint +ALTER TABLE "temperature_readings" ADD COLUMN "client_ref" uuid;--> statement-breakpoint +ALTER TABLE "temperature_readings" ADD COLUMN "entered_offline" boolean DEFAULT false NOT NULL;--> statement-breakpoint +ALTER TABLE "allergen_pages" ADD CONSTRAINT "allergen_pages_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "allergen_pages" ADD CONSTRAINT "allergen_pages_establishment_id_establishments_id_fk" FOREIGN KEY ("establishment_id") REFERENCES "public"."establishments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "allergen_pages" ADD CONSTRAINT "allergen_pages_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "haccp_sealed_exports" ADD CONSTRAINT "haccp_sealed_exports_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "haccp_sealed_exports" ADD CONSTRAINT "haccp_sealed_exports_establishment_id_establishments_id_fk" FOREIGN KEY ("establishment_id") REFERENCES "public"."establishments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "haccp_sealed_exports" ADD CONSTRAINT "haccp_sealed_exports_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pest_control_contracts" ADD CONSTRAINT "pest_control_contracts_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pest_control_contracts" ADD CONSTRAINT "pest_control_contracts_establishment_id_establishments_id_fk" FOREIGN KEY ("establishment_id") REFERENCES "public"."establishments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pest_control_contracts" ADD CONSTRAINT "pest_control_contracts_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pest_control_visits" ADD CONSTRAINT "pest_control_visits_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pest_control_visits" ADD CONSTRAINT "pest_control_visits_establishment_id_establishments_id_fk" FOREIGN KEY ("establishment_id") REFERENCES "public"."establishments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pest_control_visits" ADD CONSTRAINT "pest_control_visits_contract_id_pest_control_contracts_id_fk" FOREIGN KEY ("contract_id") REFERENCES "public"."pest_control_contracts"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pest_control_visits" ADD CONSTRAINT "pest_control_visits_corrective_action_id_haccp_corrective_actions_id_fk" FOREIGN KEY ("corrective_action_id") REFERENCES "public"."haccp_corrective_actions"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pest_control_visits" ADD CONSTRAINT "pest_control_visits_recorded_by_users_id_fk" FOREIGN KEY ("recorded_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pest_control_visits" ADD CONSTRAINT "pest_control_visits_cancelled_by_users_id_fk" FOREIGN KEY ("cancelled_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +CREATE UNIQUE INDEX "allergen_pages_token_uq" ON "allergen_pages" USING btree ("token");--> statement-breakpoint +CREATE UNIQUE INDEX "allergen_pages_est_uq" ON "allergen_pages" USING btree ("establishment_id");--> statement-breakpoint +CREATE UNIQUE INDEX "haccp_sealed_exports_token_uq" ON "haccp_sealed_exports" USING btree ("verify_token");--> statement-breakpoint +CREATE INDEX "haccp_sealed_exports_est_idx" ON "haccp_sealed_exports" USING btree ("organization_id","establishment_id","created_at");--> statement-breakpoint +CREATE INDEX "pest_control_contracts_est_idx" ON "pest_control_contracts" USING btree ("organization_id","establishment_id");--> statement-breakpoint +CREATE INDEX "pest_control_visits_est_idx" ON "pest_control_visits" USING btree ("organization_id","establishment_id","visit_on");--> statement-breakpoint +CREATE UNIQUE INDEX "pest_control_visits_token_uq" ON "pest_control_visits" USING btree ("sign_token_hash") WHERE "pest_control_visits"."sign_token_hash" IS NOT NULL;--> statement-breakpoint +CREATE UNIQUE INDEX "product_recalls_source_uq" ON "product_recalls" USING btree ("source_id");--> statement-breakpoint +CREATE INDEX "product_recalls_published_idx" ON "product_recalls" USING btree ("published_at");--> statement-breakpoint +CREATE UNIQUE INDEX "temperature_readings_client_ref_uq" ON "temperature_readings" USING btree ("organization_id","client_ref") WHERE "temperature_readings"."client_ref" IS NOT NULL;--> statement-breakpoint +ALTER TABLE "haccp_corrective_actions" ADD CONSTRAINT "haccp_corrective_actions_source_ck" CHECK ("haccp_corrective_actions"."source" IN ('sonde_hors_plage', 'sonde_muette', 'releves_manquants', 'nettoyage_manquant', 'date_limite', 'manuel', 'rappel_produit', 'nuisibles'));--> statement-breakpoint +SELECT altair_enable_tenant_rls(); diff --git a/drizzle/meta/0124_snapshot.json b/drizzle/meta/0124_snapshot.json new file mode 100644 index 00000000..52c12a65 --- /dev/null +++ b/drizzle/meta/0124_snapshot.json @@ -0,0 +1,40726 @@ +{ + "id": "987a083c-d69a-457f-a738-f160f9074881", + "prevId": "e130d134-a6ac-492d-a32c-1897ecd5191d", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.absence_requests": { + "name": "absence_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "part": { + "name": "part", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'journee'" + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en_attente'" + }, + "decided_by": { + "name": "decided_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "decision_note": { + "name": "decision_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "absence_requests_emp_idx": { + "name": "absence_requests_emp_idx", + "columns": [ + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "absence_requests_organization_id_organizations_id_fk": { + "name": "absence_requests_organization_id_organizations_id_fk", + "tableFrom": "absence_requests", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "absence_requests_employee_id_employees_id_fk": { + "name": "absence_requests_employee_id_employees_id_fk", + "tableFrom": "absence_requests", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "absence_requests_decided_by_users_id_fk": { + "name": "absence_requests_decided_by_users_id_fk", + "tableFrom": "absence_requests", + "tableTo": "users", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "absence_requests_created_by_users_id_fk": { + "name": "absence_requests_created_by_users_id_fk", + "tableFrom": "absence_requests", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "absence_requests_status_ck": { + "name": "absence_requests_status_ck", + "value": "\"absence_requests\".\"status\" IN ('en_attente', 'acceptee', 'refusee', 'annulee')" + }, + "absence_requests_dates_ck": { + "name": "absence_requests_dates_ck", + "value": "\"absence_requests\".\"end_date\" >= \"absence_requests\".\"start_date\"" + } + }, + "isRLSEnabled": false + }, + "public.account_invites": { + "name": "account_invites", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'invite'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "account_invites_token_uq": { + "name": "account_invites_token_uq", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "account_invites_user_idx": { + "name": "account_invites_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "account_invites_organization_id_organizations_id_fk": { + "name": "account_invites_organization_id_organizations_id_fk", + "tableFrom": "account_invites", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "account_invites_user_id_users_id_fk": { + "name": "account_invites_user_id_users_id_fk", + "tableFrom": "account_invites", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "account_invites_created_by_users_id_fk": { + "name": "account_invites_created_by_users_id_fk", + "tableFrom": "account_invites", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "account_invites_purpose_ck": { + "name": "account_invites_purpose_ck", + "value": "\"account_invites\".\"purpose\" IN ('invite', 'reset', 'verify')" + } + }, + "isRLSEnabled": false + }, + "public.ai_actions": { + "name": "ai_actions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_key": { + "name": "source_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "source_href": { + "name": "source_href", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "decided_by": { + "name": "decided_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "discard_reason": { + "name": "discard_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "ai_actions_org_idx": { + "name": "ai_actions_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "ai_actions_pending_uq": { + "name": "ai_actions_pending_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"ai_actions\".\"status\" = 'pending'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "ai_actions_organization_id_organizations_id_fk": { + "name": "ai_actions_organization_id_organizations_id_fk", + "tableFrom": "ai_actions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ai_actions_created_by_users_id_fk": { + "name": "ai_actions_created_by_users_id_fk", + "tableFrom": "ai_actions", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "ai_actions_decided_by_users_id_fk": { + "name": "ai_actions_decided_by_users_id_fk", + "tableFrom": "ai_actions", + "tableTo": "users", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "ai_actions_kind_ck": { + "name": "ai_actions_kind_ck", + "value": "\"ai_actions\".\"kind\" IN ('negotiation_email', 'price_change')" + }, + "ai_actions_status_ck": { + "name": "ai_actions_status_ck", + "value": "\"ai_actions\".\"status\" IN ('pending', 'sent', 'applied', 'done_manual', 'discarded')" + }, + "ai_actions_decided_ck": { + "name": "ai_actions_decided_ck", + "value": "\"ai_actions\".\"status\" = 'pending' OR \"ai_actions\".\"decided_at\" IS NOT NULL" + }, + "ai_actions_discarded_ck": { + "name": "ai_actions_discarded_ck", + "value": "\"ai_actions\".\"status\" <> 'discarded' OR \"ai_actions\".\"discard_reason\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.ai_conversations": { + "name": "ai_conversations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "ai_conversations_user_idx": { + "name": "ai_conversations_user_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "ai_conversations_organization_id_organizations_id_fk": { + "name": "ai_conversations_organization_id_organizations_id_fk", + "tableFrom": "ai_conversations", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ai_conversations_user_id_users_id_fk": { + "name": "ai_conversations_user_id_users_id_fk", + "tableFrom": "ai_conversations", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ai_messages": { + "name": "ai_messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tools": { + "name": "tools", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "input_tokens": { + "name": "input_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "output_tokens": { + "name": "output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric(12, 6)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "ai_messages_conv_idx": { + "name": "ai_messages_conv_idx", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "ai_messages_org_idx": { + "name": "ai_messages_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "ai_messages_organization_id_organizations_id_fk": { + "name": "ai_messages_organization_id_organizations_id_fk", + "tableFrom": "ai_messages", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ai_messages_conversation_id_ai_conversations_id_fk": { + "name": "ai_messages_conversation_id_ai_conversations_id_fk", + "tableFrom": "ai_messages", + "tableTo": "ai_conversations", + "columnsFrom": [ + "conversation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "ai_messages_role_ck": { + "name": "ai_messages_role_ck", + "value": "\"ai_messages\".\"role\" IN ('user', 'assistant')" + } + }, + "isRLSEnabled": false + }, + "public.ai_reco_dismissals": { + "name": "ai_reco_dismissals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "reco_id": { + "name": "reco_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "until": { + "name": "until", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "dismissed_by": { + "name": "dismissed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "ai_reco_dismissals_uq": { + "name": "ai_reco_dismissals_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "reco_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "ai_reco_dismissals_organization_id_organizations_id_fk": { + "name": "ai_reco_dismissals_organization_id_organizations_id_fk", + "tableFrom": "ai_reco_dismissals", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ai_reco_dismissals_dismissed_by_users_id_fk": { + "name": "ai_reco_dismissals_dismissed_by_users_id_fk", + "tableFrom": "ai_reco_dismissals", + "tableTo": "users", + "columnsFrom": [ + "dismissed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "ai_reco_dismissals_reason_ck": { + "name": "ai_reco_dismissals_reason_ck", + "value": "length(trim(\"ai_reco_dismissals\".\"reason\")) >= 3" + } + }, + "isRLSEnabled": false + }, + "public.allergen_pages": { + "name": "allergen_pages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "allergen_pages_token_uq": { + "name": "allergen_pages_token_uq", + "columns": [ + { + "expression": "token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "allergen_pages_est_uq": { + "name": "allergen_pages_est_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "allergen_pages_organization_id_organizations_id_fk": { + "name": "allergen_pages_organization_id_organizations_id_fk", + "tableFrom": "allergen_pages", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "allergen_pages_establishment_id_establishments_id_fk": { + "name": "allergen_pages_establishment_id_establishments_id_fk", + "tableFrom": "allergen_pages", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "allergen_pages_created_by_users_id_fk": { + "name": "allergen_pages_created_by_users_id_fk", + "tableFrom": "allergen_pages", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit_log": { + "name": "audit_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "before": { + "name": "before", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "after": { + "name": "after", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "audit_org_idx": { + "name": "audit_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "audit_log_organization_id_organizations_id_fk": { + "name": "audit_log_organization_id_organizations_id_fk", + "tableFrom": "audit_log", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "audit_log_user_id_users_id_fk": { + "name": "audit_log_user_id_users_id_fk", + "tableFrom": "audit_log", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_throttle": { + "name": "auth_throttle", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "auth_throttle_ip_idx": { + "name": "auth_throttle_ip_idx", + "columns": [ + { + "expression": "ip", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.automation_approvals": { + "name": "automation_approvals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "rule_id": { + "name": "rule_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "approver_id": { + "name": "approver_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "item_key": { + "name": "item_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "href": { + "name": "href", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "decided_by": { + "name": "decided_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivered": { + "name": "delivered", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "automation_approvals_once_uq": { + "name": "automation_approvals_once_uq", + "columns": [ + { + "expression": "rule_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "day", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_approvals_org_idx": { + "name": "automation_approvals_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "automation_approvals_organization_id_organizations_id_fk": { + "name": "automation_approvals_organization_id_organizations_id_fk", + "tableFrom": "automation_approvals", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_approvals_rule_id_automation_rules_id_fk": { + "name": "automation_approvals_rule_id_automation_rules_id_fk", + "tableFrom": "automation_approvals", + "tableTo": "automation_rules", + "columnsFrom": [ + "rule_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_approvals_approver_id_users_id_fk": { + "name": "automation_approvals_approver_id_users_id_fk", + "tableFrom": "automation_approvals", + "tableTo": "users", + "columnsFrom": [ + "approver_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "automation_approvals_decided_by_users_id_fk": { + "name": "automation_approvals_decided_by_users_id_fk", + "tableFrom": "automation_approvals", + "tableTo": "users", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "automation_approvals_status_ck": { + "name": "automation_approvals_status_ck", + "value": "\"automation_approvals\".\"status\" IN ('pending', 'approved', 'rejected')" + }, + "automation_approvals_reason_ck": { + "name": "automation_approvals_reason_ck", + "value": "\"automation_approvals\".\"status\" <> 'rejected' OR \"automation_approvals\".\"reason\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.automation_drafts": { + "name": "automation_drafts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "rule_id": { + "name": "rule_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "rule_name": { + "name": "rule_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "source_href": { + "name": "source_href", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "prepared_for": { + "name": "prepared_for", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "decided_by": { + "name": "decided_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "discard_reason": { + "name": "discard_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "result_entity_type": { + "name": "result_entity_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "result_entity_id": { + "name": "result_entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "automation_drafts_org_idx": { + "name": "automation_drafts_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_drafts_est_idx": { + "name": "automation_drafts_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "automation_drafts_organization_id_organizations_id_fk": { + "name": "automation_drafts_organization_id_organizations_id_fk", + "tableFrom": "automation_drafts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_drafts_establishment_id_establishments_id_fk": { + "name": "automation_drafts_establishment_id_establishments_id_fk", + "tableFrom": "automation_drafts", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_drafts_rule_id_automation_rules_id_fk": { + "name": "automation_drafts_rule_id_automation_rules_id_fk", + "tableFrom": "automation_drafts", + "tableTo": "automation_rules", + "columnsFrom": [ + "rule_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "automation_drafts_prepared_for_users_id_fk": { + "name": "automation_drafts_prepared_for_users_id_fk", + "tableFrom": "automation_drafts", + "tableTo": "users", + "columnsFrom": [ + "prepared_for" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "automation_drafts_decided_by_users_id_fk": { + "name": "automation_drafts_decided_by_users_id_fk", + "tableFrom": "automation_drafts", + "tableTo": "users", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "automation_drafts_kind_ck": { + "name": "automation_drafts_kind_ck", + "value": "\"automation_drafts\".\"kind\" IN ('purchase_order', 'credit_request', 'maintenance_request')" + }, + "automation_drafts_status_ck": { + "name": "automation_drafts_status_ck", + "value": "\"automation_drafts\".\"status\" IN ('pending', 'validated', 'discarded', 'expired')" + }, + "automation_drafts_validated_ck": { + "name": "automation_drafts_validated_ck", + "value": "\"automation_drafts\".\"status\" <> 'validated' OR (\"automation_drafts\".\"decided_by\" IS NOT NULL AND \"automation_drafts\".\"result_entity_type\" IS NOT NULL)" + }, + "automation_drafts_discarded_ck": { + "name": "automation_drafts_discarded_ck", + "value": "\"automation_drafts\".\"status\" <> 'discarded' OR \"automation_drafts\".\"discard_reason\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.automation_occurrences": { + "name": "automation_occurrences", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "rule_id": { + "name": "rule_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "occurrence_key": { + "name": "occurrence_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "draft_id": { + "name": "draft_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "automation_occurrences_uq": { + "name": "automation_occurrences_uq", + "columns": [ + { + "expression": "rule_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurrence_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_occurrences_org_key_idx": { + "name": "automation_occurrences_org_key_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurrence_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "automation_occurrences_organization_id_organizations_id_fk": { + "name": "automation_occurrences_organization_id_organizations_id_fk", + "tableFrom": "automation_occurrences", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_occurrences_rule_id_automation_rules_id_fk": { + "name": "automation_occurrences_rule_id_automation_rules_id_fk", + "tableFrom": "automation_occurrences", + "tableTo": "automation_rules", + "columnsFrom": [ + "rule_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_occurrences_draft_id_automation_drafts_id_fk": { + "name": "automation_occurrences_draft_id_automation_drafts_id_fk", + "tableFrom": "automation_occurrences", + "tableTo": "automation_drafts", + "columnsFrom": [ + "draft_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.automation_pending": { + "name": "automation_pending", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "rule_id": { + "name": "rule_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_key": { + "name": "item_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "automation_pending_org_idx": { + "name": "automation_pending_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "automation_pending_organization_id_organizations_id_fk": { + "name": "automation_pending_organization_id_organizations_id_fk", + "tableFrom": "automation_pending", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_pending_rule_id_automation_rules_id_fk": { + "name": "automation_pending_rule_id_automation_rules_id_fk", + "tableFrom": "automation_pending", + "tableTo": "automation_rules", + "columnsFrom": [ + "rule_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_pending_user_id_users_id_fk": { + "name": "automation_pending_user_id_users_id_fk", + "tableFrom": "automation_pending", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "automation_pending_rule_id_user_id_item_key_pk": { + "name": "automation_pending_rule_id_user_id_item_key_pk", + "columns": [ + "rule_id", + "user_id", + "item_key" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.automation_rules": { + "name": "automation_rules", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "min_severity": { + "name": "min_severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'warning'" + }, + "recipient_ids": { + "name": "recipient_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "by_email": { + "name": "by_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'notify'" + }, + "params": { + "name": "params", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "conditions": { + "name": "conditions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "delay_minutes": { + "name": "delay_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "approver_id": { + "name": "approver_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "last_triggered_at": { + "name": "last_triggered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "automation_rules_org_idx": { + "name": "automation_rules_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "automation_rules_organization_id_organizations_id_fk": { + "name": "automation_rules_organization_id_organizations_id_fk", + "tableFrom": "automation_rules", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_rules_establishment_id_establishments_id_fk": { + "name": "automation_rules_establishment_id_establishments_id_fk", + "tableFrom": "automation_rules", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_rules_approver_id_users_id_fk": { + "name": "automation_rules_approver_id_users_id_fk", + "tableFrom": "automation_rules", + "tableTo": "users", + "columnsFrom": [ + "approver_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "automation_rules_created_by_users_id_fk": { + "name": "automation_rules_created_by_users_id_fk", + "tableFrom": "automation_rules", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "automation_rules_severity_ck": { + "name": "automation_rules_severity_ck", + "value": "\"automation_rules\".\"min_severity\" IN ('warning', 'danger')" + }, + "automation_rules_action_ck": { + "name": "automation_rules_action_ck", + "value": "\"automation_rules\".\"action\" IN ('notify', 'draft_purchase_order', 'draft_credit_request', 'draft_maintenance_request')" + }, + "automation_rules_delay_ck": { + "name": "automation_rules_delay_ck", + "value": "\"automation_rules\".\"delay_minutes\" >= 0 AND \"automation_rules\".\"delay_minutes\" <= 10080" + } + }, + "isRLSEnabled": false + }, + "public.automation_runs": { + "name": "automation_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "rule_id": { + "name": "rule_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "item_key": { + "name": "item_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "href": { + "name": "href", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "emailed": { + "name": "emailed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "automation_runs_once_uq": { + "name": "automation_runs_once_uq", + "columns": [ + { + "expression": "rule_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "day", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_runs_org_idx": { + "name": "automation_runs_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "automation_runs_organization_id_organizations_id_fk": { + "name": "automation_runs_organization_id_organizations_id_fk", + "tableFrom": "automation_runs", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_runs_rule_id_automation_rules_id_fk": { + "name": "automation_runs_rule_id_automation_rules_id_fk", + "tableFrom": "automation_runs", + "tableTo": "automation_rules", + "columnsFrom": [ + "rule_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_runs_user_id_users_id_fk": { + "name": "automation_runs_user_id_users_id_fk", + "tableFrom": "automation_runs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.automation_settings": { + "name": "automation_settings", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "paused": { + "name": "paused", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "paused_reason": { + "name": "paused_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "paused_by": { + "name": "paused_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "paused_at": { + "name": "paused_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "automation_settings_organization_id_organizations_id_fk": { + "name": "automation_settings_organization_id_organizations_id_fk", + "tableFrom": "automation_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_settings_paused_by_users_id_fk": { + "name": "automation_settings_paused_by_users_id_fk", + "tableFrom": "automation_settings", + "tableTo": "users", + "columnsFrom": [ + "paused_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.bank_accounts": { + "name": "bank_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bank_name": { + "name": "bank_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "iban_last4": { + "name": "iban_last4", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "opening_balance": { + "name": "opening_balance", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "opening_date": { + "name": "opening_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "alert_threshold": { + "name": "alert_threshold", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "bank_accounts_org_idx": { + "name": "bank_accounts_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "bank_accounts_organization_id_organizations_id_fk": { + "name": "bank_accounts_organization_id_organizations_id_fk", + "tableFrom": "bank_accounts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "bank_accounts_establishment_id_establishments_id_fk": { + "name": "bank_accounts_establishment_id_establishments_id_fk", + "tableFrom": "bank_accounts", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "bank_accounts_created_by_users_id_fk": { + "name": "bank_accounts_created_by_users_id_fk", + "tableFrom": "bank_accounts", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "bank_accounts_iban_ck": { + "name": "bank_accounts_iban_ck", + "value": "\"bank_accounts\".\"iban_last4\" IS NULL OR \"bank_accounts\".\"iban_last4\" ~ '^[0-9A-Z]{4}$'" + } + }, + "isRLSEnabled": false + }, + "public.bank_imports": { + "name": "bank_imports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_sha256": { + "name": "file_sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "format": { + "name": "format", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rows_total": { + "name": "rows_total", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "rows_inserted": { + "name": "rows_inserted", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "period_from": { + "name": "period_from", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "period_to": { + "name": "period_to", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "bank_imports_account_idx": { + "name": "bank_imports_account_idx", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "bank_imports_organization_id_organizations_id_fk": { + "name": "bank_imports_organization_id_organizations_id_fk", + "tableFrom": "bank_imports", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "bank_imports_account_id_bank_accounts_id_fk": { + "name": "bank_imports_account_id_bank_accounts_id_fk", + "tableFrom": "bank_imports", + "tableTo": "bank_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "bank_imports_created_by_users_id_fk": { + "name": "bank_imports_created_by_users_id_fk", + "tableFrom": "bank_imports", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.bank_rules": { + "name": "bank_rules", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "keyword": { + "name": "keyword", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "direction": { + "name": "direction", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'any'" + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "bank_rules_uq": { + "name": "bank_rules_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"keyword\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "direction", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "bank_rules_organization_id_organizations_id_fk": { + "name": "bank_rules_organization_id_organizations_id_fk", + "tableFrom": "bank_rules", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "bank_rules_created_by_users_id_fk": { + "name": "bank_rules_created_by_users_id_fk", + "tableFrom": "bank_rules", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "bank_rules_direction_ck": { + "name": "bank_rules_direction_ck", + "value": "\"bank_rules\".\"direction\" IN ('in', 'out', 'any')" + } + }, + "isRLSEnabled": false + }, + "public.bank_transactions": { + "name": "bank_transactions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "import_id": { + "name": "import_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "booking_date": { + "name": "booking_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "value_date": { + "name": "value_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "balance_after": { + "name": "balance_after", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "category_source": { + "name": "category_source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "purchase_invoice_id": { + "name": "purchase_invoice_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "row_hash": { + "name": "row_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "bank_tx_row_uq": { + "name": "bank_tx_row_uq", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "row_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "bank_tx_invoice_uq": { + "name": "bank_tx_invoice_uq", + "columns": [ + { + "expression": "purchase_invoice_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"bank_transactions\".\"purchase_invoice_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "bank_tx_period_idx": { + "name": "bank_tx_period_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "booking_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "bank_transactions_organization_id_organizations_id_fk": { + "name": "bank_transactions_organization_id_organizations_id_fk", + "tableFrom": "bank_transactions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "bank_transactions_establishment_id_establishments_id_fk": { + "name": "bank_transactions_establishment_id_establishments_id_fk", + "tableFrom": "bank_transactions", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "bank_transactions_account_id_bank_accounts_id_fk": { + "name": "bank_transactions_account_id_bank_accounts_id_fk", + "tableFrom": "bank_transactions", + "tableTo": "bank_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "bank_transactions_import_id_bank_imports_id_fk": { + "name": "bank_transactions_import_id_bank_imports_id_fk", + "tableFrom": "bank_transactions", + "tableTo": "bank_imports", + "columnsFrom": [ + "import_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "bank_transactions_purchase_invoice_id_purchase_invoices_id_fk": { + "name": "bank_transactions_purchase_invoice_id_purchase_invoices_id_fk", + "tableFrom": "bank_transactions", + "tableTo": "purchase_invoices", + "columnsFrom": [ + "purchase_invoice_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "bank_tx_amount_ck": { + "name": "bank_tx_amount_ck", + "value": "\"bank_transactions\".\"amount\" <> 0" + } + }, + "isRLSEnabled": false + }, + "public.booking_button_clicks": { + "name": "booking_button_clicks", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "placement": { + "name": "placement", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target": { + "name": "target", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "clicks": { + "name": "clicks", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "booking_button_clicks_establishment_id_establishments_id_fk": { + "name": "booking_button_clicks_establishment_id_establishments_id_fk", + "tableFrom": "booking_button_clicks", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "booking_button_clicks_organization_id_organizations_id_fk": { + "name": "booking_button_clicks_organization_id_organizations_id_fk", + "tableFrom": "booking_button_clicks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "booking_button_clicks_establishment_id_day_placement_target_pk": { + "name": "booking_button_clicks_establishment_id_day_placement_target_pk", + "columns": [ + "establishment_id", + "day", + "placement", + "target" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "booking_button_clicks_placement_ck": { + "name": "booking_button_clicks_placement_ck", + "value": "\"booking_button_clicks\".\"placement\" IN ('instagram', 'google', 'site')" + }, + "booking_button_clicks_target_ck": { + "name": "booking_button_clicks_target_ck", + "value": "\"booking_button_clicks\".\"target\" IN ('altair', 'thefork', 'opentable', 'zenchef')" + } + }, + "isRLSEnabled": false + }, + "public.booking_channels": { + "name": "booking_channels", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "instagram_target": { + "name": "instagram_target", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'altair'" + }, + "google_target": { + "name": "google_target", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'altair'" + }, + "site_target": { + "name": "site_target", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'altair'" + }, + "thefork_url": { + "name": "thefork_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "opentable_url": { + "name": "opentable_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "zenchef_url": { + "name": "zenchef_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "booking_channels_establishment_id_establishments_id_fk": { + "name": "booking_channels_establishment_id_establishments_id_fk", + "tableFrom": "booking_channels", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "booking_channels_organization_id_organizations_id_fk": { + "name": "booking_channels_organization_id_organizations_id_fk", + "tableFrom": "booking_channels", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "booking_channels_updated_by_users_id_fk": { + "name": "booking_channels_updated_by_users_id_fk", + "tableFrom": "booking_channels", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "booking_channels_targets_ck": { + "name": "booking_channels_targets_ck", + "value": "\"booking_channels\".\"instagram_target\" IN ('altair', 'thefork', 'opentable', 'zenchef') AND \"booking_channels\".\"google_target\" IN ('altair', 'thefork', 'opentable', 'zenchef') AND \"booking_channels\".\"site_target\" IN ('altair', 'thefork', 'opentable', 'zenchef')" + }, + "booking_channels_urls_ck": { + "name": "booking_channels_urls_ck", + "value": "(\"booking_channels\".\"thefork_url\" IS NULL OR \"booking_channels\".\"thefork_url\" LIKE 'https://%') AND (\"booking_channels\".\"opentable_url\" IS NULL OR \"booking_channels\".\"opentable_url\" LIKE 'https://%') AND (\"booking_channels\".\"zenchef_url\" IS NULL OR \"booking_channels\".\"zenchef_url\" LIKE 'https://%')" + } + }, + "isRLSEnabled": false + }, + "public.business_document_versions": { + "name": "business_document_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version_no": { + "name": "version_no", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "replaced_by": { + "name": "replaced_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "replaced_at": { + "name": "replaced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "business_document_versions_uq": { + "name": "business_document_versions_uq", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version_no", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "business_document_versions_sha_idx": { + "name": "business_document_versions_sha_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sha256", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "business_document_versions_organization_id_organizations_id_fk": { + "name": "business_document_versions_organization_id_organizations_id_fk", + "tableFrom": "business_document_versions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "business_document_versions_document_id_business_documents_id_fk": { + "name": "business_document_versions_document_id_business_documents_id_fk", + "tableFrom": "business_document_versions", + "tableTo": "business_documents", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "business_document_versions_replaced_by_users_id_fk": { + "name": "business_document_versions_replaced_by_users_id_fk", + "tableFrom": "business_document_versions", + "tableTo": "users", + "columnsFrom": [ + "replaced_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "business_document_versions_size_ck": { + "name": "business_document_versions_size_ck", + "value": "\"business_document_versions\".\"size\" <= 5242880" + } + }, + "isRLSEnabled": false + }, + "public.business_documents": { + "name": "business_documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "party": { + "name": "party", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference": { + "name": "reference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "issued_on": { + "name": "issued_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "expires_on": { + "name": "expires_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "reminder_days": { + "name": "reminder_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 30 + }, + "annual_cost": { + "name": "annual_cost", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "file_version": { + "name": "file_version", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "notice_on": { + "name": "notice_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "sensitivity": { + "name": "sensitivity", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'normal'" + }, + "duplicate_of_id": { + "name": "duplicate_of_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "replaced_by_id": { + "name": "replaced_by_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "checklist_code": { + "name": "checklist_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "business_documents_org_idx": { + "name": "business_documents_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "expires_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "business_documents_checklist_uq": { + "name": "business_documents_checklist_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checklist_code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"business_documents\".\"checklist_code\" IS NOT NULL AND \"business_documents\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "business_documents_sha_idx": { + "name": "business_documents_sha_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sha256", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "business_documents_organization_id_organizations_id_fk": { + "name": "business_documents_organization_id_organizations_id_fk", + "tableFrom": "business_documents", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "business_documents_establishment_id_establishments_id_fk": { + "name": "business_documents_establishment_id_establishments_id_fk", + "tableFrom": "business_documents", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "business_documents_duplicate_of_id_business_documents_id_fk": { + "name": "business_documents_duplicate_of_id_business_documents_id_fk", + "tableFrom": "business_documents", + "tableTo": "business_documents", + "columnsFrom": [ + "duplicate_of_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "business_documents_replaced_by_id_business_documents_id_fk": { + "name": "business_documents_replaced_by_id_business_documents_id_fk", + "tableFrom": "business_documents", + "tableTo": "business_documents", + "columnsFrom": [ + "replaced_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "business_documents_created_by_users_id_fk": { + "name": "business_documents_created_by_users_id_fk", + "tableFrom": "business_documents", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "business_documents_size_ck": { + "name": "business_documents_size_ck", + "value": "\"business_documents\".\"size\" IS NULL OR \"business_documents\".\"size\" <= 5242880" + }, + "business_documents_reminder_ck": { + "name": "business_documents_reminder_ck", + "value": "\"business_documents\".\"reminder_days\" BETWEEN 0 AND 365" + }, + "business_documents_sensitivity_ck": { + "name": "business_documents_sensitivity_ck", + "value": "\"business_documents\".\"sensitivity\" IN ('normal', 'confidentiel', 'restreint')" + }, + "business_documents_notice_ck": { + "name": "business_documents_notice_ck", + "value": "\"business_documents\".\"notice_on\" IS NULL OR \"business_documents\".\"expires_on\" IS NULL OR \"business_documents\".\"notice_on\" <= \"business_documents\".\"expires_on\"" + } + }, + "isRLSEnabled": false + }, + "public.campaign_recipients": { + "name": "campaign_recipients", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "customer_id": { + "name": "customer_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unsubscribe_token_hash": { + "name": "unsubscribe_token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unsubscribed_at": { + "name": "unsubscribed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "campaign_recipients_token_uq": { + "name": "campaign_recipients_token_uq", + "columns": [ + { + "expression": "unsubscribe_token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "campaign_recipients_campaign_customer_uq": { + "name": "campaign_recipients_campaign_customer_uq", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "customer_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "campaign_recipients_customer_idx": { + "name": "campaign_recipients_customer_idx", + "columns": [ + { + "expression": "customer_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "campaign_recipients_organization_id_organizations_id_fk": { + "name": "campaign_recipients_organization_id_organizations_id_fk", + "tableFrom": "campaign_recipients", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "campaign_recipients_campaign_id_marketing_campaigns_id_fk": { + "name": "campaign_recipients_campaign_id_marketing_campaigns_id_fk", + "tableFrom": "campaign_recipients", + "tableTo": "marketing_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "campaign_recipients_customer_id_customers_id_fk": { + "name": "campaign_recipients_customer_id_customers_id_fk", + "tableFrom": "campaign_recipients", + "tableTo": "customers", + "columnsFrom": [ + "customer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.candidates": { + "name": "candidates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "job_opening_id": { + "name": "job_opening_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "first_name": { + "name": "first_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_name": { + "name": "last_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'autre'" + }, + "stage": { + "name": "stage", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'nouveau'" + }, + "stage_changed_at": { + "name": "stage_changed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "interview_at": { + "name": "interview_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "rating": { + "name": "rating", + "type": "smallint", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refusal_reason": { + "name": "refusal_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "last_contact_at": { + "name": "last_contact_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "candidates_org_idx": { + "name": "candidates_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "candidates_opening_idx": { + "name": "candidates_opening_idx", + "columns": [ + { + "expression": "job_opening_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "candidates_organization_id_organizations_id_fk": { + "name": "candidates_organization_id_organizations_id_fk", + "tableFrom": "candidates", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "candidates_establishment_id_establishments_id_fk": { + "name": "candidates_establishment_id_establishments_id_fk", + "tableFrom": "candidates", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "candidates_job_opening_id_job_openings_id_fk": { + "name": "candidates_job_opening_id_job_openings_id_fk", + "tableFrom": "candidates", + "tableTo": "job_openings", + "columnsFrom": [ + "job_opening_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "candidates_employee_id_employees_id_fk": { + "name": "candidates_employee_id_employees_id_fk", + "tableFrom": "candidates", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "candidates_created_by_users_id_fk": { + "name": "candidates_created_by_users_id_fk", + "tableFrom": "candidates", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "candidates_stage_ck": { + "name": "candidates_stage_ck", + "value": "\"candidates\".\"stage\" IN ('nouveau', 'preselection', 'entretien', 'essai', 'offre', 'embauche', 'refuse', 'desiste')" + }, + "candidates_rating_ck": { + "name": "candidates_rating_ck", + "value": "\"candidates\".\"rating\" IS NULL OR \"candidates\".\"rating\" BETWEEN 1 AND 5" + } + }, + "isRLSEnabled": false + }, + "public.cash_counts": { + "name": "cash_counts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "business_day": { + "name": "business_day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "denominations": { + "name": "denominations", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "counted_total": { + "name": "counted_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "counted_by": { + "name": "counted_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "counted_at": { + "name": "counted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "cash_counts_est_idx": { + "name": "cash_counts_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "business_day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cash_counts_organization_id_organizations_id_fk": { + "name": "cash_counts_organization_id_organizations_id_fk", + "tableFrom": "cash_counts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cash_counts_establishment_id_establishments_id_fk": { + "name": "cash_counts_establishment_id_establishments_id_fk", + "tableFrom": "cash_counts", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "cash_counts_counted_by_users_id_fk": { + "name": "cash_counts_counted_by_users_id_fk", + "tableFrom": "cash_counts", + "tableTo": "users", + "columnsFrom": [ + "counted_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cash_counts_cancelled_by_users_id_fk": { + "name": "cash_counts_cancelled_by_users_id_fk", + "tableFrom": "cash_counts", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "cash_counts_kind_ck": { + "name": "cash_counts_kind_ck", + "value": "\"cash_counts\".\"kind\" IN ('fermeture', 'ouverture')" + }, + "cash_counts_amounts_ck": { + "name": "cash_counts_amounts_ck", + "value": "\"cash_counts\".\"counted_total\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.cash_plan_items": { + "name": "cash_plan_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'once'" + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "cash_plan_org_idx": { + "name": "cash_plan_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cash_plan_items_organization_id_organizations_id_fk": { + "name": "cash_plan_items_organization_id_organizations_id_fk", + "tableFrom": "cash_plan_items", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cash_plan_items_establishment_id_establishments_id_fk": { + "name": "cash_plan_items_establishment_id_establishments_id_fk", + "tableFrom": "cash_plan_items", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "cash_plan_items_created_by_users_id_fk": { + "name": "cash_plan_items_created_by_users_id_fk", + "tableFrom": "cash_plan_items", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "cash_plan_recurrence_ck": { + "name": "cash_plan_recurrence_ck", + "value": "\"cash_plan_items\".\"recurrence\" IN ('once', 'weekly', 'monthly', 'quarterly')" + }, + "cash_plan_amount_ck": { + "name": "cash_plan_amount_ck", + "value": "\"cash_plan_items\".\"amount\" <> 0" + }, + "cash_plan_end_ck": { + "name": "cash_plan_end_ck", + "value": "\"cash_plan_items\".\"end_date\" IS NULL OR \"cash_plan_items\".\"end_date\" >= \"cash_plan_items\".\"start_date\"" + } + }, + "isRLSEnabled": false + }, + "public.cash_withdrawals": { + "name": "cash_withdrawals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "business_day": { + "name": "business_day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "recorded_at": { + "name": "recorded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "cash_withdrawals_est_idx": { + "name": "cash_withdrawals_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "business_day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cash_withdrawals_organization_id_organizations_id_fk": { + "name": "cash_withdrawals_organization_id_organizations_id_fk", + "tableFrom": "cash_withdrawals", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cash_withdrawals_establishment_id_establishments_id_fk": { + "name": "cash_withdrawals_establishment_id_establishments_id_fk", + "tableFrom": "cash_withdrawals", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "cash_withdrawals_recorded_by_users_id_fk": { + "name": "cash_withdrawals_recorded_by_users_id_fk", + "tableFrom": "cash_withdrawals", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cash_withdrawals_cancelled_by_users_id_fk": { + "name": "cash_withdrawals_cancelled_by_users_id_fk", + "tableFrom": "cash_withdrawals", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "cash_withdrawals_kind_ck": { + "name": "cash_withdrawals_kind_ck", + "value": "\"cash_withdrawals\".\"kind\" IN ('fournisseur', 'banque', 'pourboires', 'avance', 'autre')" + }, + "cash_withdrawals_amount_ck": { + "name": "cash_withdrawals_amount_ck", + "value": "\"cash_withdrawals\".\"amount\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.catalog_price_changes": { + "name": "catalog_price_changes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "old_price_ht": { + "name": "old_price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": false + }, + "new_price_ht": { + "name": "new_price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": true + }, + "effective_date": { + "name": "effective_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "catalog_price_changes_org_idx": { + "name": "catalog_price_changes_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "effective_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_price_changes_organization_id_organizations_id_fk": { + "name": "catalog_price_changes_organization_id_organizations_id_fk", + "tableFrom": "catalog_price_changes", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "catalog_price_changes_item_id_purchase_items_id_fk": { + "name": "catalog_price_changes_item_id_purchase_items_id_fk", + "tableFrom": "catalog_price_changes", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "catalog_price_changes_supplier_id_suppliers_id_fk": { + "name": "catalog_price_changes_supplier_id_suppliers_id_fk", + "tableFrom": "catalog_price_changes", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "catalog_price_changes_created_by_users_id_fk": { + "name": "catalog_price_changes_created_by_users_id_fk", + "tableFrom": "catalog_price_changes", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "catalog_price_changes_source_ck": { + "name": "catalog_price_changes_source_ck", + "value": "\"catalog_price_changes\".\"source\" IN ('import', 'manual')" + }, + "catalog_price_changes_price_ck": { + "name": "catalog_price_changes_price_ck", + "value": "\"catalog_price_changes\".\"new_price_ht\" >= 0 AND (\"catalog_price_changes\".\"old_price_ht\" IS NULL OR \"catalog_price_changes\".\"old_price_ht\" >= 0)" + } + }, + "isRLSEnabled": false + }, + "public.checklist_run_photos": { + "name": "checklist_run_photos", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_index": { + "name": "item_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "checklist_run_photos_uq": { + "name": "checklist_run_photos_uq", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_index", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "checklist_run_photos_organization_id_organizations_id_fk": { + "name": "checklist_run_photos_organization_id_organizations_id_fk", + "tableFrom": "checklist_run_photos", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "checklist_run_photos_establishment_id_establishments_id_fk": { + "name": "checklist_run_photos_establishment_id_establishments_id_fk", + "tableFrom": "checklist_run_photos", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "checklist_run_photos_run_id_checklist_runs_id_fk": { + "name": "checklist_run_photos_run_id_checklist_runs_id_fk", + "tableFrom": "checklist_run_photos", + "tableTo": "checklist_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.checklist_runs": { + "name": "checklist_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "template_id": { + "name": "template_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "template_name": { + "name": "template_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "done_at": { + "name": "done_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "answers": { + "name": "answers", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "yes_count": { + "name": "yes_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "no_count": { + "name": "no_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "na_count": { + "name": "na_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "moment": { + "name": "moment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo_count": { + "name": "photo_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "checklist_runs_est_idx": { + "name": "checklist_runs_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "done_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "checklist_runs_organization_id_organizations_id_fk": { + "name": "checklist_runs_organization_id_organizations_id_fk", + "tableFrom": "checklist_runs", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "checklist_runs_establishment_id_establishments_id_fk": { + "name": "checklist_runs_establishment_id_establishments_id_fk", + "tableFrom": "checklist_runs", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "checklist_runs_template_id_checklist_templates_id_fk": { + "name": "checklist_runs_template_id_checklist_templates_id_fk", + "tableFrom": "checklist_runs", + "tableTo": "checklist_templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "checklist_runs_recorded_by_users_id_fk": { + "name": "checklist_runs_recorded_by_users_id_fk", + "tableFrom": "checklist_runs", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "checklist_runs_cancelled_by_users_id_fk": { + "name": "checklist_runs_cancelled_by_users_id_fk", + "tableFrom": "checklist_runs", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.checklist_templates": { + "name": "checklist_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "items": { + "name": "items", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "due_by": { + "name": "due_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "moment": { + "name": "moment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "team": { + "name": "team", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo_items": { + "name": "photo_items", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "checklist_templates_est_idx": { + "name": "checklist_templates_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "checklist_templates_organization_id_organizations_id_fk": { + "name": "checklist_templates_organization_id_organizations_id_fk", + "tableFrom": "checklist_templates", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "checklist_templates_establishment_id_establishments_id_fk": { + "name": "checklist_templates_establishment_id_establishments_id_fk", + "tableFrom": "checklist_templates", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "checklist_templates_created_by_users_id_fk": { + "name": "checklist_templates_created_by_users_id_fk", + "tableFrom": "checklist_templates", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "checklist_templates_moment_ck": { + "name": "checklist_templates_moment_ck", + "value": "\"checklist_templates\".\"moment\" IS NULL OR \"checklist_templates\".\"moment\" IN ('ouverture', 'service', 'fermeture')" + } + }, + "isRLSEnabled": false + }, + "public.cleaning_records": { + "name": "cleaning_records", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "done_at": { + "name": "done_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "cleaning_records_est_idx": { + "name": "cleaning_records_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "done_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cleaning_records_task_idx": { + "name": "cleaning_records_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "done_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cleaning_records_organization_id_organizations_id_fk": { + "name": "cleaning_records_organization_id_organizations_id_fk", + "tableFrom": "cleaning_records", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cleaning_records_establishment_id_establishments_id_fk": { + "name": "cleaning_records_establishment_id_establishments_id_fk", + "tableFrom": "cleaning_records", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "cleaning_records_task_id_cleaning_tasks_id_fk": { + "name": "cleaning_records_task_id_cleaning_tasks_id_fk", + "tableFrom": "cleaning_records", + "tableTo": "cleaning_tasks", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "cleaning_records_recorded_by_users_id_fk": { + "name": "cleaning_records_recorded_by_users_id_fk", + "tableFrom": "cleaning_records", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cleaning_records_cancelled_by_users_id_fk": { + "name": "cleaning_records_cancelled_by_users_id_fk", + "tableFrom": "cleaning_records", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cleaning_tasks": { + "name": "cleaning_tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "zone_id": { + "name": "zone_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "frequency": { + "name": "frequency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "due_by": { + "name": "due_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "cleaning_tasks_zone_idx": { + "name": "cleaning_tasks_zone_idx", + "columns": [ + { + "expression": "zone_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cleaning_tasks_organization_id_organizations_id_fk": { + "name": "cleaning_tasks_organization_id_organizations_id_fk", + "tableFrom": "cleaning_tasks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cleaning_tasks_zone_id_cleaning_zones_id_fk": { + "name": "cleaning_tasks_zone_id_cleaning_zones_id_fk", + "tableFrom": "cleaning_tasks", + "tableTo": "cleaning_zones", + "columnsFrom": [ + "zone_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "cleaning_tasks_freq_ck": { + "name": "cleaning_tasks_freq_ck", + "value": "\"cleaning_tasks\".\"frequency\" IN ('service', 'jour', 'semaine', 'mois')" + } + }, + "isRLSEnabled": false + }, + "public.cleaning_zones": { + "name": "cleaning_zones", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "cleaning_zones_est_idx": { + "name": "cleaning_zones_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cleaning_zones_organization_id_organizations_id_fk": { + "name": "cleaning_zones_organization_id_organizations_id_fk", + "tableFrom": "cleaning_zones", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cleaning_zones_establishment_id_establishments_id_fk": { + "name": "cleaning_zones_establishment_id_establishments_id_fk", + "tableFrom": "cleaning_zones", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.clock_event_photos": { + "name": "clock_event_photos", + "schema": "", + "columns": { + "event_id": { + "name": "event_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "clock_event_photos_org_idx": { + "name": "clock_event_photos_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "clock_event_photos_event_id_clock_events_id_fk": { + "name": "clock_event_photos_event_id_clock_events_id_fk", + "tableFrom": "clock_event_photos", + "tableTo": "clock_events", + "columnsFrom": [ + "event_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "clock_event_photos_organization_id_organizations_id_fk": { + "name": "clock_event_photos_organization_id_organizations_id_fk", + "tableFrom": "clock_event_photos", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "clock_event_photos_size_ck": { + "name": "clock_event_photos_size_ck", + "value": "octet_length(\"clock_event_photos\".\"data\") <= 307200" + } + }, + "isRLSEnabled": false + }, + "public.clock_events": { + "name": "clock_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "at": { + "name": "at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ok'" + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "reviewed_by": { + "name": "reviewed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "reviewed_at": { + "name": "reviewed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "geo_distance_m": { + "name": "geo_distance_m", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "geo_accuracy_m": { + "name": "geo_accuracy_m", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "clock_events_est_day_idx": { + "name": "clock_events_est_day_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "clock_events_emp_day_idx": { + "name": "clock_events_emp_day_idx", + "columns": [ + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "day", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "clock_events_organization_id_organizations_id_fk": { + "name": "clock_events_organization_id_organizations_id_fk", + "tableFrom": "clock_events", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "clock_events_establishment_id_establishments_id_fk": { + "name": "clock_events_establishment_id_establishments_id_fk", + "tableFrom": "clock_events", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "clock_events_employee_id_employees_id_fk": { + "name": "clock_events_employee_id_employees_id_fk", + "tableFrom": "clock_events", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "clock_events_created_by_users_id_fk": { + "name": "clock_events_created_by_users_id_fk", + "tableFrom": "clock_events", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "clock_events_reviewed_by_users_id_fk": { + "name": "clock_events_reviewed_by_users_id_fk", + "tableFrom": "clock_events", + "tableTo": "users", + "columnsFrom": [ + "reviewed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "clock_events_kind_ck": { + "name": "clock_events_kind_ck", + "value": "\"clock_events\".\"kind\" IN ('in', 'break_start', 'break_end', 'out')" + }, + "clock_events_source_ck": { + "name": "clock_events_source_ck", + "value": "\"clock_events\".\"source\" IN ('borne', 'manuel', 'hors_ligne', 'qr', 'telephone')" + }, + "clock_events_status_ck": { + "name": "clock_events_status_ck", + "value": "\"clock_events\".\"status\" IN ('ok', 'a_valider', 'annule')" + } + }, + "isRLSEnabled": false + }, + "public.clock_pins": { + "name": "clock_pins", + "schema": "", + "columns": { + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "pin_hash": { + "name": "pin_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "failed_attempts": { + "name": "failed_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "locked_until": { + "name": "locked_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "clock_pins_employee_id_employees_id_fk": { + "name": "clock_pins_employee_id_employees_id_fk", + "tableFrom": "clock_pins", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "clock_pins_organization_id_organizations_id_fk": { + "name": "clock_pins_organization_id_organizations_id_fk", + "tableFrom": "clock_pins", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "clock_pins_updated_by_users_id_fk": { + "name": "clock_pins_updated_by_users_id_fk", + "tableFrom": "clock_pins", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.clock_qr_settings": { + "name": "clock_qr_settings", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone_enabled": { + "name": "phone_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "geo_lat": { + "name": "geo_lat", + "type": "numeric(9, 6)", + "primaryKey": false, + "notNull": false + }, + "geo_lng": { + "name": "geo_lng", + "type": "numeric(9, 6)", + "primaryKey": false, + "notNull": false + }, + "geo_radius_m": { + "name": "geo_radius_m", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "auto_apply": { + "name": "auto_apply", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "auto_apply_by": { + "name": "auto_apply_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "auto_applied_day": { + "name": "auto_applied_day", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "pin_by_employee": { + "name": "pin_by_employee", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "clock_qr_settings_establishment_id_establishments_id_fk": { + "name": "clock_qr_settings_establishment_id_establishments_id_fk", + "tableFrom": "clock_qr_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "clock_qr_settings_organization_id_organizations_id_fk": { + "name": "clock_qr_settings_organization_id_organizations_id_fk", + "tableFrom": "clock_qr_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "clock_qr_settings_auto_apply_by_users_id_fk": { + "name": "clock_qr_settings_auto_apply_by_users_id_fk", + "tableFrom": "clock_qr_settings", + "tableTo": "users", + "columnsFrom": [ + "auto_apply_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "clock_qr_settings_updated_by_users_id_fk": { + "name": "clock_qr_settings_updated_by_users_id_fk", + "tableFrom": "clock_qr_settings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.companies": { + "name": "companies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "legal_name": { + "name": "legal_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "legal_form": { + "name": "legal_form", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "siren": { + "name": "siren", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vat_number": { + "name": "vat_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_holding": { + "name": "is_holding", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "hr_settings": { + "name": "hr_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "calendar_settings": { + "name": "calendar_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "tax_settings": { + "name": "tax_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "companies_org_idx": { + "name": "companies_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "companies_organization_id_organizations_id_fk": { + "name": "companies_organization_id_organizations_id_fk", + "tableFrom": "companies", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "companies_siren_ck": { + "name": "companies_siren_ck", + "value": "\"companies\".\"siren\" IS NULL OR \"companies\".\"siren\" ~ '^[0-9]{9}$'" + } + }, + "isRLSEnabled": false + }, + "public.company_holdings": { + "name": "company_holdings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "parent_company_id": { + "name": "parent_company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "child_company_id": { + "name": "child_company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "ownership_pct": { + "name": "ownership_pct", + "type": "numeric(7, 4)", + "primaryKey": false, + "notNull": true + }, + "since": { + "name": "since", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "holdings_pair_uq": { + "name": "holdings_pair_uq", + "columns": [ + { + "expression": "parent_company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "child_company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "company_holdings_organization_id_organizations_id_fk": { + "name": "company_holdings_organization_id_organizations_id_fk", + "tableFrom": "company_holdings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "company_holdings_parent_company_id_companies_id_fk": { + "name": "company_holdings_parent_company_id_companies_id_fk", + "tableFrom": "company_holdings", + "tableTo": "companies", + "columnsFrom": [ + "parent_company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "company_holdings_child_company_id_companies_id_fk": { + "name": "company_holdings_child_company_id_companies_id_fk", + "tableFrom": "company_holdings", + "tableTo": "companies", + "columnsFrom": [ + "child_company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "holdings_pct_ck": { + "name": "holdings_pct_ck", + "value": "\"company_holdings\".\"ownership_pct\" > 0 AND \"company_holdings\".\"ownership_pct\" <= 100" + }, + "holdings_self_ck": { + "name": "holdings_self_ck", + "value": "\"company_holdings\".\"parent_company_id\" <> \"company_holdings\".\"child_company_id\"" + } + }, + "isRLSEnabled": false + }, + "public.compliance_items": { + "name": "compliance_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "obligation_id": { + "name": "obligation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verified_by": { + "name": "verified_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "verified_at": { + "name": "verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "compliance_items_uq": { + "name": "compliance_items_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "obligation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "compliance_items_document_idx": { + "name": "compliance_items_document_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "compliance_items_organization_id_organizations_id_fk": { + "name": "compliance_items_organization_id_organizations_id_fk", + "tableFrom": "compliance_items", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "compliance_items_establishment_id_establishments_id_fk": { + "name": "compliance_items_establishment_id_establishments_id_fk", + "tableFrom": "compliance_items", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "compliance_items_obligation_id_regulatory_obligations_id_fk": { + "name": "compliance_items_obligation_id_regulatory_obligations_id_fk", + "tableFrom": "compliance_items", + "tableTo": "regulatory_obligations", + "columnsFrom": [ + "obligation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "compliance_items_document_id_business_documents_id_fk": { + "name": "compliance_items_document_id_business_documents_id_fk", + "tableFrom": "compliance_items", + "tableTo": "business_documents", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "compliance_items_verified_by_users_id_fk": { + "name": "compliance_items_verified_by_users_id_fk", + "tableFrom": "compliance_items", + "tableTo": "users", + "columnsFrom": [ + "verified_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "compliance_items_status_ck": { + "name": "compliance_items_status_ck", + "value": "\"compliance_items\".\"status\" IN ('verifie', 'non_applicable_declare', 'en_cours')" + }, + "compliance_items_in_progress_ck": { + "name": "compliance_items_in_progress_ck", + "value": "\"compliance_items\".\"status\" <> 'en_cours' OR \"compliance_items\".\"note\" IS NOT NULL" + }, + "compliance_items_proof_ck": { + "name": "compliance_items_proof_ck", + "value": "(\"compliance_items\".\"status\" <> 'verifie' OR \"compliance_items\".\"document_id\" IS NOT NULL) AND (\"compliance_items\".\"status\" <> 'non_applicable_declare' OR \"compliance_items\".\"reason\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.context_observations": { + "name": "context_observations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "series": { + "name": "series", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "period": { + "name": "period", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "numeric(12, 3)", + "primaryKey": false, + "notNull": false + }, + "extra": { + "name": "extra", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "fetched_at": { + "name": "fetched_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "context_observations_uq": { + "name": "context_observations_uq", + "columns": [ + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "series", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "period", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "context_observations_source_ck": { + "name": "context_observations_source_ck", + "value": "\"context_observations\".\"source\" IN ('meteo_france', 'insee')" + } + }, + "isRLSEnabled": false + }, + "public.context_sources": { + "name": "context_sources", + "schema": "", + "columns": { + "source": { + "name": "source", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "last_attempt_at": { + "name": "last_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_success_at": { + "name": "last_success_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rows": { + "name": "rows", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.conversation_members": { + "name": "conversation_members", + "schema": "", + "columns": { + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "last_read_at": { + "name": "last_read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "notified_at": { + "name": "notified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "conversation_members_user_idx": { + "name": "conversation_members_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "conversation_members_conversation_id_conversations_id_fk": { + "name": "conversation_members_conversation_id_conversations_id_fk", + "tableFrom": "conversation_members", + "tableTo": "conversations", + "columnsFrom": [ + "conversation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "conversation_members_user_id_users_id_fk": { + "name": "conversation_members_user_id_users_id_fk", + "tableFrom": "conversation_members", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "conversation_members_conversation_id_user_id_pk": { + "name": "conversation_members_conversation_id_user_id_pk", + "columns": [ + "conversation_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.conversations": { + "name": "conversations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_group": { + "name": "is_group", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "last_message_at": { + "name": "last_message_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "conversations_org_idx": { + "name": "conversations_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "conversations_organization_id_organizations_id_fk": { + "name": "conversations_organization_id_organizations_id_fk", + "tableFrom": "conversations", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "conversations_created_by_users_id_fk": { + "name": "conversations_created_by_users_id_fk", + "tableFrom": "conversations", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.credit_request_lines": { + "name": "credit_request_lines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "unit_price_ht": { + "name": "unit_price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": true + }, + "amount_ht": { + "name": "amount_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credit_request_lines_req_idx": { + "name": "credit_request_lines_req_idx", + "columns": [ + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "credit_request_lines_organization_id_organizations_id_fk": { + "name": "credit_request_lines_organization_id_organizations_id_fk", + "tableFrom": "credit_request_lines", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credit_request_lines_request_id_credit_requests_id_fk": { + "name": "credit_request_lines_request_id_credit_requests_id_fk", + "tableFrom": "credit_request_lines", + "tableTo": "credit_requests", + "columnsFrom": [ + "request_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credit_request_lines_item_id_purchase_items_id_fk": { + "name": "credit_request_lines_item_id_purchase_items_id_fk", + "tableFrom": "credit_request_lines", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "credit_request_lines_amount_ck": { + "name": "credit_request_lines_amount_ck", + "value": "\"credit_request_lines\".\"quantity\" > 0 AND \"credit_request_lines\".\"unit_price_ht\" > 0 AND \"credit_request_lines\".\"amount_ht\" > 0" + }, + "credit_request_lines_reason_ck": { + "name": "credit_request_lines_reason_ck", + "value": "\"credit_request_lines\".\"reason\" IN ('manquant', 'abime', 'non_conforme', 'erreur_prix', 'erreur_quantite', 'dlc_courte', 'autre')" + } + }, + "isRLSEnabled": false + }, + "public.credit_request_photos": { + "name": "credit_request_photos", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credit_request_photos_req_idx": { + "name": "credit_request_photos_req_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "credit_request_photos_organization_id_organizations_id_fk": { + "name": "credit_request_photos_organization_id_organizations_id_fk", + "tableFrom": "credit_request_photos", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credit_request_photos_request_id_credit_requests_id_fk": { + "name": "credit_request_photos_request_id_credit_requests_id_fk", + "tableFrom": "credit_request_photos", + "tableTo": "credit_requests", + "columnsFrom": [ + "request_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credit_request_photos_created_by_users_id_fk": { + "name": "credit_request_photos_created_by_users_id_fk", + "tableFrom": "credit_request_photos", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "credit_request_photos_size_ck": { + "name": "credit_request_photos_size_ck", + "value": "\"credit_request_photos\".\"size\" <= 5242880" + }, + "credit_request_photos_mime_ck": { + "name": "credit_request_photos_mime_ck", + "value": "\"credit_request_photos\".\"mime\" IN ('image/jpeg', 'image/png', 'image/webp')" + } + }, + "isRLSEnabled": false + }, + "public.credit_requests": { + "name": "credit_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "request_date": { + "name": "request_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "purchase_order_id": { + "name": "purchase_order_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "invoice_id": { + "name": "invoice_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "total_ht": { + "name": "total_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "credited_ht": { + "name": "credited_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "closed_by": { + "name": "closed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "close_reason": { + "name": "close_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credit_requests_est_idx": { + "name": "credit_requests_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credit_requests_number_uq": { + "name": "credit_requests_number_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "credit_requests_organization_id_organizations_id_fk": { + "name": "credit_requests_organization_id_organizations_id_fk", + "tableFrom": "credit_requests", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credit_requests_establishment_id_establishments_id_fk": { + "name": "credit_requests_establishment_id_establishments_id_fk", + "tableFrom": "credit_requests", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "credit_requests_supplier_id_suppliers_id_fk": { + "name": "credit_requests_supplier_id_suppliers_id_fk", + "tableFrom": "credit_requests", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "credit_requests_purchase_order_id_purchase_orders_id_fk": { + "name": "credit_requests_purchase_order_id_purchase_orders_id_fk", + "tableFrom": "credit_requests", + "tableTo": "purchase_orders", + "columnsFrom": [ + "purchase_order_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "credit_requests_invoice_id_purchase_invoices_id_fk": { + "name": "credit_requests_invoice_id_purchase_invoices_id_fk", + "tableFrom": "credit_requests", + "tableTo": "purchase_invoices", + "columnsFrom": [ + "invoice_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "credit_requests_closed_by_users_id_fk": { + "name": "credit_requests_closed_by_users_id_fk", + "tableFrom": "credit_requests", + "tableTo": "users", + "columnsFrom": [ + "closed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "credit_requests_created_by_users_id_fk": { + "name": "credit_requests_created_by_users_id_fk", + "tableFrom": "credit_requests", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "credit_requests_status_ck": { + "name": "credit_requests_status_ck", + "value": "\"credit_requests\".\"status\" IN ('open', 'sent', 'accepted', 'refused', 'cancelled')" + }, + "credit_requests_total_ck": { + "name": "credit_requests_total_ck", + "value": "\"credit_requests\".\"total_ht\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.customers": { + "name": "customers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "first_name": { + "name": "first_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_name": { + "name": "last_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "allergies": { + "name": "allergies", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "preferences": { + "name": "preferences", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "birthday": { + "name": "birthday", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "vip": { + "name": "vip", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "tags": { + "name": "tags", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "consent_email": { + "name": "consent_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "consent_sms": { + "name": "consent_sms", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "consent_at": { + "name": "consent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "consent_source": { + "name": "consent_source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "anonymized_at": { + "name": "anonymized_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "customers_org_idx": { + "name": "customers_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "customers_phone_idx": { + "name": "customers_phone_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "phone", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "customers_email_idx": { + "name": "customers_email_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "customers_organization_id_organizations_id_fk": { + "name": "customers_organization_id_organizations_id_fk", + "tableFrom": "customers", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dashboard_layouts": { + "name": "dashboard_layouts", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "preset": { + "name": "preset", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "blocks": { + "name": "blocks", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "dashboard_layouts_user_id_users_id_fk": { + "name": "dashboard_layouts_user_id_users_id_fk", + "tableFrom": "dashboard_layouts", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dashboard_layouts_organization_id_organizations_id_fk": { + "name": "dashboard_layouts_organization_id_organizations_id_fk", + "tableFrom": "dashboard_layouts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "dashboard_layouts_user_id_organization_id_pk": { + "name": "dashboard_layouts_user_id_organization_id_pk", + "columns": [ + "user_id", + "organization_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.delivery_note_scans": { + "name": "delivery_note_scans", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "order_id": { + "name": "order_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "extracted": { + "name": "extracted", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric(12, 6)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "delivery_note_scans_order_idx": { + "name": "delivery_note_scans_order_idx", + "columns": [ + { + "expression": "order_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "delivery_note_scans_org_idx": { + "name": "delivery_note_scans_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "delivery_note_scans_organization_id_organizations_id_fk": { + "name": "delivery_note_scans_organization_id_organizations_id_fk", + "tableFrom": "delivery_note_scans", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "delivery_note_scans_establishment_id_establishments_id_fk": { + "name": "delivery_note_scans_establishment_id_establishments_id_fk", + "tableFrom": "delivery_note_scans", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "delivery_note_scans_order_id_purchase_orders_id_fk": { + "name": "delivery_note_scans_order_id_purchase_orders_id_fk", + "tableFrom": "delivery_note_scans", + "tableTo": "purchase_orders", + "columnsFrom": [ + "order_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "delivery_note_scans_created_by_users_id_fk": { + "name": "delivery_note_scans_created_by_users_id_fk", + "tableFrom": "delivery_note_scans", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "delivery_note_scans_status_ck": { + "name": "delivery_note_scans_status_ck", + "value": "\"delivery_note_scans\".\"status\" IN ('lu', 'echec')" + }, + "delivery_note_scans_size_ck": { + "name": "delivery_note_scans_size_ck", + "value": "\"delivery_note_scans\".\"size\" > 0 AND \"delivery_note_scans\".\"size\" <= 10485760" + } + }, + "isRLSEnabled": false + }, + "public.dish_quality_checks": { + "name": "dish_quality_checks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "recipe_id": { + "name": "recipe_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "checked_by": { + "name": "checked_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "weight_g": { + "name": "weight_g", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "target_weight_g": { + "name": "target_weight_g", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tolerance_pct": { + "name": "tolerance_pct", + "type": "smallint", + "primaryKey": false, + "notNull": false + }, + "plating_ok": { + "name": "plating_ok", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "temperature_ok": { + "name": "temperature_ok", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "conform": { + "name": "conform", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "dish_quality_checks_est_idx": { + "name": "dish_quality_checks_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dish_quality_checks_recipe_idx": { + "name": "dish_quality_checks_recipe_idx", + "columns": [ + { + "expression": "recipe_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dish_quality_checks_organization_id_organizations_id_fk": { + "name": "dish_quality_checks_organization_id_organizations_id_fk", + "tableFrom": "dish_quality_checks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dish_quality_checks_establishment_id_establishments_id_fk": { + "name": "dish_quality_checks_establishment_id_establishments_id_fk", + "tableFrom": "dish_quality_checks", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dish_quality_checks_recipe_id_recipes_id_fk": { + "name": "dish_quality_checks_recipe_id_recipes_id_fk", + "tableFrom": "dish_quality_checks", + "tableTo": "recipes", + "columnsFrom": [ + "recipe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dish_quality_checks_checked_by_users_id_fk": { + "name": "dish_quality_checks_checked_by_users_id_fk", + "tableFrom": "dish_quality_checks", + "tableTo": "users", + "columnsFrom": [ + "checked_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "dish_quality_checks_weight_ck": { + "name": "dish_quality_checks_weight_ck", + "value": "(\"dish_quality_checks\".\"weight_g\" IS NULL OR \"dish_quality_checks\".\"weight_g\" BETWEEN 1 AND 20000) AND (\"dish_quality_checks\".\"target_weight_g\" IS NULL OR \"dish_quality_checks\".\"target_weight_g\" BETWEEN 1 AND 20000)" + } + }, + "isRLSEnabled": false + }, + "public.duerp_risks": { + "name": "duerp_risks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "unit_id": { + "name": "unit_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "hazard": { + "name": "hazard", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "situation": { + "name": "situation", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "existing_measures": { + "name": "existing_measures", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "gravity": { + "name": "gravity", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "probability": { + "name": "probability", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "planned_action": { + "name": "planned_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_owner": { + "name": "action_owner", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_due": { + "name": "action_due", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "action_status": { + "name": "action_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "from_template": { + "name": "from_template", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "duerp_risks_unit_idx": { + "name": "duerp_risks_unit_idx", + "columns": [ + { + "expression": "unit_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "duerp_risks_est_idx": { + "name": "duerp_risks_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "duerp_risks_organization_id_organizations_id_fk": { + "name": "duerp_risks_organization_id_organizations_id_fk", + "tableFrom": "duerp_risks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "duerp_risks_establishment_id_establishments_id_fk": { + "name": "duerp_risks_establishment_id_establishments_id_fk", + "tableFrom": "duerp_risks", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "duerp_risks_unit_id_duerp_units_id_fk": { + "name": "duerp_risks_unit_id_duerp_units_id_fk", + "tableFrom": "duerp_risks", + "tableTo": "duerp_units", + "columnsFrom": [ + "unit_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "duerp_risks_scale_ck": { + "name": "duerp_risks_scale_ck", + "value": "(\"duerp_risks\".\"gravity\" IS NULL OR \"duerp_risks\".\"gravity\" BETWEEN 1 AND 4) AND (\"duerp_risks\".\"probability\" IS NULL OR \"duerp_risks\".\"probability\" BETWEEN 1 AND 4)" + }, + "duerp_risks_action_ck": { + "name": "duerp_risks_action_ck", + "value": "\"duerp_risks\".\"action_status\" IS NULL OR (\"duerp_risks\".\"action_status\" IN ('a_faire', 'en_cours', 'faite') AND \"duerp_risks\".\"planned_action\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.duerp_units": { + "name": "duerp_units", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "headcount": { + "name": "headcount", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "duerp_units_est_idx": { + "name": "duerp_units_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "duerp_units_name_uq": { + "name": "duerp_units_name_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"duerp_units\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "duerp_units_organization_id_organizations_id_fk": { + "name": "duerp_units_organization_id_organizations_id_fk", + "tableFrom": "duerp_units", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "duerp_units_establishment_id_establishments_id_fk": { + "name": "duerp_units_establishment_id_establishments_id_fk", + "tableFrom": "duerp_units", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "duerp_units_headcount_ck": { + "name": "duerp_units_headcount_ck", + "value": "\"duerp_units\".\"headcount\" IS NULL OR \"duerp_units\".\"headcount\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.duerp_versions": { + "name": "duerp_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version_no": { + "name": "version_no", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "snapshot": { + "name": "snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "published_by": { + "name": "published_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "published_by_name": { + "name": "published_by_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "duerp_versions_no_uq": { + "name": "duerp_versions_no_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version_no", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "duerp_versions_org_idx": { + "name": "duerp_versions_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "duerp_versions_organization_id_organizations_id_fk": { + "name": "duerp_versions_organization_id_organizations_id_fk", + "tableFrom": "duerp_versions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "duerp_versions_establishment_id_establishments_id_fk": { + "name": "duerp_versions_establishment_id_establishments_id_fk", + "tableFrom": "duerp_versions", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.email_attachments": { + "name": "email_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'application/pdf'" + }, + "content": { + "name": "content", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_attachments_org_idx": { + "name": "email_attachments_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "email_attachments_organization_id_organizations_id_fk": { + "name": "email_attachments_organization_id_organizations_id_fk", + "tableFrom": "email_attachments", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "email_attachments_mime_ck": { + "name": "email_attachments_mime_ck", + "value": "\"email_attachments\".\"mime\" = 'application/pdf'" + }, + "email_attachments_size_ck": { + "name": "email_attachments_size_ck", + "value": "\"email_attachments\".\"size\" >= 0 AND \"email_attachments\".\"size\" <= 5242880" + } + }, + "isRLSEnabled": false + }, + "public.email_outbox": { + "name": "email_outbox", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "to_email": { + "name": "to_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "signature_request_id": { + "name": "signature_request_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "attachment_id": { + "name": "attachment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "list_unsubscribe": { + "name": "list_unsubscribe", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en_attente'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_outbox_pending_idx": { + "name": "email_outbox_pending_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "email_outbox_organization_id_organizations_id_fk": { + "name": "email_outbox_organization_id_organizations_id_fk", + "tableFrom": "email_outbox", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "email_outbox_attachment_id_email_attachments_id_fk": { + "name": "email_outbox_attachment_id_email_attachments_id_fk", + "tableFrom": "email_outbox", + "tableTo": "email_attachments", + "columnsFrom": [ + "attachment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "email_outbox_status_ck": { + "name": "email_outbox_status_ck", + "value": "\"email_outbox\".\"status\" IN ('en_attente', 'envoye', 'echec')" + } + }, + "isRLSEnabled": false + }, + "public.employee_contracts": { + "name": "employee_contracts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "amends_id": { + "name": "amends_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "trial_end_date": { + "name": "trial_end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "step": { + "name": "step", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'employe'" + }, + "weekly_hours": { + "name": "weekly_hours", + "type": "numeric(6, 2)", + "primaryKey": false, + "notNull": false + }, + "hourly_rate_gross": { + "name": "hourly_rate_gross", + "type": "numeric(12, 4)", + "primaryKey": false, + "notNull": false + }, + "monthly_gross": { + "name": "monthly_gross", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "cdd_reason": { + "name": "cdd_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "replaced_person": { + "name": "replaced_person", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "meal_benefit": { + "name": "meal_benefit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "end_reason": { + "name": "end_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "hire_time": { + "name": "hire_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dpae_status": { + "name": "dpae_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dpae_declared_on": { + "name": "dpae_declared_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "dpae_reference": { + "name": "dpae_reference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dpae_note": { + "name": "dpae_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "employee_contracts_emp_idx": { + "name": "employee_contracts_emp_idx", + "columns": [ + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "start_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "employee_contracts_organization_id_organizations_id_fk": { + "name": "employee_contracts_organization_id_organizations_id_fk", + "tableFrom": "employee_contracts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_contracts_employee_id_employees_id_fk": { + "name": "employee_contracts_employee_id_employees_id_fk", + "tableFrom": "employee_contracts", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_contracts_amends_id_employee_contracts_id_fk": { + "name": "employee_contracts_amends_id_employee_contracts_id_fk", + "tableFrom": "employee_contracts", + "tableTo": "employee_contracts", + "columnsFrom": [ + "amends_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "employee_contracts_created_by_users_id_fk": { + "name": "employee_contracts_created_by_users_id_fk", + "tableFrom": "employee_contracts", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "employee_contracts_dpae_ck": { + "name": "employee_contracts_dpae_ck", + "value": "(\"employee_contracts\".\"dpae_status\" IS NULL OR \"employee_contracts\".\"dpae_status\" IN ('enregistree', 'non_concernee_declaree')) AND (\"employee_contracts\".\"dpae_status\" IS DISTINCT FROM 'enregistree' OR \"employee_contracts\".\"dpae_declared_on\" IS NOT NULL) AND (\"employee_contracts\".\"dpae_status\" IS DISTINCT FROM 'non_concernee_declaree' OR \"employee_contracts\".\"dpae_note\" IS NOT NULL)" + }, + "employee_contracts_kind_ck": { + "name": "employee_contracts_kind_ck", + "value": "\"employee_contracts\".\"kind\" IN ('cdi', 'cdd', 'extra', 'saisonnier', 'apprentissage', 'professionnalisation', 'stage', 'dirigeant')" + }, + "employee_contracts_dates_ck": { + "name": "employee_contracts_dates_ck", + "value": "\"employee_contracts\".\"end_date\" IS NULL OR \"employee_contracts\".\"end_date\" >= \"employee_contracts\".\"start_date\"" + }, + "employee_contracts_category_ck": { + "name": "employee_contracts_category_ck", + "value": "\"employee_contracts\".\"category\" IN ('employe', 'agent_maitrise', 'cadre')" + }, + "employee_contracts_hours_ck": { + "name": "employee_contracts_hours_ck", + "value": "\"employee_contracts\".\"weekly_hours\" IS NULL OR (\"employee_contracts\".\"weekly_hours\" > 0 AND \"employee_contracts\".\"weekly_hours\" <= 48)" + }, + "employee_contracts_rate_ck": { + "name": "employee_contracts_rate_ck", + "value": "(\"employee_contracts\".\"hourly_rate_gross\" IS NULL OR \"employee_contracts\".\"hourly_rate_gross\" >= 0) AND (\"employee_contracts\".\"monthly_gross\" IS NULL OR \"employee_contracts\".\"monthly_gross\" >= 0)" + }, + "employee_contracts_hire_time_ck": { + "name": "employee_contracts_hire_time_ck", + "value": "\"employee_contracts\".\"hire_time\" IS NULL OR \"employee_contracts\".\"hire_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$'" + }, + "employee_contracts_meal_ck": { + "name": "employee_contracts_meal_ck", + "value": "\"employee_contracts\".\"meal_benefit\" IS NULL OR \"employee_contracts\".\"meal_benefit\" IN ('nature', 'indemnite', 'aucun')" + } + }, + "isRLSEnabled": false + }, + "public.employee_files": { + "name": "employee_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "period": { + "name": "period", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "duplicate_of_id": { + "name": "duplicate_of_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "visible_to_employee": { + "name": "visible_to_employee", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "employee_files_emp_idx": { + "name": "employee_files_emp_idx", + "columns": [ + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "employee_files_sha_idx": { + "name": "employee_files_sha_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sha256", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "employee_files_organization_id_organizations_id_fk": { + "name": "employee_files_organization_id_organizations_id_fk", + "tableFrom": "employee_files", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_files_employee_id_employees_id_fk": { + "name": "employee_files_employee_id_employees_id_fk", + "tableFrom": "employee_files", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_files_duplicate_of_id_employee_files_id_fk": { + "name": "employee_files_duplicate_of_id_employee_files_id_fk", + "tableFrom": "employee_files", + "tableTo": "employee_files", + "columnsFrom": [ + "duplicate_of_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "employee_files_uploaded_by_users_id_fk": { + "name": "employee_files_uploaded_by_users_id_fk", + "tableFrom": "employee_files", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "employee_files_size_ck": { + "name": "employee_files_size_ck", + "value": "\"employee_files\".\"size\" <= 5242880" + } + }, + "isRLSEnabled": false + }, + "public.employee_reviews": { + "name": "employee_reviews", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'prevu'" + }, + "scheduled_on": { + "name": "scheduled_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "done_on": { + "name": "done_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "reviewer_id": { + "name": "reviewer_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "objectives": { + "name": "objectives", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "training_wishes": { + "name": "training_wishes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "employee_comment": { + "name": "employee_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "file_id": { + "name": "file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "employee_reviews_emp_idx": { + "name": "employee_reviews_emp_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "employee_reviews_organization_id_organizations_id_fk": { + "name": "employee_reviews_organization_id_organizations_id_fk", + "tableFrom": "employee_reviews", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_reviews_employee_id_employees_id_fk": { + "name": "employee_reviews_employee_id_employees_id_fk", + "tableFrom": "employee_reviews", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_reviews_reviewer_id_users_id_fk": { + "name": "employee_reviews_reviewer_id_users_id_fk", + "tableFrom": "employee_reviews", + "tableTo": "users", + "columnsFrom": [ + "reviewer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "employee_reviews_file_id_employee_files_id_fk": { + "name": "employee_reviews_file_id_employee_files_id_fk", + "tableFrom": "employee_reviews", + "tableTo": "employee_files", + "columnsFrom": [ + "file_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "employee_reviews_created_by_users_id_fk": { + "name": "employee_reviews_created_by_users_id_fk", + "tableFrom": "employee_reviews", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "employee_reviews_kind_ck": { + "name": "employee_reviews_kind_ck", + "value": "\"employee_reviews\".\"kind\" IN ('annuel', 'professionnel', 'etat_des_lieux', 'fin_essai')" + }, + "employee_reviews_status_ck": { + "name": "employee_reviews_status_ck", + "value": "\"employee_reviews\".\"status\" IN ('prevu', 'realise', 'annule')" + }, + "employee_reviews_done_ck": { + "name": "employee_reviews_done_ck", + "value": "\"employee_reviews\".\"status\" <> 'realise' OR \"employee_reviews\".\"done_on\" IS NOT NULL" + }, + "employee_reviews_planned_ck": { + "name": "employee_reviews_planned_ck", + "value": "\"employee_reviews\".\"status\" <> 'prevu' OR \"employee_reviews\".\"scheduled_on\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.employee_skills": { + "name": "employee_skills", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "skill_id": { + "name": "skill_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "smallint", + "primaryKey": false, + "notNull": true + }, + "assessed_on": { + "name": "assessed_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "assessed_by": { + "name": "assessed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "employee_skills_organization_id_organizations_id_fk": { + "name": "employee_skills_organization_id_organizations_id_fk", + "tableFrom": "employee_skills", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_skills_employee_id_employees_id_fk": { + "name": "employee_skills_employee_id_employees_id_fk", + "tableFrom": "employee_skills", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_skills_skill_id_skills_id_fk": { + "name": "employee_skills_skill_id_skills_id_fk", + "tableFrom": "employee_skills", + "tableTo": "skills", + "columnsFrom": [ + "skill_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_skills_assessed_by_users_id_fk": { + "name": "employee_skills_assessed_by_users_id_fk", + "tableFrom": "employee_skills", + "tableTo": "users", + "columnsFrom": [ + "assessed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "employee_skills_employee_id_skill_id_pk": { + "name": "employee_skills_employee_id_skill_id_pk", + "columns": [ + "employee_id", + "skill_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "employee_skills_level_ck": { + "name": "employee_skills_level_ck", + "value": "\"employee_skills\".\"level\" BETWEEN 0 AND 4" + } + }, + "isRLSEnabled": false + }, + "public.employee_trainings": { + "name": "employee_trainings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'autre'" + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'realisee'" + }, + "planned_on": { + "name": "planned_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "done_on": { + "name": "done_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "valid_until": { + "name": "valid_until", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "hours": { + "name": "hours", + "type": "numeric(6, 2)", + "primaryKey": false, + "notNull": false + }, + "cost": { + "name": "cost", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "funded_by": { + "name": "funded_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "file_id": { + "name": "file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "employee_trainings_emp_idx": { + "name": "employee_trainings_emp_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "employee_trainings_organization_id_organizations_id_fk": { + "name": "employee_trainings_organization_id_organizations_id_fk", + "tableFrom": "employee_trainings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_trainings_employee_id_employees_id_fk": { + "name": "employee_trainings_employee_id_employees_id_fk", + "tableFrom": "employee_trainings", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employee_trainings_file_id_employee_files_id_fk": { + "name": "employee_trainings_file_id_employee_files_id_fk", + "tableFrom": "employee_trainings", + "tableTo": "employee_files", + "columnsFrom": [ + "file_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "employee_trainings_created_by_users_id_fk": { + "name": "employee_trainings_created_by_users_id_fk", + "tableFrom": "employee_trainings", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "employee_trainings_status_ck": { + "name": "employee_trainings_status_ck", + "value": "\"employee_trainings\".\"status\" IN ('prevue', 'realisee', 'annulee')" + }, + "employee_trainings_done_ck": { + "name": "employee_trainings_done_ck", + "value": "\"employee_trainings\".\"status\" <> 'realisee' OR \"employee_trainings\".\"done_on\" IS NOT NULL" + }, + "employee_trainings_valid_ck": { + "name": "employee_trainings_valid_ck", + "value": "\"employee_trainings\".\"valid_until\" IS NULL OR \"employee_trainings\".\"done_on\" IS NULL OR \"employee_trainings\".\"valid_until\" >= \"employee_trainings\".\"done_on\"" + }, + "employee_trainings_amounts_ck": { + "name": "employee_trainings_amounts_ck", + "value": "(\"employee_trainings\".\"hours\" IS NULL OR \"employee_trainings\".\"hours\" > 0) AND (\"employee_trainings\".\"cost\" IS NULL OR \"employee_trainings\".\"cost\" >= 0)" + } + }, + "isRLSEnabled": false + }, + "public.employees": { + "name": "employees", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "team": { + "name": "team", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "registry_number": { + "name": "registry_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "gender": { + "name": "gender", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "first_name": { + "name": "first_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "birth_name": { + "name": "birth_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_name": { + "name": "last_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "birth_date": { + "name": "birth_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "birth_place": { + "name": "birth_place", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "nationality": { + "name": "nationality", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "birth_country": { + "name": "birth_country", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "birth_department": { + "name": "birth_department", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "family_situation": { + "name": "family_situation", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "work_permit_type": { + "name": "work_permit_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "work_permit_number": { + "name": "work_permit_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "work_permit_expiry": { + "name": "work_permit_expiry", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "social_security_enc": { + "name": "social_security_enc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "iban_enc": { + "name": "iban_enc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bic": { + "name": "bic", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "account_holder": { + "name": "account_holder", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "address_line": { + "name": "address_line", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "postal_code": { + "name": "postal_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "city": { + "name": "city", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "emergency_contact": { + "name": "emergency_contact", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "emergency_phone": { + "name": "emergency_phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "disability": { + "name": "disability", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "medical_visit_date": { + "name": "medical_visit_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "medical_visit_next_due": { + "name": "medical_visit_next_due", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "reinforced_medical": { + "name": "reinforced_medical", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "planning_hidden": { + "name": "planning_hidden", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "employees_org_idx": { + "name": "employees_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "employees_registry_uq": { + "name": "employees_registry_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "registry_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "employees_organization_id_organizations_id_fk": { + "name": "employees_organization_id_organizations_id_fk", + "tableFrom": "employees", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employees_establishment_id_establishments_id_fk": { + "name": "employees_establishment_id_establishments_id_fk", + "tableFrom": "employees", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "employees_user_id_users_id_fk": { + "name": "employees_user_id_users_id_fk", + "tableFrom": "employees", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "employees_gender_ck": { + "name": "employees_gender_ck", + "value": "\"employees\".\"gender\" IS NULL OR \"employees\".\"gender\" IN ('F', 'M', 'X')" + }, + "employees_birth_department_ck": { + "name": "employees_birth_department_ck", + "value": "\"employees\".\"birth_department\" IS NULL OR \"employees\".\"birth_department\" ~ '^([0-9]{2}|2[AB]|9[78][0-9])$'" + } + }, + "isRLSEnabled": false + }, + "public.employer_signatures": { + "name": "employer_signatures", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "png": { + "name": "png", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "signer_name": { + "name": "signer_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "employer_signatures_company_uq": { + "name": "employer_signatures_company_uq", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "employer_signatures_organization_id_organizations_id_fk": { + "name": "employer_signatures_organization_id_organizations_id_fk", + "tableFrom": "employer_signatures", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employer_signatures_company_id_companies_id_fk": { + "name": "employer_signatures_company_id_companies_id_fk", + "tableFrom": "employer_signatures", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "employer_signatures_updated_by_users_id_fk": { + "name": "employer_signatures_updated_by_users_id_fk", + "tableFrom": "employer_signatures", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "employer_signatures_size_ck": { + "name": "employer_signatures_size_ck", + "value": "octet_length(\"employer_signatures\".\"png\") <= 102400" + } + }, + "isRLSEnabled": false + }, + "public.equipment": { + "name": "equipment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "temp_tracked": { + "name": "temp_tracked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "temp_min": { + "name": "temp_min", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "temp_max": { + "name": "temp_max", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "readings_per_day": { + "name": "readings_per_day", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 2 + }, + "brand": { + "name": "brand", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "serial_number": { + "name": "serial_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "installed_on": { + "name": "installed_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "warranty_until": { + "name": "warranty_until", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "service_partner": { + "name": "service_partner", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "service_phone": { + "name": "service_phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "service_every_months": { + "name": "service_every_months", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "purchase_price_ht": { + "name": "purchase_price_ht", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "equipment_est_idx": { + "name": "equipment_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "equipment_organization_id_organizations_id_fk": { + "name": "equipment_organization_id_organizations_id_fk", + "tableFrom": "equipment", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "equipment_establishment_id_establishments_id_fk": { + "name": "equipment_establishment_id_establishments_id_fk", + "tableFrom": "equipment", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "equipment_created_by_users_id_fk": { + "name": "equipment_created_by_users_id_fk", + "tableFrom": "equipment", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "equipment_range_ck": { + "name": "equipment_range_ck", + "value": "\"equipment\".\"temp_min\" IS NULL OR \"equipment\".\"temp_max\" IS NULL OR \"equipment\".\"temp_min\" <= \"equipment\".\"temp_max\"" + }, + "equipment_rpd_ck": { + "name": "equipment_rpd_ck", + "value": "\"equipment\".\"readings_per_day\" BETWEEN 1 AND 4" + }, + "equipment_price_ck": { + "name": "equipment_price_ck", + "value": "\"equipment\".\"purchase_price_ht\" IS NULL OR \"equipment\".\"purchase_price_ht\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.establishment_fee_rules": { + "name": "establishment_fee_rules", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rate_pct": { + "name": "rate_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "basis": { + "name": "basis", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ttc'" + }, + "match_channel": { + "name": "match_channel", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "match_payment": { + "name": "match_payment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fixed_monthly_ht": { + "name": "fixed_monthly_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "valid_from": { + "name": "valid_from", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "valid_to": { + "name": "valid_to", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "establishment_fee_rules_est_idx": { + "name": "establishment_fee_rules_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "establishment_fee_rules_organization_id_organizations_id_fk": { + "name": "establishment_fee_rules_organization_id_organizations_id_fk", + "tableFrom": "establishment_fee_rules", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "establishment_fee_rules_establishment_id_establishments_id_fk": { + "name": "establishment_fee_rules_establishment_id_establishments_id_fk", + "tableFrom": "establishment_fee_rules", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "establishment_fee_rules_created_by_users_id_fk": { + "name": "establishment_fee_rules_created_by_users_id_fk", + "tableFrom": "establishment_fee_rules", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "establishment_fee_rules_kind_ck": { + "name": "establishment_fee_rules_kind_ck", + "value": "\"establishment_fee_rules\".\"kind\" IN ('plateforme', 'franchise')" + }, + "establishment_fee_rules_basis_ck": { + "name": "establishment_fee_rules_basis_ck", + "value": "\"establishment_fee_rules\".\"basis\" IN ('ttc', 'ht')" + }, + "establishment_fee_rules_rate_ck": { + "name": "establishment_fee_rules_rate_ck", + "value": "\"establishment_fee_rules\".\"rate_pct\" >= 0 AND \"establishment_fee_rules\".\"rate_pct\" < 100" + }, + "establishment_fee_rules_fixed_ck": { + "name": "establishment_fee_rules_fixed_ck", + "value": "\"establishment_fee_rules\".\"fixed_monthly_ht\" IS NULL OR \"establishment_fee_rules\".\"fixed_monthly_ht\" >= 0" + }, + "establishment_fee_rules_channel_ck": { + "name": "establishment_fee_rules_channel_ck", + "value": "\"establishment_fee_rules\".\"match_channel\" IS NULL OR \"establishment_fee_rules\".\"match_channel\" IN ('sur_place', 'emporter', 'livraison', 'click_collect', 'autre')" + }, + "establishment_fee_rules_dates_ck": { + "name": "establishment_fee_rules_dates_ck", + "value": "\"establishment_fee_rules\".\"valid_to\" IS NULL OR \"establishment_fee_rules\".\"valid_to\" >= \"establishment_fee_rules\".\"valid_from\"" + }, + "establishment_fee_rules_label_ck": { + "name": "establishment_fee_rules_label_ck", + "value": "char_length(\"establishment_fee_rules\".\"label\") BETWEEN 1 AND 80" + } + }, + "isRLSEnabled": false + }, + "public.establishment_regulatory_profiles": { + "name": "establishment_regulatory_profiles", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "on_site": { + "name": "on_site", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "takeaway": { + "name": "takeaway", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "delivery": { + "name": "delivery", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "seating_capacity": { + "name": "seating_capacity", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "erp_category": { + "name": "erp_category", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "erp_type": { + "name": "erp_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "headcount_declared": { + "name": "headcount_declared", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "alcohol_licence": { + "name": "alcohol_licence", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "terrace": { + "name": "terrace", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "music": { + "name": "music", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "cameras": { + "name": "cameras", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "fryer": { + "name": "fryer", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "minors_employed": { + "name": "minors_employed", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "foreign_workers": { + "name": "foreign_workers", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "franchise": { + "name": "franchise", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "establishment_regulatory_profiles_org_idx": { + "name": "establishment_regulatory_profiles_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "establishment_regulatory_profiles_establishment_id_establishments_id_fk": { + "name": "establishment_regulatory_profiles_establishment_id_establishments_id_fk", + "tableFrom": "establishment_regulatory_profiles", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "establishment_regulatory_profiles_organization_id_organizations_id_fk": { + "name": "establishment_regulatory_profiles_organization_id_organizations_id_fk", + "tableFrom": "establishment_regulatory_profiles", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "establishment_regulatory_profiles_updated_by_users_id_fk": { + "name": "establishment_regulatory_profiles_updated_by_users_id_fk", + "tableFrom": "establishment_regulatory_profiles", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "establishment_regulatory_profiles_erp_ck": { + "name": "establishment_regulatory_profiles_erp_ck", + "value": "\"establishment_regulatory_profiles\".\"erp_category\" IS NULL OR \"establishment_regulatory_profiles\".\"erp_category\" IN ('1', '2', '3', '4', '5')" + }, + "establishment_regulatory_profiles_licence_ck": { + "name": "establishment_regulatory_profiles_licence_ck", + "value": "\"establishment_regulatory_profiles\".\"alcohol_licence\" IS NULL OR \"establishment_regulatory_profiles\".\"alcohol_licence\" IN ('aucune', 'petite_licence_restaurant', 'licence_restaurant', 'licence_3', 'licence_4', 'petite_licence_emporter', 'licence_emporter', 'inconnue')" + }, + "establishment_regulatory_profiles_counts_ck": { + "name": "establishment_regulatory_profiles_counts_ck", + "value": "(\"establishment_regulatory_profiles\".\"seating_capacity\" IS NULL OR \"establishment_regulatory_profiles\".\"seating_capacity\" >= 0) AND (\"establishment_regulatory_profiles\".\"headcount_declared\" IS NULL OR \"establishment_regulatory_profiles\".\"headcount_declared\" >= 0)" + } + }, + "isRLSEnabled": false + }, + "public.establishments": { + "name": "establishments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'restaurant'" + }, + "address_line": { + "name": "address_line", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "postal_code": { + "name": "postal_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "city": { + "name": "city", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "siret": { + "name": "siret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ape_code": { + "name": "ape_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "idcc": { + "name": "idcc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'FR'" + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'Europe/Paris'" + }, + "currency": { + "name": "currency", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'EUR'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "establishments_org_idx": { + "name": "establishments_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "establishments_organization_id_organizations_id_fk": { + "name": "establishments_organization_id_organizations_id_fk", + "tableFrom": "establishments", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "establishments_company_id_companies_id_fk": { + "name": "establishments_company_id_companies_id_fk", + "tableFrom": "establishments", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.expense_entries": { + "name": "expense_entries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "supplier": { + "name": "supplier", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "period_start": { + "name": "period_start", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "period_end": { + "name": "period_end", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "amount_ht": { + "name": "amount_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "vat_rate": { + "name": "vat_rate", + "type": "numeric(6, 4)", + "primaryKey": false, + "notNull": true + }, + "vat_amount": { + "name": "vat_amount", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "amount_ttc": { + "name": "amount_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "data_status": { + "name": "data_status", + "type": "data_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "recurrence": { + "name": "recurrence", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "recurrence_until": { + "name": "recurrence_until", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deleted_by": { + "name": "deleted_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "deletion_reason": { + "name": "deletion_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "double_count_decision": { + "name": "double_count_decision", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "double_count_decided_by": { + "name": "double_count_decided_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "double_count_decided_at": { + "name": "double_count_decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "expenses_period_idx": { + "name": "expenses_period_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "period_start", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "period_end", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "expense_entries_organization_id_organizations_id_fk": { + "name": "expense_entries_organization_id_organizations_id_fk", + "tableFrom": "expense_entries", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "expense_entries_establishment_id_establishments_id_fk": { + "name": "expense_entries_establishment_id_establishments_id_fk", + "tableFrom": "expense_entries", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "expense_entries_created_by_users_id_fk": { + "name": "expense_entries_created_by_users_id_fk", + "tableFrom": "expense_entries", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "expense_entries_deleted_by_users_id_fk": { + "name": "expense_entries_deleted_by_users_id_fk", + "tableFrom": "expense_entries", + "tableTo": "users", + "columnsFrom": [ + "deleted_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "expense_entries_double_count_decided_by_users_id_fk": { + "name": "expense_entries_double_count_decided_by_users_id_fk", + "tableFrom": "expense_entries", + "tableTo": "users", + "columnsFrom": [ + "double_count_decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "expenses_period_ck": { + "name": "expenses_period_ck", + "value": "\"expense_entries\".\"period_start\" <= \"expense_entries\".\"period_end\"" + }, + "expenses_recurrence_ck": { + "name": "expenses_recurrence_ck", + "value": "\"expense_entries\".\"recurrence\" IN ('none', 'monthly', 'quarterly', 'yearly')" + }, + "expenses_recurrence_until_ck": { + "name": "expenses_recurrence_until_ck", + "value": "\"expense_entries\".\"recurrence_until\" IS NULL OR (\"expense_entries\".\"recurrence\" <> 'none' AND \"expense_entries\".\"recurrence_until\" >= \"expense_entries\".\"period_start\")" + }, + "expenses_ttc_consistency_ck": { + "name": "expenses_ttc_consistency_ck", + "value": "\"expense_entries\".\"amount_ttc\" = \"expense_entries\".\"amount_ht\" + \"expense_entries\".\"vat_amount\"" + }, + "expense_double_count_ck": { + "name": "expense_double_count_ck", + "value": "\"expense_entries\".\"double_count_decision\" IS NULL OR \"expense_entries\".\"double_count_decision\" IN ('keep', 'exclude')" + } + }, + "isRLSEnabled": false + }, + "public.feedback_ambassadors": { + "name": "feedback_ambassadors", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "appointed_by": { + "name": "appointed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "feedback_ambassadors_organization_id_organizations_id_fk": { + "name": "feedback_ambassadors_organization_id_organizations_id_fk", + "tableFrom": "feedback_ambassadors", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "feedback_ambassadors_user_id_users_id_fk": { + "name": "feedback_ambassadors_user_id_users_id_fk", + "tableFrom": "feedback_ambassadors", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "feedback_ambassadors_appointed_by_users_id_fk": { + "name": "feedback_ambassadors_appointed_by_users_id_fk", + "tableFrom": "feedback_ambassadors", + "tableTo": "users", + "columnsFrom": [ + "appointed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "feedback_ambassadors_organization_id_user_id_pk": { + "name": "feedback_ambassadors_organization_id_user_id_pk", + "columns": [ + "organization_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.feedback_comments": { + "name": "feedback_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "feedback_id": { + "name": "feedback_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'commentaire'" + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "from_status": { + "name": "from_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "to_status": { + "name": "to_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "feedback_comments_item_idx": { + "name": "feedback_comments_item_idx", + "columns": [ + { + "expression": "feedback_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "feedback_comments_organization_id_organizations_id_fk": { + "name": "feedback_comments_organization_id_organizations_id_fk", + "tableFrom": "feedback_comments", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "feedback_comments_feedback_id_feedback_items_id_fk": { + "name": "feedback_comments_feedback_id_feedback_items_id_fk", + "tableFrom": "feedback_comments", + "tableTo": "feedback_items", + "columnsFrom": [ + "feedback_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "feedback_comments_user_id_users_id_fk": { + "name": "feedback_comments_user_id_users_id_fk", + "tableFrom": "feedback_comments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "feedback_comments_kind_ck": { + "name": "feedback_comments_kind_ck", + "value": "\"feedback_comments\".\"kind\" IN ('commentaire', 'reponse', 'statut', 'fusion')" + } + }, + "isRLSEnabled": false + }, + "public.feedback_items": { + "name": "feedback_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "module": { + "name": "module", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "page_path": { + "name": "page_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "app_version": { + "name": "app_version", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "author_role": { + "name": "author_role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "screenshot": { + "name": "screenshot", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "screenshot_mime": { + "name": "screenshot_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'recue'" + }, + "status_note": { + "name": "status_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "release_version": { + "name": "release_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "merged_into_id": { + "name": "merged_into_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "first_response_at": { + "name": "first_response_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "status_changed_at": { + "name": "status_changed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "delivered_at": { + "name": "delivered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "feedback_items_number_uq": { + "name": "feedback_items_number_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "feedback_items_org_idx": { + "name": "feedback_items_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "feedback_items_organization_id_organizations_id_fk": { + "name": "feedback_items_organization_id_organizations_id_fk", + "tableFrom": "feedback_items", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "feedback_items_merged_into_id_feedback_items_id_fk": { + "name": "feedback_items_merged_into_id_feedback_items_id_fk", + "tableFrom": "feedback_items", + "tableTo": "feedback_items", + "columnsFrom": [ + "merged_into_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "feedback_items_author_id_users_id_fk": { + "name": "feedback_items_author_id_users_id_fk", + "tableFrom": "feedback_items", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "feedback_items_kind_ck": { + "name": "feedback_items_kind_ck", + "value": "\"feedback_items\".\"kind\" IN ('idee', 'probleme', 'question')" + }, + "feedback_items_status_ck": { + "name": "feedback_items_status_ck", + "value": "\"feedback_items\".\"status\" IN ('recue', 'etude', 'prevue', 'en_cours', 'livree', 'pas_maintenant')" + } + }, + "isRLSEnabled": false + }, + "public.feedback_pulses": { + "name": "feedback_pulses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "module": { + "name": "module", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "answer": { + "name": "answer", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "app_version": { + "name": "app_version", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "feedback_pulses_once_uq": { + "name": "feedback_pulses_once_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "module", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "app_version", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "feedback_pulses_org_idx": { + "name": "feedback_pulses_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "module", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "feedback_pulses_organization_id_organizations_id_fk": { + "name": "feedback_pulses_organization_id_organizations_id_fk", + "tableFrom": "feedback_pulses", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "feedback_pulses_user_id_users_id_fk": { + "name": "feedback_pulses_user_id_users_id_fk", + "tableFrom": "feedback_pulses", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "feedback_pulses_answer_ck": { + "name": "feedback_pulses_answer_ck", + "value": "\"feedback_pulses\".\"answer\" IN ('oui', 'non')" + } + }, + "isRLSEnabled": false + }, + "public.feedback_testers": { + "name": "feedback_testers", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "feedback_testers_organization_id_organizations_id_fk": { + "name": "feedback_testers_organization_id_organizations_id_fk", + "tableFrom": "feedback_testers", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "feedback_testers_user_id_users_id_fk": { + "name": "feedback_testers_user_id_users_id_fk", + "tableFrom": "feedback_testers", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "feedback_testers_organization_id_user_id_pk": { + "name": "feedback_testers_organization_id_user_id_pk", + "columns": [ + "organization_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.feedback_votes": { + "name": "feedback_votes", + "schema": "", + "columns": { + "feedback_id": { + "name": "feedback_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "feedback_votes_feedback_id_feedback_items_id_fk": { + "name": "feedback_votes_feedback_id_feedback_items_id_fk", + "tableFrom": "feedback_votes", + "tableTo": "feedback_items", + "columnsFrom": [ + "feedback_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "feedback_votes_user_id_users_id_fk": { + "name": "feedback_votes_user_id_users_id_fk", + "tableFrom": "feedback_votes", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "feedback_votes_feedback_id_user_id_pk": { + "name": "feedback_votes_feedback_id_user_id_pk", + "columns": [ + "feedback_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.file_downloads": { + "name": "file_downloads", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sensitivity": { + "name": "sensitivity", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "disposition": { + "name": "disposition", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "file_downloads_entity_idx": { + "name": "file_downloads_entity_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "file_downloads_organization_id_organizations_id_fk": { + "name": "file_downloads_organization_id_organizations_id_fk", + "tableFrom": "file_downloads", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "file_downloads_user_id_users_id_fk": { + "name": "file_downloads_user_id_users_id_fk", + "tableFrom": "file_downloads", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "file_downloads_source_ck": { + "name": "file_downloads_source_ck", + "value": "\"file_downloads\".\"source\" IN ('business_document', 'business_document_version', 'employee_file', 'vault_zip', 'privacy_export', 'signature_request', 'sos_zip', 'generated_report', 'generated_hr_document', 'data_export')" + }, + "file_downloads_disposition_ck": { + "name": "file_downloads_disposition_ck", + "value": "\"file_downloads\".\"disposition\" IN ('inline', 'attachment', 'zip')" + } + }, + "isRLSEnabled": false + }, + "public.fixed_assets": { + "name": "fixed_assets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "financing": { + "name": "financing", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "acquired_on": { + "name": "acquired_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "amount_ht": { + "name": "amount_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "useful_life_months": { + "name": "useful_life_months", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "purchase_invoice_id": { + "name": "purchase_invoice_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "pennylane_record_id": { + "name": "pennylane_record_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "document_id": { + "name": "document_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_monthly_ht": { + "name": "lease_monthly_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "lease_end_on": { + "name": "lease_end_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "lease_residual_ht": { + "name": "lease_residual_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "disposed_on": { + "name": "disposed_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "disposal_reason": { + "name": "disposal_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "fixed_assets_est_idx": { + "name": "fixed_assets_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fixed_assets_invoice_uq": { + "name": "fixed_assets_invoice_uq", + "columns": [ + { + "expression": "purchase_invoice_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"fixed_assets\".\"purchase_invoice_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "fixed_assets_pennylane_uq": { + "name": "fixed_assets_pennylane_uq", + "columns": [ + { + "expression": "pennylane_record_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"fixed_assets\".\"pennylane_record_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "fixed_assets_organization_id_organizations_id_fk": { + "name": "fixed_assets_organization_id_organizations_id_fk", + "tableFrom": "fixed_assets", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "fixed_assets_establishment_id_establishments_id_fk": { + "name": "fixed_assets_establishment_id_establishments_id_fk", + "tableFrom": "fixed_assets", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "fixed_assets_supplier_id_suppliers_id_fk": { + "name": "fixed_assets_supplier_id_suppliers_id_fk", + "tableFrom": "fixed_assets", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "fixed_assets_purchase_invoice_id_purchase_invoices_id_fk": { + "name": "fixed_assets_purchase_invoice_id_purchase_invoices_id_fk", + "tableFrom": "fixed_assets", + "tableTo": "purchase_invoices", + "columnsFrom": [ + "purchase_invoice_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "fixed_assets_pennylane_record_id_pennylane_records_id_fk": { + "name": "fixed_assets_pennylane_record_id_pennylane_records_id_fk", + "tableFrom": "fixed_assets", + "tableTo": "pennylane_records", + "columnsFrom": [ + "pennylane_record_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "fixed_assets_document_id_business_documents_id_fk": { + "name": "fixed_assets_document_id_business_documents_id_fk", + "tableFrom": "fixed_assets", + "tableTo": "business_documents", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "fixed_assets_created_by_users_id_fk": { + "name": "fixed_assets_created_by_users_id_fk", + "tableFrom": "fixed_assets", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "fixed_assets_category_ck": { + "name": "fixed_assets_category_ck", + "value": "\"fixed_assets\".\"category\" IN ('materiel_cuisine', 'mobilier', 'informatique', 'agencement', 'vehicule', 'autre')" + }, + "fixed_assets_financing_ck": { + "name": "fixed_assets_financing_ck", + "value": "\"fixed_assets\".\"financing\" IN ('achat', 'credit_bail', 'location_financiere')" + }, + "fixed_assets_purchase_ck": { + "name": "fixed_assets_purchase_ck", + "value": "\"fixed_assets\".\"financing\" <> 'achat' OR (\"fixed_assets\".\"amount_ht\" IS NOT NULL AND \"fixed_assets\".\"amount_ht\" > 0 AND \"fixed_assets\".\"useful_life_months\" IS NOT NULL)" + }, + "fixed_assets_lease_ck": { + "name": "fixed_assets_lease_ck", + "value": "\"fixed_assets\".\"financing\" = 'achat' OR (\"fixed_assets\".\"lease_monthly_ht\" IS NOT NULL AND \"fixed_assets\".\"lease_monthly_ht\" > 0 AND \"fixed_assets\".\"lease_end_on\" IS NOT NULL AND \"fixed_assets\".\"lease_end_on\" > \"fixed_assets\".\"acquired_on\")" + }, + "fixed_assets_life_ck": { + "name": "fixed_assets_life_ck", + "value": "\"fixed_assets\".\"useful_life_months\" IS NULL OR \"fixed_assets\".\"useful_life_months\" BETWEEN 1 AND 600" + }, + "fixed_assets_amounts_ck": { + "name": "fixed_assets_amounts_ck", + "value": "(\"fixed_assets\".\"amount_ht\" IS NULL OR \"fixed_assets\".\"amount_ht\" >= 0) AND (\"fixed_assets\".\"lease_residual_ht\" IS NULL OR \"fixed_assets\".\"lease_residual_ht\" >= 0)" + }, + "fixed_assets_disposal_ck": { + "name": "fixed_assets_disposal_ck", + "value": "\"fixed_assets\".\"disposed_on\" IS NULL OR (\"fixed_assets\".\"disposed_on\" >= \"fixed_assets\".\"acquired_on\" AND \"fixed_assets\".\"disposal_reason\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.floor_items": { + "name": "floor_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "room_id": { + "name": "room_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "shape": { + "name": "shape", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "seats": { + "name": "seats", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "x": { + "name": "x", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "y": { + "name": "y", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "w": { + "name": "w", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "h": { + "name": "h", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "rotation": { + "name": "rotation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "floor_items_room_idx": { + "name": "floor_items_room_idx", + "columns": [ + { + "expression": "room_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "floor_items_table_label_uq": { + "name": "floor_items_table_label_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"label\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"floor_items\".\"kind\" = 'table' AND \"floor_items\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "floor_items_organization_id_organizations_id_fk": { + "name": "floor_items_organization_id_organizations_id_fk", + "tableFrom": "floor_items", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "floor_items_establishment_id_establishments_id_fk": { + "name": "floor_items_establishment_id_establishments_id_fk", + "tableFrom": "floor_items", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "floor_items_room_id_floor_rooms_id_fk": { + "name": "floor_items_room_id_floor_rooms_id_fk", + "tableFrom": "floor_items", + "tableTo": "floor_rooms", + "columnsFrom": [ + "room_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "floor_items_kind_ck": { + "name": "floor_items_kind_ck", + "value": "\"floor_items\".\"kind\" IN ('table', 'wall', 'bar', 'door', 'window', 'pillar', 'plant', 'zone', 'text')" + }, + "floor_items_table_ck": { + "name": "floor_items_table_ck", + "value": "\"floor_items\".\"kind\" <> 'table' OR (\"floor_items\".\"shape\" IN ('round', 'square', 'rect') AND \"floor_items\".\"label\" IS NOT NULL AND \"floor_items\".\"seats\" BETWEEN 1 AND 40)" + }, + "floor_items_size_ck": { + "name": "floor_items_size_ck", + "value": "\"floor_items\".\"w\" BETWEEN 5 AND 10000 AND \"floor_items\".\"h\" BETWEEN 5 AND 10000 AND \"floor_items\".\"rotation\" BETWEEN 0 AND 359" + } + }, + "isRLSEnabled": false + }, + "public.floor_rooms": { + "name": "floor_rooms", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "width_cm": { + "name": "width_cm", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1200 + }, + "height_cm": { + "name": "height_cm", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 800 + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "floor_rooms_est_idx": { + "name": "floor_rooms_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "floor_rooms_organization_id_organizations_id_fk": { + "name": "floor_rooms_organization_id_organizations_id_fk", + "tableFrom": "floor_rooms", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "floor_rooms_establishment_id_establishments_id_fk": { + "name": "floor_rooms_establishment_id_establishments_id_fk", + "tableFrom": "floor_rooms", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "floor_rooms_created_by_users_id_fk": { + "name": "floor_rooms_created_by_users_id_fk", + "tableFrom": "floor_rooms", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "floor_rooms_size_ck": { + "name": "floor_rooms_size_ck", + "value": "\"floor_rooms\".\"width_cm\" BETWEEN 200 AND 10000 AND \"floor_rooms\".\"height_cm\" BETWEEN 200 AND 10000" + } + }, + "isRLSEnabled": false + }, + "public.forecast_events": { + "name": "forecast_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "from_day": { + "name": "from_day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "to_day": { + "name": "to_day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "impact_pct": { + "name": "impact_pct", + "type": "numeric(6, 2)", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "forecast_events_org_idx": { + "name": "forecast_events_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "from_day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "forecast_events_organization_id_organizations_id_fk": { + "name": "forecast_events_organization_id_organizations_id_fk", + "tableFrom": "forecast_events", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "forecast_events_establishment_id_establishments_id_fk": { + "name": "forecast_events_establishment_id_establishments_id_fk", + "tableFrom": "forecast_events", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "forecast_events_created_by_users_id_fk": { + "name": "forecast_events_created_by_users_id_fk", + "tableFrom": "forecast_events", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "forecast_events_range_ck": { + "name": "forecast_events_range_ck", + "value": "\"forecast_events\".\"to_day\" >= \"forecast_events\".\"from_day\" AND \"forecast_events\".\"to_day\" - \"forecast_events\".\"from_day\" <= 92" + }, + "forecast_events_impact_ck": { + "name": "forecast_events_impact_ck", + "value": "\"forecast_events\".\"impact_pct\" IS NULL OR (\"forecast_events\".\"impact_pct\" >= -100 AND \"forecast_events\".\"impact_pct\" <= 500)" + } + }, + "isRLSEnabled": false + }, + "public.forum_replies": { + "name": "forum_replies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "topic_id": { + "name": "topic_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "hidden": { + "name": "hidden", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "forum_replies_topic_idx": { + "name": "forum_replies_topic_idx", + "columns": [ + { + "expression": "topic_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "forum_replies_organization_id_organizations_id_fk": { + "name": "forum_replies_organization_id_organizations_id_fk", + "tableFrom": "forum_replies", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "forum_replies_topic_id_forum_topics_id_fk": { + "name": "forum_replies_topic_id_forum_topics_id_fk", + "tableFrom": "forum_replies", + "tableTo": "forum_topics", + "columnsFrom": [ + "topic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "forum_replies_author_id_users_id_fk": { + "name": "forum_replies_author_id_users_id_fk", + "tableFrom": "forum_replies", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.forum_topics": { + "name": "forum_topics", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'question'" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "module": { + "name": "module", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "pinned": { + "name": "pinned", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "locked": { + "name": "locked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "hidden": { + "name": "hidden", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "solution_reply_id": { + "name": "solution_reply_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "idea_id": { + "name": "idea_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "last_activity_at": { + "name": "last_activity_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "forum_topics_number_uq": { + "name": "forum_topics_number_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "forum_topics_org_idx": { + "name": "forum_topics_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pinned", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_activity_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "forum_topics_organization_id_organizations_id_fk": { + "name": "forum_topics_organization_id_organizations_id_fk", + "tableFrom": "forum_topics", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "forum_topics_author_id_users_id_fk": { + "name": "forum_topics_author_id_users_id_fk", + "tableFrom": "forum_topics", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "forum_topics_idea_id_feedback_items_id_fk": { + "name": "forum_topics_idea_id_feedback_items_id_fk", + "tableFrom": "forum_topics", + "tableTo": "feedback_items", + "columnsFrom": [ + "idea_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "forum_topics_category_ck": { + "name": "forum_topics_category_ck", + "value": "\"forum_topics\".\"category\" IN ('question', 'astuce', 'discussion')" + } + }, + "isRLSEnabled": false + }, + "public.google_post_settings": { + "name": "google_post_settings", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "schedule_mode": { + "name": "schedule_mode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'per_week'" + }, + "weekdays": { + "name": "weekdays", + "type": "integer[]", + "primaryKey": false, + "notNull": true, + "default": "ARRAY[2,5]::integer[]" + }, + "per_week": { + "name": "per_week", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 2 + }, + "post_time": { + "name": "post_time", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'10:00'" + }, + "lead_hours": { + "name": "lead_hours", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 48 + }, + "src_menu": { + "name": "src_menu", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "src_events": { + "name": "src_events", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "src_hours": { + "name": "src_hours", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "src_best_sellers": { + "name": "src_best_sellers", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "src_seasonal": { + "name": "src_seasonal", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "src_reviews": { + "name": "src_reviews", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "review_min_rating": { + "name": "review_min_rating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 5 + }, + "default_cta_type": { + "name": "default_cta_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "default_cta_url": { + "name": "default_cta_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'fr'" + }, + "autopublish": { + "name": "autopublish", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "enabled_by": { + "name": "enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "enabled_at": { + "name": "enabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "confirmation": { + "name": "confirmation", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "paused_reason": { + "name": "paused_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_generated_at": { + "name": "last_generated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "google_post_settings_org_idx": { + "name": "google_post_settings_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "google_post_settings_establishment_id_establishments_id_fk": { + "name": "google_post_settings_establishment_id_establishments_id_fk", + "tableFrom": "google_post_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "google_post_settings_organization_id_organizations_id_fk": { + "name": "google_post_settings_organization_id_organizations_id_fk", + "tableFrom": "google_post_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "google_post_settings_enabled_by_users_id_fk": { + "name": "google_post_settings_enabled_by_users_id_fk", + "tableFrom": "google_post_settings", + "tableTo": "users", + "columnsFrom": [ + "enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "google_post_settings_updated_by_users_id_fk": { + "name": "google_post_settings_updated_by_users_id_fk", + "tableFrom": "google_post_settings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "google_post_settings_mode_ck": { + "name": "google_post_settings_mode_ck", + "value": "\"google_post_settings\".\"schedule_mode\" IN ('weekdays', 'per_week')" + }, + "google_post_settings_weekdays_ck": { + "name": "google_post_settings_weekdays_ck", + "value": "cardinality(\"google_post_settings\".\"weekdays\") BETWEEN 1 AND 7 AND \"google_post_settings\".\"weekdays\" <@ ARRAY[1,2,3,4,5,6,7]::integer[]" + }, + "google_post_settings_per_week_ck": { + "name": "google_post_settings_per_week_ck", + "value": "\"google_post_settings\".\"per_week\" BETWEEN 1 AND 7" + }, + "google_post_settings_time_ck": { + "name": "google_post_settings_time_ck", + "value": "\"google_post_settings\".\"post_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$'" + }, + "google_post_settings_lead_ck": { + "name": "google_post_settings_lead_ck", + "value": "\"google_post_settings\".\"lead_hours\" BETWEEN 12 AND 168" + }, + "google_post_settings_rating_ck": { + "name": "google_post_settings_rating_ck", + "value": "\"google_post_settings\".\"review_min_rating\" BETWEEN 4 AND 5" + }, + "google_post_settings_cta_ck": { + "name": "google_post_settings_cta_ck", + "value": "\"google_post_settings\".\"default_cta_type\" IS NULL OR \"google_post_settings\".\"default_cta_type\" IN ('BOOK', 'ORDER', 'SHOP', 'LEARN_MORE', 'SIGN_UP', 'CALL')" + }, + "google_post_settings_autopublish_ck": { + "name": "google_post_settings_autopublish_ck", + "value": "NOT \"google_post_settings\".\"autopublish\" OR \"google_post_settings\".\"confirmation\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.google_posts": { + "name": "google_posts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_key": { + "name": "source_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "generator": { + "name": "generator", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rationale": { + "name": "rationale", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "facts": { + "name": "facts", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "topic_type": { + "name": "topic_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'STANDARD'" + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cta_type": { + "name": "cta_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cta_url": { + "name": "cta_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "event_title": { + "name": "event_title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "event_start_date": { + "name": "event_start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "event_start_time": { + "name": "event_start_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "event_end_date": { + "name": "event_end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "event_end_time": { + "name": "event_end_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "offer_coupon": { + "name": "offer_coupon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "offer_url": { + "name": "offer_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "offer_terms": { + "name": "offer_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "visual_id": { + "name": "visual_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "image": { + "name": "image", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "image_mime": { + "name": "image_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "public_token": { + "name": "public_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scheduled_for": { + "name": "scheduled_for", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "blocked_words": { + "name": "blocked_words", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "approved_by": { + "name": "approved_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "google_name": { + "name": "google_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "google_state": { + "name": "google_state", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "search_url": { + "name": "search_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "ai_cost_usd": { + "name": "ai_cost_usd", + "type": "numeric(12, 6)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "google_posts_due_idx": { + "name": "google_posts_due_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_attempt_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "google_posts_cal_idx": { + "name": "google_posts_cal_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scheduled_for", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "google_posts_source_uq": { + "name": "google_posts_source_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"google_posts\".\"source_key\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "google_posts_token_uq": { + "name": "google_posts_token_uq", + "columns": [ + { + "expression": "public_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "google_posts_organization_id_organizations_id_fk": { + "name": "google_posts_organization_id_organizations_id_fk", + "tableFrom": "google_posts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "google_posts_establishment_id_establishments_id_fk": { + "name": "google_posts_establishment_id_establishments_id_fk", + "tableFrom": "google_posts", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "google_posts_visual_id_studio_visuals_id_fk": { + "name": "google_posts_visual_id_studio_visuals_id_fk", + "tableFrom": "google_posts", + "tableTo": "studio_visuals", + "columnsFrom": [ + "visual_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "google_posts_approved_by_users_id_fk": { + "name": "google_posts_approved_by_users_id_fk", + "tableFrom": "google_posts", + "tableTo": "users", + "columnsFrom": [ + "approved_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "google_posts_created_by_users_id_fk": { + "name": "google_posts_created_by_users_id_fk", + "tableFrom": "google_posts", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "google_posts_source_ck": { + "name": "google_posts_source_ck", + "value": "\"google_posts\".\"source\" IN ('manuel', 'menu_du_jour', 'evenement', 'horaires', 'meilleures_ventes', 'saison', 'avis')" + }, + "google_posts_generator_ck": { + "name": "google_posts_generator_ck", + "value": "\"google_posts\".\"generator\" IN ('ia', 'modele', 'humain')" + }, + "google_posts_topic_ck": { + "name": "google_posts_topic_ck", + "value": "\"google_posts\".\"topic_type\" IN ('STANDARD', 'EVENT', 'OFFER')" + }, + "google_posts_status_ck": { + "name": "google_posts_status_ck", + "value": "\"google_posts\".\"status\" IN ('brouillon', 'planifie', 'publishing', 'publie', 'echec', 'bloque', 'annule', 'expire', 'retire')" + }, + "google_posts_summary_ck": { + "name": "google_posts_summary_ck", + "value": "char_length(\"google_posts\".\"summary\") BETWEEN 1 AND 1500" + }, + "google_posts_cta_ck": { + "name": "google_posts_cta_ck", + "value": "\"google_posts\".\"cta_type\" IS NULL OR \"google_posts\".\"cta_type\" IN ('BOOK', 'ORDER', 'SHOP', 'LEARN_MORE', 'SIGN_UP', 'CALL')" + }, + "google_posts_image_ck": { + "name": "google_posts_image_ck", + "value": "(\"google_posts\".\"image\" IS NULL) = (\"google_posts\".\"image_mime\" IS NULL)" + } + }, + "isRLSEnabled": false + }, + "public.haccp_corrective_actions": { + "name": "haccp_corrective_actions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "dedup_key": { + "name": "dedup_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "detected_at": { + "name": "detected_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "action_taken": { + "name": "action_taken", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "closed_by": { + "name": "closed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "haccp_corrective_actions_dedup_uq": { + "name": "haccp_corrective_actions_dedup_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dedup_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "haccp_corrective_actions_open_idx": { + "name": "haccp_corrective_actions_open_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "detected_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"haccp_corrective_actions\".\"closed_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "haccp_corrective_actions_organization_id_organizations_id_fk": { + "name": "haccp_corrective_actions_organization_id_organizations_id_fk", + "tableFrom": "haccp_corrective_actions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "haccp_corrective_actions_establishment_id_establishments_id_fk": { + "name": "haccp_corrective_actions_establishment_id_establishments_id_fk", + "tableFrom": "haccp_corrective_actions", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "haccp_corrective_actions_closed_by_users_id_fk": { + "name": "haccp_corrective_actions_closed_by_users_id_fk", + "tableFrom": "haccp_corrective_actions", + "tableTo": "users", + "columnsFrom": [ + "closed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "haccp_corrective_actions_created_by_users_id_fk": { + "name": "haccp_corrective_actions_created_by_users_id_fk", + "tableFrom": "haccp_corrective_actions", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "haccp_corrective_actions_source_ck": { + "name": "haccp_corrective_actions_source_ck", + "value": "\"haccp_corrective_actions\".\"source\" IN ('sonde_hors_plage', 'sonde_muette', 'releves_manquants', 'nettoyage_manquant', 'date_limite', 'manuel', 'rappel_produit', 'nuisibles')" + }, + "haccp_corrective_actions_close_ck": { + "name": "haccp_corrective_actions_close_ck", + "value": "(\"haccp_corrective_actions\".\"closed_at\" IS NULL) = (\"haccp_corrective_actions\".\"action_taken\" IS NULL) AND (\"haccp_corrective_actions\".\"closed_at\" IS NULL) = (\"haccp_corrective_actions\".\"closed_by\" IS NULL)" + } + }, + "isRLSEnabled": false + }, + "public.haccp_sealed_exports": { + "name": "haccp_sealed_exports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'dossier'" + }, + "period_from": { + "name": "period_from", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "period_to": { + "name": "period_to", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "verify_token": { + "name": "verify_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bytes": { + "name": "bytes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "haccp_sealed_exports_token_uq": { + "name": "haccp_sealed_exports_token_uq", + "columns": [ + { + "expression": "verify_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "haccp_sealed_exports_est_idx": { + "name": "haccp_sealed_exports_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "haccp_sealed_exports_organization_id_organizations_id_fk": { + "name": "haccp_sealed_exports_organization_id_organizations_id_fk", + "tableFrom": "haccp_sealed_exports", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "haccp_sealed_exports_establishment_id_establishments_id_fk": { + "name": "haccp_sealed_exports_establishment_id_establishments_id_fk", + "tableFrom": "haccp_sealed_exports", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "haccp_sealed_exports_created_by_users_id_fk": { + "name": "haccp_sealed_exports_created_by_users_id_fk", + "tableFrom": "haccp_sealed_exports", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "haccp_sealed_exports_kind_ck": { + "name": "haccp_sealed_exports_kind_ck", + "value": "\"haccp_sealed_exports\".\"kind\" IN ('dossier')" + } + }, + "isRLSEnabled": false + }, + "public.incidents": { + "name": "incidents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actions_taken": { + "name": "actions_taken", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ouvert'" + }, + "reported_by": { + "name": "reported_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "reported_at": { + "name": "reported_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "closed_by": { + "name": "closed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "follow_up": { + "name": "follow_up", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "incidents_est_idx": { + "name": "incidents_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurred_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "incidents_organization_id_organizations_id_fk": { + "name": "incidents_organization_id_organizations_id_fk", + "tableFrom": "incidents", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "incidents_establishment_id_establishments_id_fk": { + "name": "incidents_establishment_id_establishments_id_fk", + "tableFrom": "incidents", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "incidents_reported_by_users_id_fk": { + "name": "incidents_reported_by_users_id_fk", + "tableFrom": "incidents", + "tableTo": "users", + "columnsFrom": [ + "reported_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "incidents_closed_by_users_id_fk": { + "name": "incidents_closed_by_users_id_fk", + "tableFrom": "incidents", + "tableTo": "users", + "columnsFrom": [ + "closed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "incidents_kind_ck": { + "name": "incidents_kind_ck", + "value": "\"incidents\".\"kind\" IN ('client', 'accident', 'casse', 'vol', 'securite', 'hygiene', 'livraison', 'autre')" + }, + "incidents_severity_ck": { + "name": "incidents_severity_ck", + "value": "\"incidents\".\"severity\" IN ('mineur', 'important', 'grave')" + }, + "incidents_status_ck": { + "name": "incidents_status_ck", + "value": "\"incidents\".\"status\" IN ('ouvert', 'clos')" + }, + "incidents_closed_ck": { + "name": "incidents_closed_ck", + "value": "\"incidents\".\"status\" = 'ouvert' OR (\"incidents\".\"closed_at\" IS NOT NULL AND \"incidents\".\"follow_up\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.inspection_shares": { + "name": "inspection_shares", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "inspector_code": { + "name": "inspector_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by_name": { + "name": "created_by_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "access_count": { + "name": "access_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_access_at": { + "name": "last_access_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "inspection_shares_token_uq": { + "name": "inspection_shares_token_uq", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "inspection_shares_est_idx": { + "name": "inspection_shares_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "inspection_shares_organization_id_organizations_id_fk": { + "name": "inspection_shares_organization_id_organizations_id_fk", + "tableFrom": "inspection_shares", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "inspection_shares_establishment_id_establishments_id_fk": { + "name": "inspection_shares_establishment_id_establishments_id_fk", + "tableFrom": "inspection_shares", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "inspection_shares_created_by_users_id_fk": { + "name": "inspection_shares_created_by_users_id_fk", + "tableFrom": "inspection_shares", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.integration_connections": { + "name": "integration_connections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "connection_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'not_configured'" + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "public_config": { + "name": "public_config", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "secret_enc": { + "name": "secret_enc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "auto_sync": { + "name": "auto_sync", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "sync_interval_hours": { + "name": "sync_interval_hours", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 24 + }, + "next_sync_at": { + "name": "next_sync_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "integration_conn_uq": { + "name": "integration_conn_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "integration_connections_organization_id_organizations_id_fk": { + "name": "integration_connections_organization_id_organizations_id_fk", + "tableFrom": "integration_connections", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "integration_connections_establishment_id_establishments_id_fk": { + "name": "integration_connections_establishment_id_establishments_id_fk", + "tableFrom": "integration_connections", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "integration_conn_interval_ck": { + "name": "integration_conn_interval_ck", + "value": "\"integration_connections\".\"sync_interval_hours\" BETWEEN 1 AND 168" + }, + "integration_conn_failures_ck": { + "name": "integration_conn_failures_ck", + "value": "\"integration_connections\".\"consecutive_failures\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.integration_sync_runs": { + "name": "integration_sync_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "counts": { + "name": "counts", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "errors": { + "name": "errors", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "integration_sync_runs_idx": { + "name": "integration_sync_runs_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "integration_sync_runs_organization_id_organizations_id_fk": { + "name": "integration_sync_runs_organization_id_organizations_id_fk", + "tableFrom": "integration_sync_runs", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "integration_sync_runs_establishment_id_establishments_id_fk": { + "name": "integration_sync_runs_establishment_id_establishments_id_fk", + "tableFrom": "integration_sync_runs", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "integration_sync_runs_user_id_users_id_fk": { + "name": "integration_sync_runs_user_id_users_id_fk", + "tableFrom": "integration_sync_runs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "integration_sync_runs_trigger_ck": { + "name": "integration_sync_runs_trigger_ck", + "value": "\"integration_sync_runs\".\"trigger\" IN ('manual', 'auto')" + }, + "integration_sync_runs_outcome_ck": { + "name": "integration_sync_runs_outcome_ck", + "value": "\"integration_sync_runs\".\"outcome\" IN ('success', 'partial', 'error')" + } + }, + "isRLSEnabled": false + }, + "public.intercompany_flows": { + "name": "intercompany_flows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "payer_company_id": { + "name": "payer_company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "payee_company_id": { + "name": "payee_company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "flow_date": { + "name": "flow_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "amount_ht": { + "name": "amount_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "vat_amount": { + "name": "vat_amount", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "agreement_ref": { + "name": "agreement_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'saisie'" + }, + "purchase_invoice_id": { + "name": "purchase_invoice_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "bank_transaction_id": { + "name": "bank_transaction_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancellation_reason": { + "name": "cancellation_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "intercompany_flows_org_idx": { + "name": "intercompany_flows_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "flow_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "intercompany_flows_invoice_uq": { + "name": "intercompany_flows_invoice_uq", + "columns": [ + { + "expression": "purchase_invoice_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"intercompany_flows\".\"purchase_invoice_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "intercompany_flows_bank_uq": { + "name": "intercompany_flows_bank_uq", + "columns": [ + { + "expression": "bank_transaction_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"intercompany_flows\".\"bank_transaction_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "intercompany_flows_organization_id_organizations_id_fk": { + "name": "intercompany_flows_organization_id_organizations_id_fk", + "tableFrom": "intercompany_flows", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "intercompany_flows_payer_company_id_companies_id_fk": { + "name": "intercompany_flows_payer_company_id_companies_id_fk", + "tableFrom": "intercompany_flows", + "tableTo": "companies", + "columnsFrom": [ + "payer_company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "intercompany_flows_payee_company_id_companies_id_fk": { + "name": "intercompany_flows_payee_company_id_companies_id_fk", + "tableFrom": "intercompany_flows", + "tableTo": "companies", + "columnsFrom": [ + "payee_company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "intercompany_flows_purchase_invoice_id_purchase_invoices_id_fk": { + "name": "intercompany_flows_purchase_invoice_id_purchase_invoices_id_fk", + "tableFrom": "intercompany_flows", + "tableTo": "purchase_invoices", + "columnsFrom": [ + "purchase_invoice_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "intercompany_flows_bank_transaction_id_bank_transactions_id_fk": { + "name": "intercompany_flows_bank_transaction_id_bank_transactions_id_fk", + "tableFrom": "intercompany_flows", + "tableTo": "bank_transactions", + "columnsFrom": [ + "bank_transaction_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "intercompany_flows_created_by_users_id_fk": { + "name": "intercompany_flows_created_by_users_id_fk", + "tableFrom": "intercompany_flows", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "intercompany_flows_cancelled_by_users_id_fk": { + "name": "intercompany_flows_cancelled_by_users_id_fk", + "tableFrom": "intercompany_flows", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "intercompany_flows_pair_ck": { + "name": "intercompany_flows_pair_ck", + "value": "\"intercompany_flows\".\"payer_company_id\" <> \"intercompany_flows\".\"payee_company_id\"" + }, + "intercompany_flows_amount_ck": { + "name": "intercompany_flows_amount_ck", + "value": "\"intercompany_flows\".\"amount_ht\" > 0 AND (\"intercompany_flows\".\"vat_amount\" IS NULL OR \"intercompany_flows\".\"vat_amount\" >= 0)" + }, + "intercompany_flows_source_ck": { + "name": "intercompany_flows_source_ck", + "value": "\"intercompany_flows\".\"source\" IN ('saisie', 'facture', 'banque')" + }, + "intercompany_flows_kind_ck": { + "name": "intercompany_flows_kind_ck", + "value": "\"intercompany_flows\".\"kind\" IN ('refacturation', 'management_fees', 'loyer', 'vente', 'interets', 'dividendes', 'pret', 'remboursement_pret', 'apport_compte_courant', 'remboursement_compte_courant', 'autre')" + } + }, + "isRLSEnabled": false + }, + "public.inventories": { + "name": "inventories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "count_date": { + "name": "count_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "total_value": { + "name": "total_value", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "validated_by": { + "name": "validated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "validated_at": { + "name": "validated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "inventories_est_idx": { + "name": "inventories_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "count_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "inventories_validated_day_uq": { + "name": "inventories_validated_day_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "count_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"inventories\".\"status\" = 'validated'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "inventories_organization_id_organizations_id_fk": { + "name": "inventories_organization_id_organizations_id_fk", + "tableFrom": "inventories", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "inventories_establishment_id_establishments_id_fk": { + "name": "inventories_establishment_id_establishments_id_fk", + "tableFrom": "inventories", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "inventories_created_by_users_id_fk": { + "name": "inventories_created_by_users_id_fk", + "tableFrom": "inventories", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "inventories_validated_by_users_id_fk": { + "name": "inventories_validated_by_users_id_fk", + "tableFrom": "inventories", + "tableTo": "users", + "columnsFrom": [ + "validated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "inventories_status_ck": { + "name": "inventories_status_ck", + "value": "\"inventories\".\"status\" IN ('draft', 'validated')" + } + }, + "isRLSEnabled": false + }, + "public.inventory_lines": { + "name": "inventory_lines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "inventory_id": { + "name": "inventory_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "unit_cost": { + "name": "unit_cost", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": false + }, + "value": { + "name": "value", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "inventory_lines_item_uq": { + "name": "inventory_lines_item_uq", + "columns": [ + { + "expression": "inventory_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "inventory_lines_organization_id_organizations_id_fk": { + "name": "inventory_lines_organization_id_organizations_id_fk", + "tableFrom": "inventory_lines", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "inventory_lines_inventory_id_inventories_id_fk": { + "name": "inventory_lines_inventory_id_inventories_id_fk", + "tableFrom": "inventory_lines", + "tableTo": "inventories", + "columnsFrom": [ + "inventory_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "inventory_lines_item_id_purchase_items_id_fk": { + "name": "inventory_lines_item_id_purchase_items_id_fk", + "tableFrom": "inventory_lines", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "inventory_lines_qty_ck": { + "name": "inventory_lines_qty_ck", + "value": "\"inventory_lines\".\"quantity\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.investment_scenarios": { + "name": "investment_scenarios", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'etude'" + }, + "price": { + "name": "price", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "fees": { + "name": "fees", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "works": { + "name": "works", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "working_capital": { + "name": "working_capital", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "equity": { + "name": "equity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "loan_rate_pct": { + "name": "loan_rate_pct", + "type": "numeric(6, 3)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "loan_years": { + "name": "loan_years", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 7 + }, + "revenue_ht": { + "name": "revenue_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "ebe": { + "name": "ebe", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "adjustments": { + "name": "adjustments", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "owner_pay": { + "name": "owner_pay", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "maintenance_capex": { + "name": "maintenance_capex", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "investment_scenarios_org_idx": { + "name": "investment_scenarios_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "investment_scenarios_organization_id_organizations_id_fk": { + "name": "investment_scenarios_organization_id_organizations_id_fk", + "tableFrom": "investment_scenarios", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "investment_scenarios_establishment_id_establishments_id_fk": { + "name": "investment_scenarios_establishment_id_establishments_id_fk", + "tableFrom": "investment_scenarios", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "investment_scenarios_created_by_users_id_fk": { + "name": "investment_scenarios_created_by_users_id_fk", + "tableFrom": "investment_scenarios", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "investment_scenarios_updated_by_users_id_fk": { + "name": "investment_scenarios_updated_by_users_id_fk", + "tableFrom": "investment_scenarios", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "investment_scenarios_kind_ck": { + "name": "investment_scenarios_kind_ck", + "value": "\"investment_scenarios\".\"kind\" IN ('rachat_fonds', 'rachat_parts', 'travaux', 'equipement', 'ouverture', 'autre')" + }, + "investment_scenarios_status_ck": { + "name": "investment_scenarios_status_ck", + "value": "\"investment_scenarios\".\"status\" IN ('etude', 'retenu', 'abandonne', 'realise')" + }, + "investment_scenarios_years_ck": { + "name": "investment_scenarios_years_ck", + "value": "\"investment_scenarios\".\"loan_years\" BETWEEN 1 AND 30" + }, + "investment_scenarios_rate_ck": { + "name": "investment_scenarios_rate_ck", + "value": "\"investment_scenarios\".\"loan_rate_pct\" >= 0 AND \"investment_scenarios\".\"loan_rate_pct\" <= 20" + }, + "investment_scenarios_amounts_ck": { + "name": "investment_scenarios_amounts_ck", + "value": "\"investment_scenarios\".\"price\" >= 0 AND \"investment_scenarios\".\"fees\" >= 0 AND \"investment_scenarios\".\"works\" >= 0 AND \"investment_scenarios\".\"working_capital\" >= 0 AND \"investment_scenarios\".\"equity\" >= 0 AND \"investment_scenarios\".\"owner_pay\" >= 0 AND \"investment_scenarios\".\"maintenance_capex\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.invoice_label_links": { + "name": "invoice_label_links", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "link_key": { + "name": "link_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "supplier_name": { + "name": "supplier_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "invoice_label_links_key_uq": { + "name": "invoice_label_links_key_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "link_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "invoice_label_links_organization_id_organizations_id_fk": { + "name": "invoice_label_links_organization_id_organizations_id_fk", + "tableFrom": "invoice_label_links", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "invoice_label_links_item_id_purchase_items_id_fk": { + "name": "invoice_label_links_item_id_purchase_items_id_fk", + "tableFrom": "invoice_label_links", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "invoice_label_links_created_by_users_id_fk": { + "name": "invoice_label_links_created_by_users_id_fk", + "tableFrom": "invoice_label_links", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_stock_settings": { + "name": "item_stock_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "min_stock": { + "name": "min_stock", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "target_stock": { + "name": "target_stock", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "overstock_days": { + "name": "overstock_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "item_stock_settings_uq": { + "name": "item_stock_settings_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "item_stock_settings_organization_id_organizations_id_fk": { + "name": "item_stock_settings_organization_id_organizations_id_fk", + "tableFrom": "item_stock_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "item_stock_settings_establishment_id_establishments_id_fk": { + "name": "item_stock_settings_establishment_id_establishments_id_fk", + "tableFrom": "item_stock_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "item_stock_settings_item_id_purchase_items_id_fk": { + "name": "item_stock_settings_item_id_purchase_items_id_fk", + "tableFrom": "item_stock_settings", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "item_stock_settings_ck": { + "name": "item_stock_settings_ck", + "value": "(\"item_stock_settings\".\"min_stock\" IS NULL OR \"item_stock_settings\".\"min_stock\" >= 0) AND (\"item_stock_settings\".\"target_stock\" IS NULL OR \"item_stock_settings\".\"target_stock\" >= 0) AND (\"item_stock_settings\".\"overstock_days\" IS NULL OR \"item_stock_settings\".\"overstock_days\" BETWEEN 1 AND 365)" + } + }, + "isRLSEnabled": false + }, + "public.job_openings": { + "name": "job_openings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "team": { + "name": "team", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contract_kind": { + "name": "contract_kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'cdi'" + }, + "weekly_hours": { + "name": "weekly_hours", + "type": "numeric(6, 2)", + "primaryKey": false, + "notNull": false + }, + "start_wanted": { + "name": "start_wanted", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ouvert'" + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "job_openings_org_idx": { + "name": "job_openings_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "job_openings_organization_id_organizations_id_fk": { + "name": "job_openings_organization_id_organizations_id_fk", + "tableFrom": "job_openings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "job_openings_establishment_id_establishments_id_fk": { + "name": "job_openings_establishment_id_establishments_id_fk", + "tableFrom": "job_openings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "job_openings_created_by_users_id_fk": { + "name": "job_openings_created_by_users_id_fk", + "tableFrom": "job_openings", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "job_openings_status_ck": { + "name": "job_openings_status_ck", + "value": "\"job_openings\".\"status\" IN ('ouvert', 'pourvu', 'ferme')" + }, + "job_openings_hours_ck": { + "name": "job_openings_hours_ck", + "value": "\"job_openings\".\"weekly_hours\" IS NULL OR (\"job_openings\".\"weekly_hours\" > 0 AND \"job_openings\".\"weekly_hours\" <= 48)" + } + }, + "isRLSEnabled": false + }, + "public.known_devices": { + "name": "known_devices", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_ip": { + "name": "last_ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "alerted_at": { + "name": "alerted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "known_devices_uq": { + "name": "known_devices_uq", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "known_devices_user_idx": { + "name": "known_devices_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_seen_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "known_devices_user_id_users_id_fk": { + "name": "known_devices_user_id_users_id_fk", + "tableFrom": "known_devices", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lead_activities": { + "name": "lead_activities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "lead_id": { + "name": "lead_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "lead_activities_lead_idx": { + "name": "lead_activities_lead_idx", + "columns": [ + { + "expression": "lead_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "lead_activities_organization_id_organizations_id_fk": { + "name": "lead_activities_organization_id_organizations_id_fk", + "tableFrom": "lead_activities", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "lead_activities_lead_id_leads_id_fk": { + "name": "lead_activities_lead_id_leads_id_fk", + "tableFrom": "lead_activities", + "tableTo": "leads", + "columnsFrom": [ + "lead_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "lead_activities_created_by_users_id_fk": { + "name": "lead_activities_created_by_users_id_fk", + "tableFrom": "lead_activities", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.leads": { + "name": "leads", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_kind": { + "name": "event_kind", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "event_date": { + "name": "event_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "guests": { + "name": "guests", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "budget_ttc": { + "name": "budget_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "contact_name": { + "name": "contact_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "company": { + "name": "company", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "customer_id": { + "name": "customer_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stage": { + "name": "stage", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'nouveau'" + }, + "lost_reason": { + "name": "lost_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_action_on": { + "name": "next_action_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "next_action": { + "name": "next_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "owner_user_id": { + "name": "owner_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "set_menu_id": { + "name": "set_menu_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "leads_org_stage_idx": { + "name": "leads_org_stage_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_action_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "leads_est_idx": { + "name": "leads_est_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "leads_organization_id_organizations_id_fk": { + "name": "leads_organization_id_organizations_id_fk", + "tableFrom": "leads", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "leads_establishment_id_establishments_id_fk": { + "name": "leads_establishment_id_establishments_id_fk", + "tableFrom": "leads", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "leads_customer_id_customers_id_fk": { + "name": "leads_customer_id_customers_id_fk", + "tableFrom": "leads", + "tableTo": "customers", + "columnsFrom": [ + "customer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "leads_owner_user_id_users_id_fk": { + "name": "leads_owner_user_id_users_id_fk", + "tableFrom": "leads", + "tableTo": "users", + "columnsFrom": [ + "owner_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "leads_set_menu_id_set_menus_id_fk": { + "name": "leads_set_menu_id_set_menus_id_fk", + "tableFrom": "leads", + "tableTo": "set_menus", + "columnsFrom": [ + "set_menu_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "leads_created_by_users_id_fk": { + "name": "leads_created_by_users_id_fk", + "tableFrom": "leads", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "leads_stage_ck": { + "name": "leads_stage_ck", + "value": "\"leads\".\"stage\" IN ('nouveau', 'contacte', 'devis', 'negociation', 'gagne', 'perdu')" + }, + "leads_guests_ck": { + "name": "leads_guests_ck", + "value": "\"leads\".\"guests\" IS NULL OR (\"leads\".\"guests\" > 0 AND \"leads\".\"guests\" <= 5000)" + }, + "leads_budget_ck": { + "name": "leads_budget_ck", + "value": "\"leads\".\"budget_ttc\" IS NULL OR \"leads\".\"budget_ttc\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.leave_adjustments": { + "name": "leave_adjustments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "effective_date": { + "name": "effective_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(8, 2)", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "leave_adjustments_emp_idx": { + "name": "leave_adjustments_emp_idx", + "columns": [ + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "leave_adjustments_organization_id_organizations_id_fk": { + "name": "leave_adjustments_organization_id_organizations_id_fk", + "tableFrom": "leave_adjustments", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "leave_adjustments_employee_id_employees_id_fk": { + "name": "leave_adjustments_employee_id_employees_id_fk", + "tableFrom": "leave_adjustments", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "leave_adjustments_created_by_users_id_fk": { + "name": "leave_adjustments_created_by_users_id_fk", + "tableFrom": "leave_adjustments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "leave_adjustments_counter_ck": { + "name": "leave_adjustments_counter_ck", + "value": "\"leave_adjustments\".\"counter\" IN ('cp_n1', 'cp_n', 'rc')" + }, + "leave_adjustments_amount_ck": { + "name": "leave_adjustments_amount_ck", + "value": "\"leave_adjustments\".\"amount\" <> 0 AND abs(\"leave_adjustments\".\"amount\") <= 500" + } + }, + "isRLSEnabled": false + }, + "public.leave_settings": { + "name": "leave_settings", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cp_unit": { + "name": "cp_unit", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ouvrables'" + }, + "overtime_as_rest": { + "name": "overtime_as_rest", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "leave_settings_establishment_id_establishments_id_fk": { + "name": "leave_settings_establishment_id_establishments_id_fk", + "tableFrom": "leave_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "leave_settings_organization_id_organizations_id_fk": { + "name": "leave_settings_organization_id_organizations_id_fk", + "tableFrom": "leave_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "leave_settings_updated_by_users_id_fk": { + "name": "leave_settings_updated_by_users_id_fk", + "tableFrom": "leave_settings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "leave_settings_unit_ck": { + "name": "leave_settings_unit_ck", + "value": "\"leave_settings\".\"cp_unit\" IN ('ouvrables', 'ouvres')" + } + }, + "isRLSEnabled": false + }, + "public.logbook_entries": { + "name": "logbook_entries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'info'" + }, + "team": { + "name": "team", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "important": { + "name": "important", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "done_at": { + "name": "done_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "done_by": { + "name": "done_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "done_note": { + "name": "done_note", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "logbook_entries_est_idx": { + "name": "logbook_entries_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "logbook_entries_organization_id_organizations_id_fk": { + "name": "logbook_entries_organization_id_organizations_id_fk", + "tableFrom": "logbook_entries", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "logbook_entries_establishment_id_establishments_id_fk": { + "name": "logbook_entries_establishment_id_establishments_id_fk", + "tableFrom": "logbook_entries", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "logbook_entries_author_id_users_id_fk": { + "name": "logbook_entries_author_id_users_id_fk", + "tableFrom": "logbook_entries", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "logbook_entries_done_by_users_id_fk": { + "name": "logbook_entries_done_by_users_id_fk", + "tableFrom": "logbook_entries", + "tableTo": "users", + "columnsFrom": [ + "done_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "logbook_entries_category_ck": { + "name": "logbook_entries_category_ck", + "value": "\"logbook_entries\".\"category\" IN ('info', 'a_traiter', 'client', 'livraison', 'equipe')" + } + }, + "isRLSEnabled": false + }, + "public.logbook_reads": { + "name": "logbook_reads", + "schema": "", + "columns": { + "entry_id": { + "name": "entry_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "logbook_reads_entry_id_logbook_entries_id_fk": { + "name": "logbook_reads_entry_id_logbook_entries_id_fk", + "tableFrom": "logbook_reads", + "tableTo": "logbook_entries", + "columnsFrom": [ + "entry_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "logbook_reads_user_id_users_id_fk": { + "name": "logbook_reads_user_id_users_id_fk", + "tableFrom": "logbook_reads", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "logbook_reads_entry_id_user_id_pk": { + "name": "logbook_reads_entry_id_user_id_pk", + "columns": [ + "entry_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.loyalty_events": { + "name": "loyalty_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "customer_id": { + "name": "customer_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "visits": { + "name": "visits", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "loyalty_events_customer_idx": { + "name": "loyalty_events_customer_idx", + "columns": [ + { + "expression": "customer_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "loyalty_events_est_idx": { + "name": "loyalty_events_est_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "loyalty_events_organization_id_organizations_id_fk": { + "name": "loyalty_events_organization_id_organizations_id_fk", + "tableFrom": "loyalty_events", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "loyalty_events_establishment_id_establishments_id_fk": { + "name": "loyalty_events_establishment_id_establishments_id_fk", + "tableFrom": "loyalty_events", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "loyalty_events_customer_id_customers_id_fk": { + "name": "loyalty_events_customer_id_customers_id_fk", + "tableFrom": "loyalty_events", + "tableTo": "customers", + "columnsFrom": [ + "customer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "loyalty_events_created_by_users_id_fk": { + "name": "loyalty_events_created_by_users_id_fk", + "tableFrom": "loyalty_events", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "loyalty_events_kind_ck": { + "name": "loyalty_events_kind_ck", + "value": "\"loyalty_events\".\"kind\" IN ('ajustement', 'recompense')" + }, + "loyalty_events_visits_ck": { + "name": "loyalty_events_visits_ck", + "value": "\"loyalty_events\".\"visits\" <> 0 AND (\"loyalty_events\".\"kind\" <> 'recompense' OR \"loyalty_events\".\"visits\" < 0)" + } + }, + "isRLSEnabled": false + }, + "public.loyalty_programs": { + "name": "loyalty_programs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "visits_per_reward": { + "name": "visits_per_reward", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "reward_label": { + "name": "reward_label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "starts_on": { + "name": "starts_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "loyalty_programs_est_uq": { + "name": "loyalty_programs_est_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "loyalty_programs_org_idx": { + "name": "loyalty_programs_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "loyalty_programs_organization_id_organizations_id_fk": { + "name": "loyalty_programs_organization_id_organizations_id_fk", + "tableFrom": "loyalty_programs", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "loyalty_programs_establishment_id_establishments_id_fk": { + "name": "loyalty_programs_establishment_id_establishments_id_fk", + "tableFrom": "loyalty_programs", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "loyalty_programs_updated_by_users_id_fk": { + "name": "loyalty_programs_updated_by_users_id_fk", + "tableFrom": "loyalty_programs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "loyalty_programs_visits_ck": { + "name": "loyalty_programs_visits_ck", + "value": "\"loyalty_programs\".\"visits_per_reward\" BETWEEN 2 AND 50" + } + }, + "isRLSEnabled": false + }, + "public.mail_accounts": { + "name": "mail_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'gmail'" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'connected'" + }, + "secret_enc": { + "name": "secret_enc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "cursor_ms": { + "name": "cursor_ms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "next_sync_at": { + "name": "next_sync_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "connected_by": { + "name": "connected_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mail_accounts_email_uq": { + "name": "mail_accounts_email_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"email\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mail_accounts_organization_id_organizations_id_fk": { + "name": "mail_accounts_organization_id_organizations_id_fk", + "tableFrom": "mail_accounts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mail_accounts_establishment_id_establishments_id_fk": { + "name": "mail_accounts_establishment_id_establishments_id_fk", + "tableFrom": "mail_accounts", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mail_accounts_connected_by_users_id_fk": { + "name": "mail_accounts_connected_by_users_id_fk", + "tableFrom": "mail_accounts", + "tableTo": "users", + "columnsFrom": [ + "connected_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "mail_accounts_provider_ck": { + "name": "mail_accounts_provider_ck", + "value": "\"mail_accounts\".\"provider\" IN ('gmail', 'outlook')" + }, + "mail_accounts_status_ck": { + "name": "mail_accounts_status_ck", + "value": "\"mail_accounts\".\"status\" IN ('connected', 'error', 'disabled')" + }, + "mail_accounts_failures_ck": { + "name": "mail_accounts_failures_ck", + "value": "\"mail_accounts\".\"consecutive_failures\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.mail_documents": { + "name": "mail_documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "part_id": { + "name": "part_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "extracted": { + "name": "extracted", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "supplier_name": { + "name": "supplier_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "siret": { + "name": "siret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "invoice_number": { + "name": "invoice_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "invoice_date": { + "name": "invoice_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "amount_ht": { + "name": "amount_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "amount_ttc": { + "name": "amount_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'a_verifier'" + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "pennylane_record_id": { + "name": "pennylane_record_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "suggested_issue_id": { + "name": "suggested_issue_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "match_reason": { + "name": "match_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "business_document_id": { + "name": "business_document_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "maintenance_invoice_id": { + "name": "maintenance_invoice_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decided_by": { + "name": "decided_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mail_documents_part_uq": { + "name": "mail_documents_part_uq", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "part_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mail_documents_org_idx": { + "name": "mail_documents_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mail_documents_organization_id_organizations_id_fk": { + "name": "mail_documents_organization_id_organizations_id_fk", + "tableFrom": "mail_documents", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mail_documents_message_id_mail_messages_id_fk": { + "name": "mail_documents_message_id_mail_messages_id_fk", + "tableFrom": "mail_documents", + "tableTo": "mail_messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mail_documents_establishment_id_establishments_id_fk": { + "name": "mail_documents_establishment_id_establishments_id_fk", + "tableFrom": "mail_documents", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "mail_documents_supplier_id_suppliers_id_fk": { + "name": "mail_documents_supplier_id_suppliers_id_fk", + "tableFrom": "mail_documents", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "mail_documents_pennylane_record_id_pennylane_records_id_fk": { + "name": "mail_documents_pennylane_record_id_pennylane_records_id_fk", + "tableFrom": "mail_documents", + "tableTo": "pennylane_records", + "columnsFrom": [ + "pennylane_record_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "mail_documents_suggested_issue_id_maintenance_issues_id_fk": { + "name": "mail_documents_suggested_issue_id_maintenance_issues_id_fk", + "tableFrom": "mail_documents", + "tableTo": "maintenance_issues", + "columnsFrom": [ + "suggested_issue_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "mail_documents_business_document_id_business_documents_id_fk": { + "name": "mail_documents_business_document_id_business_documents_id_fk", + "tableFrom": "mail_documents", + "tableTo": "business_documents", + "columnsFrom": [ + "business_document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "mail_documents_maintenance_invoice_id_maintenance_invoices_id_fk": { + "name": "mail_documents_maintenance_invoice_id_maintenance_invoices_id_fk", + "tableFrom": "mail_documents", + "tableTo": "maintenance_invoices", + "columnsFrom": [ + "maintenance_invoice_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "mail_documents_decided_by_users_id_fk": { + "name": "mail_documents_decided_by_users_id_fk", + "tableFrom": "mail_documents", + "tableTo": "users", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "mail_documents_kind_ck": { + "name": "mail_documents_kind_ck", + "value": "\"mail_documents\".\"kind\" IN ('facture', 'devis', 'attestation', 'autre')" + }, + "mail_documents_status_ck": { + "name": "mail_documents_status_ck", + "value": "\"mail_documents\".\"status\" IN ('a_verifier', 'verifiee', 'classee', 'ignoree')" + }, + "mail_documents_size_ck": { + "name": "mail_documents_size_ck", + "value": "\"mail_documents\".\"size\" <= 4718592" + } + }, + "isRLSEnabled": false + }, + "public.mail_messages": { + "name": "mail_messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "thread_id": { + "name": "thread_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "from_name": { + "name": "from_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "from_email": { + "name": "from_email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "to_text": { + "name": "to_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "snippet": { + "name": "snippet", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body_text": { + "name": "body_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "received_at": { + "name": "received_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'autre'" + }, + "attachment_count": { + "name": "attachment_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mail_messages_ext_uq": { + "name": "mail_messages_ext_uq", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mail_messages_org_idx": { + "name": "mail_messages_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "received_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mail_messages_organization_id_organizations_id_fk": { + "name": "mail_messages_organization_id_organizations_id_fk", + "tableFrom": "mail_messages", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mail_messages_account_id_mail_accounts_id_fk": { + "name": "mail_messages_account_id_mail_accounts_id_fk", + "tableFrom": "mail_messages", + "tableTo": "mail_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "mail_messages_category_ck": { + "name": "mail_messages_category_ck", + "value": "\"mail_messages\".\"category\" IN ('facture', 'devis', 'attestation', 'reservation', 'commande', 'autre')" + } + }, + "isRLSEnabled": false + }, + "public.maintenance_interventions": { + "name": "maintenance_interventions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "equipment_id": { + "name": "equipment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "issue_id": { + "name": "issue_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "performed_on": { + "name": "performed_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cost_ht": { + "name": "cost_ht", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "invoice_ref": { + "name": "invoice_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_due_on": { + "name": "next_due_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "maintenance_interventions_eq_idx": { + "name": "maintenance_interventions_eq_idx", + "columns": [ + { + "expression": "equipment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "performed_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "maintenance_interventions_organization_id_organizations_id_fk": { + "name": "maintenance_interventions_organization_id_organizations_id_fk", + "tableFrom": "maintenance_interventions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "maintenance_interventions_establishment_id_establishments_id_fk": { + "name": "maintenance_interventions_establishment_id_establishments_id_fk", + "tableFrom": "maintenance_interventions", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_interventions_equipment_id_equipment_id_fk": { + "name": "maintenance_interventions_equipment_id_equipment_id_fk", + "tableFrom": "maintenance_interventions", + "tableTo": "equipment", + "columnsFrom": [ + "equipment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_interventions_issue_id_maintenance_issues_id_fk": { + "name": "maintenance_interventions_issue_id_maintenance_issues_id_fk", + "tableFrom": "maintenance_interventions", + "tableTo": "maintenance_issues", + "columnsFrom": [ + "issue_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_interventions_recorded_by_users_id_fk": { + "name": "maintenance_interventions_recorded_by_users_id_fk", + "tableFrom": "maintenance_interventions", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "maintenance_interventions_cancelled_by_users_id_fk": { + "name": "maintenance_interventions_cancelled_by_users_id_fk", + "tableFrom": "maintenance_interventions", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "maintenance_interventions_kind_ck": { + "name": "maintenance_interventions_kind_ck", + "value": "\"maintenance_interventions\".\"kind\" IN ('preventive', 'curative', 'reglementaire')" + }, + "maintenance_interventions_cost_ck": { + "name": "maintenance_interventions_cost_ck", + "value": "\"maintenance_interventions\".\"cost_ht\" IS NULL OR \"maintenance_interventions\".\"cost_ht\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.maintenance_invoices": { + "name": "maintenance_invoices", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "equipment_id": { + "name": "equipment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "issue_id": { + "name": "issue_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "quote_id": { + "name": "quote_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pennylane_record_id": { + "name": "pennylane_record_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'reparation'" + }, + "repairer": { + "name": "repairer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "invoice_number": { + "name": "invoice_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "invoice_date": { + "name": "invoice_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "amount_ht": { + "name": "amount_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "amount_ttc": { + "name": "amount_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "document": { + "name": "document", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "document_mime": { + "name": "document_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "document_name": { + "name": "document_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "extracted": { + "name": "extracted", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "auto": { + "name": "auto", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "match_reason": { + "name": "match_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "linked_by": { + "name": "linked_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "maintenance_invoices_est_idx": { + "name": "maintenance_invoices_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "invoice_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "maintenance_invoices_issue_idx": { + "name": "maintenance_invoices_issue_idx", + "columns": [ + { + "expression": "issue_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "maintenance_invoices_pennylane_uq": { + "name": "maintenance_invoices_pennylane_uq", + "columns": [ + { + "expression": "pennylane_record_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"maintenance_invoices\".\"pennylane_record_id\" IS NOT NULL AND \"maintenance_invoices\".\"cancelled_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "maintenance_invoices_organization_id_organizations_id_fk": { + "name": "maintenance_invoices_organization_id_organizations_id_fk", + "tableFrom": "maintenance_invoices", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "maintenance_invoices_establishment_id_establishments_id_fk": { + "name": "maintenance_invoices_establishment_id_establishments_id_fk", + "tableFrom": "maintenance_invoices", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_invoices_equipment_id_equipment_id_fk": { + "name": "maintenance_invoices_equipment_id_equipment_id_fk", + "tableFrom": "maintenance_invoices", + "tableTo": "equipment", + "columnsFrom": [ + "equipment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_invoices_issue_id_maintenance_issues_id_fk": { + "name": "maintenance_invoices_issue_id_maintenance_issues_id_fk", + "tableFrom": "maintenance_invoices", + "tableTo": "maintenance_issues", + "columnsFrom": [ + "issue_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_invoices_quote_id_maintenance_quotes_id_fk": { + "name": "maintenance_invoices_quote_id_maintenance_quotes_id_fk", + "tableFrom": "maintenance_invoices", + "tableTo": "maintenance_quotes", + "columnsFrom": [ + "quote_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_invoices_pennylane_record_id_pennylane_records_id_fk": { + "name": "maintenance_invoices_pennylane_record_id_pennylane_records_id_fk", + "tableFrom": "maintenance_invoices", + "tableTo": "pennylane_records", + "columnsFrom": [ + "pennylane_record_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "maintenance_invoices_linked_by_users_id_fk": { + "name": "maintenance_invoices_linked_by_users_id_fk", + "tableFrom": "maintenance_invoices", + "tableTo": "users", + "columnsFrom": [ + "linked_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "maintenance_invoices_cancelled_by_users_id_fk": { + "name": "maintenance_invoices_cancelled_by_users_id_fk", + "tableFrom": "maintenance_invoices", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "maintenance_invoices_source_ck": { + "name": "maintenance_invoices_source_ck", + "value": "\"maintenance_invoices\".\"source\" IN ('pennylane', 'document', 'saisie')" + }, + "maintenance_invoices_kind_ck": { + "name": "maintenance_invoices_kind_ck", + "value": "\"maintenance_invoices\".\"kind\" IN ('entretien', 'reparation', 'controle')" + }, + "maintenance_invoices_amount_ck": { + "name": "maintenance_invoices_amount_ck", + "value": "(\"maintenance_invoices\".\"amount_ht\" IS NOT NULL OR \"maintenance_invoices\".\"amount_ttc\" IS NOT NULL) AND (\"maintenance_invoices\".\"amount_ht\" IS NULL OR \"maintenance_invoices\".\"amount_ht\" >= 0) AND (\"maintenance_invoices\".\"amount_ttc\" IS NULL OR \"maintenance_invoices\".\"amount_ttc\" >= 0)" + } + }, + "isRLSEnabled": false + }, + "public.maintenance_issues": { + "name": "maintenance_issues", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "equipment_id": { + "name": "equipment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ouvert'" + }, + "reported_by": { + "name": "reported_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "reported_at": { + "name": "reported_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "resolved_by": { + "name": "resolved_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "resolution": { + "name": "resolution", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "maintenance_issues_est_idx": { + "name": "maintenance_issues_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "maintenance_issues_organization_id_organizations_id_fk": { + "name": "maintenance_issues_organization_id_organizations_id_fk", + "tableFrom": "maintenance_issues", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "maintenance_issues_establishment_id_establishments_id_fk": { + "name": "maintenance_issues_establishment_id_establishments_id_fk", + "tableFrom": "maintenance_issues", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_issues_equipment_id_equipment_id_fk": { + "name": "maintenance_issues_equipment_id_equipment_id_fk", + "tableFrom": "maintenance_issues", + "tableTo": "equipment", + "columnsFrom": [ + "equipment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_issues_reported_by_users_id_fk": { + "name": "maintenance_issues_reported_by_users_id_fk", + "tableFrom": "maintenance_issues", + "tableTo": "users", + "columnsFrom": [ + "reported_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "maintenance_issues_resolved_by_users_id_fk": { + "name": "maintenance_issues_resolved_by_users_id_fk", + "tableFrom": "maintenance_issues", + "tableTo": "users", + "columnsFrom": [ + "resolved_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "maintenance_issues_severity_ck": { + "name": "maintenance_issues_severity_ck", + "value": "\"maintenance_issues\".\"severity\" IN ('bloquant', 'genant', 'mineur')" + }, + "maintenance_issues_status_ck": { + "name": "maintenance_issues_status_ck", + "value": "\"maintenance_issues\".\"status\" IN ('ouvert', 'en_cours', 'resolu')" + } + }, + "isRLSEnabled": false + }, + "public.maintenance_quotes": { + "name": "maintenance_quotes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "issue_id": { + "name": "issue_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "repairer": { + "name": "repairer", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quote_ref": { + "name": "quote_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "received_on": { + "name": "received_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "amount_ht": { + "name": "amount_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "amount_ttc": { + "name": "amount_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "document": { + "name": "document", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "document_mime": { + "name": "document_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "document_name": { + "name": "document_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "extracted": { + "name": "extracted", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'a_valider'" + }, + "decided_by": { + "name": "decided_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "decision_note": { + "name": "decision_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "maintenance_quotes_issue_idx": { + "name": "maintenance_quotes_issue_idx", + "columns": [ + { + "expression": "issue_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "maintenance_quotes_est_idx": { + "name": "maintenance_quotes_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "maintenance_quotes_one_valid_uq": { + "name": "maintenance_quotes_one_valid_uq", + "columns": [ + { + "expression": "issue_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"maintenance_quotes\".\"status\" = 'valide'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "maintenance_quotes_organization_id_organizations_id_fk": { + "name": "maintenance_quotes_organization_id_organizations_id_fk", + "tableFrom": "maintenance_quotes", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "maintenance_quotes_establishment_id_establishments_id_fk": { + "name": "maintenance_quotes_establishment_id_establishments_id_fk", + "tableFrom": "maintenance_quotes", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_quotes_issue_id_maintenance_issues_id_fk": { + "name": "maintenance_quotes_issue_id_maintenance_issues_id_fk", + "tableFrom": "maintenance_quotes", + "tableTo": "maintenance_issues", + "columnsFrom": [ + "issue_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "maintenance_quotes_decided_by_users_id_fk": { + "name": "maintenance_quotes_decided_by_users_id_fk", + "tableFrom": "maintenance_quotes", + "tableTo": "users", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "maintenance_quotes_created_by_users_id_fk": { + "name": "maintenance_quotes_created_by_users_id_fk", + "tableFrom": "maintenance_quotes", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "maintenance_quotes_status_ck": { + "name": "maintenance_quotes_status_ck", + "value": "\"maintenance_quotes\".\"status\" IN ('a_valider', 'valide', 'refuse')" + }, + "maintenance_quotes_amount_ck": { + "name": "maintenance_quotes_amount_ck", + "value": "(\"maintenance_quotes\".\"amount_ht\" IS NOT NULL OR \"maintenance_quotes\".\"amount_ttc\" IS NOT NULL) AND (\"maintenance_quotes\".\"amount_ht\" IS NULL OR \"maintenance_quotes\".\"amount_ht\" >= 0) AND (\"maintenance_quotes\".\"amount_ttc\" IS NULL OR \"maintenance_quotes\".\"amount_ttc\" >= 0)" + } + }, + "isRLSEnabled": false + }, + "public.marketing_campaigns": { + "name": "marketing_campaigns", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "segment": { + "name": "segment", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sms_text": { + "name": "sms_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'brouillon'" + }, + "recipients_count": { + "name": "recipients_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "marketing_campaigns_org_idx": { + "name": "marketing_campaigns_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "marketing_campaigns_organization_id_organizations_id_fk": { + "name": "marketing_campaigns_organization_id_organizations_id_fk", + "tableFrom": "marketing_campaigns", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "marketing_campaigns_establishment_id_establishments_id_fk": { + "name": "marketing_campaigns_establishment_id_establishments_id_fk", + "tableFrom": "marketing_campaigns", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "marketing_campaigns_created_by_users_id_fk": { + "name": "marketing_campaigns_created_by_users_id_fk", + "tableFrom": "marketing_campaigns", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "marketing_campaigns_status_ck": { + "name": "marketing_campaigns_status_ck", + "value": "\"marketing_campaigns\".\"status\" IN ('brouillon', 'envoyee')" + } + }, + "isRLSEnabled": false + }, + "public.media_assets": { + "name": "media_assets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "recipe_id": { + "name": "recipe_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tags": { + "name": "tags", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'upload'" + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "used_count": { + "name": "used_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "media_assets_org_idx": { + "name": "media_assets_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "media_assets_recipe_idx": { + "name": "media_assets_recipe_idx", + "columns": [ + { + "expression": "recipe_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "media_assets_hash_uq": { + "name": "media_assets_hash_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sha256", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_assets_organization_id_organizations_id_fk": { + "name": "media_assets_organization_id_organizations_id_fk", + "tableFrom": "media_assets", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_assets_establishment_id_establishments_id_fk": { + "name": "media_assets_establishment_id_establishments_id_fk", + "tableFrom": "media_assets", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_assets_recipe_id_recipes_id_fk": { + "name": "media_assets_recipe_id_recipes_id_fk", + "tableFrom": "media_assets", + "tableTo": "recipes", + "columnsFrom": [ + "recipe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "media_assets_created_by_users_id_fk": { + "name": "media_assets_created_by_users_id_fk", + "tableFrom": "media_assets", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "media_assets_source_ck": { + "name": "media_assets_source_ck", + "value": "\"media_assets\".\"source\" IN ('upload', 'fiche', 'studio')" + }, + "media_assets_mime_ck": { + "name": "media_assets_mime_ck", + "value": "\"media_assets\".\"mime\" IN ('image/jpeg', 'image/png', 'image/webp')" + }, + "media_assets_size_ck": { + "name": "media_assets_size_ck", + "value": "\"media_assets\".\"size\" BETWEEN 1 AND 5242880" + }, + "media_assets_title_ck": { + "name": "media_assets_title_ck", + "value": "char_length(\"media_assets\".\"title\") BETWEEN 1 AND 120" + } + }, + "isRLSEnabled": false + }, + "public.membership_establishments": { + "name": "membership_establishments", + "schema": "", + "columns": { + "membership_id": { + "name": "membership_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "membership_establishments_membership_id_memberships_id_fk": { + "name": "membership_establishments_membership_id_memberships_id_fk", + "tableFrom": "membership_establishments", + "tableTo": "memberships", + "columnsFrom": [ + "membership_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "membership_establishments_establishment_id_establishments_id_fk": { + "name": "membership_establishments_establishment_id_establishments_id_fk", + "tableFrom": "membership_establishments", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "membership_establishments_membership_id_establishment_id_pk": { + "name": "membership_establishments_membership_id_establishment_id_pk", + "columns": [ + "membership_id", + "establishment_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memberships": { + "name": "memberships", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "member_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "all_establishments": { + "name": "all_establishments", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "permissions_added": { + "name": "permissions_added", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "permissions_removed": { + "name": "permissions_removed", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "memberships_user_org_uq": { + "name": "memberships_user_org_uq", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memberships_user_id_users_id_fk": { + "name": "memberships_user_id_users_id_fk", + "tableFrom": "memberships", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memberships_organization_id_organizations_id_fk": { + "name": "memberships_organization_id_organizations_id_fk", + "tableFrom": "memberships", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.messages": { + "name": "messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "messages_conv_idx": { + "name": "messages_conv_idx", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "messages_organization_id_organizations_id_fk": { + "name": "messages_organization_id_organizations_id_fk", + "tableFrom": "messages", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "messages_conversation_id_conversations_id_fk": { + "name": "messages_conversation_id_conversations_id_fk", + "tableFrom": "messages", + "tableTo": "conversations", + "columnsFrom": [ + "conversation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "messages_user_id_users_id_fk": { + "name": "messages_user_id_users_id_fk", + "tableFrom": "messages", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mfa_challenges": { + "name": "mfa_challenges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mfa_challenges_user_idx": { + "name": "mfa_challenges_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mfa_challenges_user_id_users_id_fk": { + "name": "mfa_challenges_user_id_users_id_fk", + "tableFrom": "mfa_challenges", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.monthly_budgets": { + "name": "monthly_budgets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "month": { + "name": "month", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "revenue_ht": { + "name": "revenue_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "covers": { + "name": "covers", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "charges_ht": { + "name": "charges_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "food_cost_pct": { + "name": "food_cost_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "beverage_cost_pct": { + "name": "beverage_cost_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "labor_cost_pct": { + "name": "labor_cost_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "monthly_budgets_est_month_uq": { + "name": "monthly_budgets_est_month_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "month", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "monthly_budgets_org_idx": { + "name": "monthly_budgets_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "month", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "monthly_budgets_organization_id_organizations_id_fk": { + "name": "monthly_budgets_organization_id_organizations_id_fk", + "tableFrom": "monthly_budgets", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "monthly_budgets_establishment_id_establishments_id_fk": { + "name": "monthly_budgets_establishment_id_establishments_id_fk", + "tableFrom": "monthly_budgets", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "monthly_budgets_updated_by_users_id_fk": { + "name": "monthly_budgets_updated_by_users_id_fk", + "tableFrom": "monthly_budgets", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "monthly_budgets_month_ck": { + "name": "monthly_budgets_month_ck", + "value": "extract(day from \"monthly_budgets\".\"month\") = 1" + }, + "monthly_budgets_values_ck": { + "name": "monthly_budgets_values_ck", + "value": "(\"monthly_budgets\".\"revenue_ht\" IS NULL OR \"monthly_budgets\".\"revenue_ht\" >= 0) AND (\"monthly_budgets\".\"charges_ht\" IS NULL OR \"monthly_budgets\".\"charges_ht\" >= 0) AND (\"monthly_budgets\".\"covers\" IS NULL OR \"monthly_budgets\".\"covers\" >= 0)\n AND (\"monthly_budgets\".\"food_cost_pct\" IS NULL OR \"monthly_budgets\".\"food_cost_pct\" BETWEEN 0 AND 100) AND (\"monthly_budgets\".\"beverage_cost_pct\" IS NULL OR \"monthly_budgets\".\"beverage_cost_pct\" BETWEEN 0 AND 100) AND (\"monthly_budgets\".\"labor_cost_pct\" IS NULL OR \"monthly_budgets\".\"labor_cost_pct\" BETWEEN 0 AND 100)" + } + }, + "isRLSEnabled": false + }, + "public.notification_deliveries": { + "name": "notification_deliveries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "notification_id": { + "name": "notification_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "email_outbox_id": { + "name": "email_outbox_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "push_subscription_id": { + "name": "push_subscription_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "target": { + "name": "target", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "notification_deliveries_org_idx": { + "name": "notification_deliveries_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "notification_deliveries_user_idx": { + "name": "notification_deliveries_user_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "notification_deliveries_pending_idx": { + "name": "notification_deliveries_pending_idx", + "columns": [ + { + "expression": "channel", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "notification_deliveries_organization_id_organizations_id_fk": { + "name": "notification_deliveries_organization_id_organizations_id_fk", + "tableFrom": "notification_deliveries", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notification_deliveries_user_id_users_id_fk": { + "name": "notification_deliveries_user_id_users_id_fk", + "tableFrom": "notification_deliveries", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notification_deliveries_notification_id_notifications_id_fk": { + "name": "notification_deliveries_notification_id_notifications_id_fk", + "tableFrom": "notification_deliveries", + "tableTo": "notifications", + "columnsFrom": [ + "notification_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "notification_deliveries_email_outbox_id_email_outbox_id_fk": { + "name": "notification_deliveries_email_outbox_id_email_outbox_id_fk", + "tableFrom": "notification_deliveries", + "tableTo": "email_outbox", + "columnsFrom": [ + "email_outbox_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "notification_deliveries_push_subscription_id_push_subscriptions_id_fk": { + "name": "notification_deliveries_push_subscription_id_push_subscriptions_id_fk", + "tableFrom": "notification_deliveries", + "tableTo": "push_subscriptions", + "columnsFrom": [ + "push_subscription_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "notification_deliveries_channel_ck": { + "name": "notification_deliveries_channel_ck", + "value": "\"notification_deliveries\".\"channel\" IN ('in_app', 'email', 'push', 'sms')" + }, + "notification_deliveries_status_ck": { + "name": "notification_deliveries_status_ck", + "value": "\"notification_deliveries\".\"status\" IN ('envoye', 'en_attente', 'echec', 'simule', 'desactive', 'indisponible')" + } + }, + "isRLSEnabled": false + }, + "public.notification_preferences": { + "name": "notification_preferences", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "notification_preferences_organization_id_organizations_id_fk": { + "name": "notification_preferences_organization_id_organizations_id_fk", + "tableFrom": "notification_preferences", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notification_preferences_user_id_users_id_fk": { + "name": "notification_preferences_user_id_users_id_fk", + "tableFrom": "notification_preferences", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "notification_preferences_organization_id_user_id_category_channel_pk": { + "name": "notification_preferences_organization_id_user_id_category_channel_pk", + "columns": [ + "organization_id", + "user_id", + "category", + "channel" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "notification_preferences_channel_ck": { + "name": "notification_preferences_channel_ck", + "value": "\"notification_preferences\".\"channel\" IN ('in_app', 'email', 'push', 'sms')" + } + }, + "isRLSEnabled": false + }, + "public.notification_templates": { + "name": "notification_templates", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "notification_templates_organization_id_organizations_id_fk": { + "name": "notification_templates_organization_id_organizations_id_fk", + "tableFrom": "notification_templates", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notification_templates_updated_by_users_id_fk": { + "name": "notification_templates_updated_by_users_id_fk", + "tableFrom": "notification_templates", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "notification_templates_organization_id_category_channel_pk": { + "name": "notification_templates_organization_id_category_channel_pk", + "columns": [ + "organization_id", + "category", + "channel" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "notification_templates_channel_ck": { + "name": "notification_templates_channel_ck", + "value": "\"notification_templates\".\"channel\" IN ('email', 'push', 'sms')" + } + }, + "isRLSEnabled": false + }, + "public.notifications": { + "name": "notifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "href": { + "name": "href", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "notifications_user_idx": { + "name": "notifications_user_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "read_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "notifications_organization_id_organizations_id_fk": { + "name": "notifications_organization_id_organizations_id_fk", + "tableFrom": "notifications", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_user_id_users_id_fk": { + "name": "notifications_user_id_users_id_fk", + "tableFrom": "notifications", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oil_checks": { + "name": "oil_checks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "equipment_id": { + "name": "equipment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "temperature": { + "name": "temperature", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "polar_pct": { + "name": "polar_pct", + "type": "numeric(4, 1)", + "primaryKey": false, + "notNull": false + }, + "conform": { + "name": "conform", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "corrective_action": { + "name": "corrective_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "oil_checks_est_idx": { + "name": "oil_checks_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oil_checks_organization_id_organizations_id_fk": { + "name": "oil_checks_organization_id_organizations_id_fk", + "tableFrom": "oil_checks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oil_checks_establishment_id_establishments_id_fk": { + "name": "oil_checks_establishment_id_establishments_id_fk", + "tableFrom": "oil_checks", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "oil_checks_equipment_id_equipment_id_fk": { + "name": "oil_checks_equipment_id_equipment_id_fk", + "tableFrom": "oil_checks", + "tableTo": "equipment", + "columnsFrom": [ + "equipment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "oil_checks_recorded_by_users_id_fk": { + "name": "oil_checks_recorded_by_users_id_fk", + "tableFrom": "oil_checks", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "oil_checks_cancelled_by_users_id_fk": { + "name": "oil_checks_cancelled_by_users_id_fk", + "tableFrom": "oil_checks", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "oil_checks_kind_ck": { + "name": "oil_checks_kind_ck", + "value": "\"oil_checks\".\"kind\" IN ('controle', 'filtrage', 'changement')" + }, + "oil_checks_action_ck": { + "name": "oil_checks_action_ck", + "value": "\"oil_checks\".\"conform\" OR \"oil_checks\".\"corrective_action\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.onboarding_items": { + "name": "onboarding_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "step_id": { + "name": "step_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "due_on": { + "name": "due_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "auto_check": { + "name": "auto_check", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "done_at": { + "name": "done_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "done_by": { + "name": "done_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "done_how": { + "name": "done_how", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "onboarding_items_emp_idx": { + "name": "onboarding_items_emp_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "onboarding_items_step_uq": { + "name": "onboarding_items_step_uq", + "columns": [ + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "step_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"onboarding_items\".\"step_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "onboarding_items_organization_id_organizations_id_fk": { + "name": "onboarding_items_organization_id_organizations_id_fk", + "tableFrom": "onboarding_items", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "onboarding_items_employee_id_employees_id_fk": { + "name": "onboarding_items_employee_id_employees_id_fk", + "tableFrom": "onboarding_items", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "onboarding_items_step_id_onboarding_steps_id_fk": { + "name": "onboarding_items_step_id_onboarding_steps_id_fk", + "tableFrom": "onboarding_items", + "tableTo": "onboarding_steps", + "columnsFrom": [ + "step_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "onboarding_items_done_by_users_id_fk": { + "name": "onboarding_items_done_by_users_id_fk", + "tableFrom": "onboarding_items", + "tableTo": "users", + "columnsFrom": [ + "done_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "onboarding_items_how_ck": { + "name": "onboarding_items_how_ck", + "value": "\"onboarding_items\".\"done_how\" IS NULL OR \"onboarding_items\".\"done_how\" IN ('manuel', 'auto')" + } + }, + "isRLSEnabled": false + }, + "public.onboarding_steps": { + "name": "onboarding_steps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "team": { + "name": "team", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "day_offset": { + "name": "day_offset", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "auto_check": { + "name": "auto_check", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "onboarding_steps_org_idx": { + "name": "onboarding_steps_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "onboarding_steps_organization_id_organizations_id_fk": { + "name": "onboarding_steps_organization_id_organizations_id_fk", + "tableFrom": "onboarding_steps", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "onboarding_steps_offset_ck": { + "name": "onboarding_steps_offset_ck", + "value": "\"onboarding_steps\".\"day_offset\" BETWEEN -60 AND 365" + } + }, + "isRLSEnabled": false + }, + "public.organizations": { + "name": "organizations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_demo": { + "name": "is_demo", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "stock_valuation": { + "name": "stock_valuation", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'dernier_prix'" + }, + "require_mfa": { + "name": "require_mfa", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_via": { + "name": "created_via", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "onboarding_dismissed_at": { + "name": "onboarding_dismissed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "onboarding_skipped": { + "name": "onboarding_skipped", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "is_test": { + "name": "is_test", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "suspended_at": { + "name": "suspended_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "organizations_slug_unique": { + "name": "organizations_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": { + "organizations_stock_valuation_ck": { + "name": "organizations_stock_valuation_ck", + "value": "\"organizations\".\"stock_valuation\" IN ('dernier_prix', 'cump', 'fifo')" + }, + "organizations_demo_or_test_ck": { + "name": "organizations_demo_or_test_ck", + "value": "NOT (\"organizations\".\"is_demo\" AND \"organizations\".\"is_test\")" + } + }, + "isRLSEnabled": false + }, + "public.partner_booking_imports": { + "name": "partner_booking_imports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "partner": { + "name": "partner", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "origin": { + "name": "origin", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created": { + "name": "created", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "updated": { + "name": "updated", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cancelled": { + "name": "cancelled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "unchanged": { + "name": "unchanged", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "skipped": { + "name": "skipped", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "notes": { + "name": "notes", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "partner_booking_imports_est_idx": { + "name": "partner_booking_imports_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "partner_booking_imports_organization_id_organizations_id_fk": { + "name": "partner_booking_imports_organization_id_organizations_id_fk", + "tableFrom": "partner_booking_imports", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "partner_booking_imports_establishment_id_establishments_id_fk": { + "name": "partner_booking_imports_establishment_id_establishments_id_fk", + "tableFrom": "partner_booking_imports", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "partner_booking_imports_created_by_users_id_fk": { + "name": "partner_booking_imports_created_by_users_id_fk", + "tableFrom": "partner_booking_imports", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "partner_booking_imports_partner_ck": { + "name": "partner_booking_imports_partner_ck", + "value": "\"partner_booking_imports\".\"partner\" IN ('thefork', 'opentable', 'google')" + }, + "partner_booking_imports_origin_ck": { + "name": "partner_booking_imports_origin_ck", + "value": "\"partner_booking_imports\".\"origin\" IN ('api', 'fichier', 'demo')" + } + }, + "isRLSEnabled": false + }, + "public.payroll_bonuses": { + "name": "payroll_bonuses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount_gross": { + "name": "amount_gross", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payroll_bonuses_est_date_idx": { + "name": "payroll_bonuses_est_date_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payroll_bonuses_org_idx": { + "name": "payroll_bonuses_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "payroll_bonuses_organization_id_organizations_id_fk": { + "name": "payroll_bonuses_organization_id_organizations_id_fk", + "tableFrom": "payroll_bonuses", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payroll_bonuses_establishment_id_establishments_id_fk": { + "name": "payroll_bonuses_establishment_id_establishments_id_fk", + "tableFrom": "payroll_bonuses", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payroll_bonuses_employee_id_employees_id_fk": { + "name": "payroll_bonuses_employee_id_employees_id_fk", + "tableFrom": "payroll_bonuses", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payroll_bonuses_created_by_users_id_fk": { + "name": "payroll_bonuses_created_by_users_id_fk", + "tableFrom": "payroll_bonuses", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "payroll_bonuses_amount_ck": { + "name": "payroll_bonuses_amount_ck", + "value": "\"payroll_bonuses\".\"amount_gross\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.payroll_parameters": { + "name": "payroll_parameters", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "effective_from": { + "name": "effective_from", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "employer_charge_pct": { + "name": "employer_charge_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "labor_alert_pct": { + "name": "labor_alert_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "source_note": { + "name": "source_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "min_productivity_ht": { + "name": "min_productivity_ht", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "meal_value": { + "name": "meal_value", + "type": "numeric(8, 4)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "payroll_parameters_est_from_uq": { + "name": "payroll_parameters_est_from_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "effective_from", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "payroll_parameters_org_idx": { + "name": "payroll_parameters_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "payroll_parameters_organization_id_organizations_id_fk": { + "name": "payroll_parameters_organization_id_organizations_id_fk", + "tableFrom": "payroll_parameters", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payroll_parameters_establishment_id_establishments_id_fk": { + "name": "payroll_parameters_establishment_id_establishments_id_fk", + "tableFrom": "payroll_parameters", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "payroll_parameters_created_by_users_id_fk": { + "name": "payroll_parameters_created_by_users_id_fk", + "tableFrom": "payroll_parameters", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "payroll_parameters_pct_ck": { + "name": "payroll_parameters_pct_ck", + "value": "(\"payroll_parameters\".\"employer_charge_pct\" IS NULL OR \"payroll_parameters\".\"employer_charge_pct\" BETWEEN 0 AND 100) AND (\"payroll_parameters\".\"labor_alert_pct\" IS NULL OR \"payroll_parameters\".\"labor_alert_pct\" BETWEEN 0 AND 100)" + }, + "payroll_parameters_prod_ck": { + "name": "payroll_parameters_prod_ck", + "value": "\"payroll_parameters\".\"min_productivity_ht\" IS NULL OR \"payroll_parameters\".\"min_productivity_ht\" > 0" + }, + "payroll_parameters_meal_ck": { + "name": "payroll_parameters_meal_ck", + "value": "\"payroll_parameters\".\"meal_value\" IS NULL OR \"payroll_parameters\".\"meal_value\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.pennylane_category_mappings": { + "name": "pennylane_category_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "category_key": { + "name": "category_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target": { + "name": "target", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pennylane_category_mappings_uq": { + "name": "pennylane_category_mappings_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "category_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pennylane_category_mappings_organization_id_organizations_id_fk": { + "name": "pennylane_category_mappings_organization_id_organizations_id_fk", + "tableFrom": "pennylane_category_mappings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pennylane_category_mappings_updated_by_users_id_fk": { + "name": "pennylane_category_mappings_updated_by_users_id_fk", + "tableFrom": "pennylane_category_mappings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pennylane_item_prices": { + "name": "pennylane_item_prices", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "record_id": { + "name": "record_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "line_index": { + "name": "line_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "invoice_date": { + "name": "invoice_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "supplier_name": { + "name": "supplier_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "unit_price_ht": { + "name": "unit_price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": true + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pennylane_item_prices_line_uq": { + "name": "pennylane_item_prices_line_uq", + "columns": [ + { + "expression": "record_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "line_index", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pennylane_item_prices_item_idx": { + "name": "pennylane_item_prices_item_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "invoice_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pennylane_item_prices_organization_id_organizations_id_fk": { + "name": "pennylane_item_prices_organization_id_organizations_id_fk", + "tableFrom": "pennylane_item_prices", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pennylane_item_prices_establishment_id_establishments_id_fk": { + "name": "pennylane_item_prices_establishment_id_establishments_id_fk", + "tableFrom": "pennylane_item_prices", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pennylane_item_prices_record_id_pennylane_records_id_fk": { + "name": "pennylane_item_prices_record_id_pennylane_records_id_fk", + "tableFrom": "pennylane_item_prices", + "tableTo": "pennylane_records", + "columnsFrom": [ + "record_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pennylane_item_prices_item_id_purchase_items_id_fk": { + "name": "pennylane_item_prices_item_id_purchase_items_id_fk", + "tableFrom": "pennylane_item_prices", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pennylane_item_prices_method_ck": { + "name": "pennylane_item_prices_method_ck", + "value": "\"pennylane_item_prices\".\"method\" IN ('confirme', 'reference', 'libelle')" + }, + "pennylane_item_prices_values_ck": { + "name": "pennylane_item_prices_values_ck", + "value": "\"pennylane_item_prices\".\"quantity\" > 0 AND \"pennylane_item_prices\".\"unit_price_ht\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.pennylane_records": { + "name": "pennylane_records", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "third_party": { + "name": "third_party", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "remaining": { + "name": "remaining", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "payment_status": { + "name": "payment_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'unknown'" + }, + "currency": { + "name": "currency", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "bank_account_ref": { + "name": "bank_account_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "raw": { + "name": "raw", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "lines": { + "name": "lines", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "categories": { + "name": "categories", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "synced_at": { + "name": "synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pennylane_records_uq": { + "name": "pennylane_records_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pennylane_records_date_idx": { + "name": "pennylane_records_date_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pennylane_records_organization_id_organizations_id_fk": { + "name": "pennylane_records_organization_id_organizations_id_fk", + "tableFrom": "pennylane_records", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pennylane_records_establishment_id_establishments_id_fk": { + "name": "pennylane_records_establishment_id_establishments_id_fk", + "tableFrom": "pennylane_records", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pennylane_records_kind_ck": { + "name": "pennylane_records_kind_ck", + "value": "\"pennylane_records\".\"kind\" IN ('supplier_invoice', 'customer_invoice', 'transaction', 'bank_account')" + } + }, + "isRLSEnabled": false + }, + "public.pest_control_contracts": { + "name": "pest_control_contracts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider_name": { + "name": "provider_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "certibiocide_number": { + "name": "certibiocide_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contact_phone": { + "name": "contact_phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contact_email": { + "name": "contact_email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "starts_on": { + "name": "starts_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "ends_on": { + "name": "ends_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "visits_per_year": { + "name": "visits_per_year", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "trap_plan": { + "name": "trap_plan", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "trap_plan_mime": { + "name": "trap_plan_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "trap_plan_size": { + "name": "trap_plan_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pest_control_contracts_est_idx": { + "name": "pest_control_contracts_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pest_control_contracts_organization_id_organizations_id_fk": { + "name": "pest_control_contracts_organization_id_organizations_id_fk", + "tableFrom": "pest_control_contracts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pest_control_contracts_establishment_id_establishments_id_fk": { + "name": "pest_control_contracts_establishment_id_establishments_id_fk", + "tableFrom": "pest_control_contracts", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pest_control_contracts_created_by_users_id_fk": { + "name": "pest_control_contracts_created_by_users_id_fk", + "tableFrom": "pest_control_contracts", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pest_control_contracts_visits_ck": { + "name": "pest_control_contracts_visits_ck", + "value": "\"pest_control_contracts\".\"visits_per_year\" IS NULL OR (\"pest_control_contracts\".\"visits_per_year\" BETWEEN 1 AND 52)" + }, + "pest_control_contracts_plan_ck": { + "name": "pest_control_contracts_plan_ck", + "value": "\"pest_control_contracts\".\"trap_plan_size\" IS NULL OR \"pest_control_contracts\".\"trap_plan_size\" <= 5242880" + } + }, + "isRLSEnabled": false + }, + "public.pest_control_visits": { + "name": "pest_control_visits", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "visit_on": { + "name": "visit_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'contrat'" + }, + "technician_name": { + "name": "technician_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "activity": { + "name": "activity", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pests": { + "name": "pests", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "findings": { + "name": "findings", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actions": { + "name": "actions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recommendations": { + "name": "recommendations", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "products": { + "name": "products", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sign_token_hash": { + "name": "sign_token_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sign_token_expires_at": { + "name": "sign_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "signed_at": { + "name": "signed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "signer_name": { + "name": "signer_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "signature": { + "name": "signature", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "corrective_action_id": { + "name": "corrective_action_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pest_control_visits_est_idx": { + "name": "pest_control_visits_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "visit_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pest_control_visits_token_uq": { + "name": "pest_control_visits_token_uq", + "columns": [ + { + "expression": "sign_token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"pest_control_visits\".\"sign_token_hash\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pest_control_visits_organization_id_organizations_id_fk": { + "name": "pest_control_visits_organization_id_organizations_id_fk", + "tableFrom": "pest_control_visits", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pest_control_visits_establishment_id_establishments_id_fk": { + "name": "pest_control_visits_establishment_id_establishments_id_fk", + "tableFrom": "pest_control_visits", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pest_control_visits_contract_id_pest_control_contracts_id_fk": { + "name": "pest_control_visits_contract_id_pest_control_contracts_id_fk", + "tableFrom": "pest_control_visits", + "tableTo": "pest_control_contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pest_control_visits_corrective_action_id_haccp_corrective_actions_id_fk": { + "name": "pest_control_visits_corrective_action_id_haccp_corrective_actions_id_fk", + "tableFrom": "pest_control_visits", + "tableTo": "haccp_corrective_actions", + "columnsFrom": [ + "corrective_action_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pest_control_visits_recorded_by_users_id_fk": { + "name": "pest_control_visits_recorded_by_users_id_fk", + "tableFrom": "pest_control_visits", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "pest_control_visits_cancelled_by_users_id_fk": { + "name": "pest_control_visits_cancelled_by_users_id_fk", + "tableFrom": "pest_control_visits", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pest_control_visits_kind_ck": { + "name": "pest_control_visits_kind_ck", + "value": "\"pest_control_visits\".\"kind\" IN ('contrat', 'curatif')" + }, + "pest_control_visits_activity_ck": { + "name": "pest_control_visits_activity_ck", + "value": "\"pest_control_visits\".\"activity\" IS NULL OR \"pest_control_visits\".\"activity\" IN ('aucune', 'faible', 'forte')" + }, + "pest_control_visits_signed_ck": { + "name": "pest_control_visits_signed_ck", + "value": "(\"pest_control_visits\".\"signed_at\" IS NULL) = (\"pest_control_visits\".\"signature\" IS NULL)" + } + }, + "isRLSEnabled": false + }, + "public.planning_absences": { + "name": "planning_absences", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "part": { + "name": "part", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'journee'" + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "planning_absences_uq": { + "name": "planning_absences_uq", + "columns": [ + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "part", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_absences_organization_id_organizations_id_fk": { + "name": "planning_absences_organization_id_organizations_id_fk", + "tableFrom": "planning_absences", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "planning_absences_employee_id_employees_id_fk": { + "name": "planning_absences_employee_id_employees_id_fk", + "tableFrom": "planning_absences", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "planning_absences_created_by_users_id_fk": { + "name": "planning_absences_created_by_users_id_fk", + "tableFrom": "planning_absences", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "planning_absences_part_ck": { + "name": "planning_absences_part_ck", + "value": "\"planning_absences\".\"part\" IN ('journee', 'matin', 'apres_midi')" + } + }, + "isRLSEnabled": false + }, + "public.planning_day_budgets": { + "name": "planning_day_budgets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "sales_ht": { + "name": "sales_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "planning_day_budgets_uq": { + "name": "planning_day_budgets_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "planning_day_budgets_org_idx": { + "name": "planning_day_budgets_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_day_budgets_organization_id_organizations_id_fk": { + "name": "planning_day_budgets_organization_id_organizations_id_fk", + "tableFrom": "planning_day_budgets", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "planning_day_budgets_establishment_id_establishments_id_fk": { + "name": "planning_day_budgets_establishment_id_establishments_id_fk", + "tableFrom": "planning_day_budgets", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "planning_day_budgets_updated_by_users_id_fk": { + "name": "planning_day_budgets_updated_by_users_id_fk", + "tableFrom": "planning_day_budgets", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "planning_day_budgets_ck": { + "name": "planning_day_budgets_ck", + "value": "\"planning_day_budgets\".\"sales_ht\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.planning_day_notes": { + "name": "planning_day_notes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "planning_day_notes_uq": { + "name": "planning_day_notes_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_day_notes_organization_id_organizations_id_fk": { + "name": "planning_day_notes_organization_id_organizations_id_fk", + "tableFrom": "planning_day_notes", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "planning_day_notes_establishment_id_establishments_id_fk": { + "name": "planning_day_notes_establishment_id_establishments_id_fk", + "tableFrom": "planning_day_notes", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "planning_day_notes_updated_by_users_id_fk": { + "name": "planning_day_notes_updated_by_users_id_fk", + "tableFrom": "planning_day_notes", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "planning_day_notes_len_ck": { + "name": "planning_day_notes_len_ck", + "value": "char_length(\"planning_day_notes\".\"text\") BETWEEN 1 AND 500" + } + }, + "isRLSEnabled": false + }, + "public.planning_weeks": { + "name": "planning_weeks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "week_start": { + "name": "week_start", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "published_by": { + "name": "published_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "changed_at": { + "name": "changed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "sales_forecast_ht": { + "name": "sales_forecast_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "hours_budget": { + "name": "hours_budget", + "type": "numeric(8, 2)", + "primaryKey": false, + "notNull": false + }, + "published_teams": { + "name": "published_teams", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "published_pdf": { + "name": "published_pdf", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "planning_weeks_uq": { + "name": "planning_weeks_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "week_start", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "planning_weeks_organization_id_organizations_id_fk": { + "name": "planning_weeks_organization_id_organizations_id_fk", + "tableFrom": "planning_weeks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "planning_weeks_establishment_id_establishments_id_fk": { + "name": "planning_weeks_establishment_id_establishments_id_fk", + "tableFrom": "planning_weeks", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "planning_weeks_published_by_users_id_fk": { + "name": "planning_weeks_published_by_users_id_fk", + "tableFrom": "planning_weeks", + "tableTo": "users", + "columnsFrom": [ + "published_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.platform_settings": { + "name": "platform_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "default": 1 + }, + "signup_open": { + "name": "signup_open", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "mail_organization_id": { + "name": "mail_organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "vapid_public_key": { + "name": "vapid_public_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vapid_private_enc": { + "name": "vapid_private_enc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "platform_settings_mail_organization_id_organizations_id_fk": { + "name": "platform_settings_mail_organization_id_organizations_id_fk", + "tableFrom": "platform_settings", + "tableTo": "organizations", + "columnsFrom": [ + "mail_organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "platform_settings_updated_by_users_id_fk": { + "name": "platform_settings_updated_by_users_id_fk", + "tableFrom": "platform_settings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "platform_settings_single_ck": { + "name": "platform_settings_single_ck", + "value": "\"platform_settings\".\"id\" = 1" + } + }, + "isRLSEnabled": false + }, + "public.posting_records": { + "name": "posting_records", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "values": { + "name": "values", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "installed_on": { + "name": "installed_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo_size": { + "name": "photo_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "validated_by": { + "name": "validated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "validated_by_name": { + "name": "validated_by_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "validated_at": { + "name": "validated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "posting_records_uq": { + "name": "posting_records_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "posting_records_org_idx": { + "name": "posting_records_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "posting_records_organization_id_organizations_id_fk": { + "name": "posting_records_organization_id_organizations_id_fk", + "tableFrom": "posting_records", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "posting_records_establishment_id_establishments_id_fk": { + "name": "posting_records_establishment_id_establishments_id_fk", + "tableFrom": "posting_records", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "posting_records_validated_by_users_id_fk": { + "name": "posting_records_validated_by_users_id_fk", + "tableFrom": "posting_records", + "tableTo": "users", + "columnsFrom": [ + "validated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "posting_records_updated_by_users_id_fk": { + "name": "posting_records_updated_by_users_id_fk", + "tableFrom": "posting_records", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "posting_records_photo_ck": { + "name": "posting_records_photo_ck", + "value": "(\"posting_records\".\"photo\" IS NULL) = (\"posting_records\".\"photo_mime\" IS NULL) AND (\"posting_records\".\"photo\" IS NULL OR \"posting_records\".\"photo_mime\" IN ('image/jpeg', 'image/png', 'image/webp'))" + }, + "posting_records_validation_ck": { + "name": "posting_records_validation_ck", + "value": "(\"posting_records\".\"validated_at\" IS NULL) = (\"posting_records\".\"validated_by_name\" IS NULL)" + } + }, + "isRLSEnabled": false + }, + "public.price_request_lines": { + "name": "price_request_lines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "pack_size": { + "name": "pack_size", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "pack_label": { + "name": "pack_label", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "price_request_lines_item_uq": { + "name": "price_request_lines_item_uq", + "columns": [ + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "price_request_lines_organization_id_organizations_id_fk": { + "name": "price_request_lines_organization_id_organizations_id_fk", + "tableFrom": "price_request_lines", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "price_request_lines_request_id_price_requests_id_fk": { + "name": "price_request_lines_request_id_price_requests_id_fk", + "tableFrom": "price_request_lines", + "tableTo": "price_requests", + "columnsFrom": [ + "request_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "price_request_lines_item_id_purchase_items_id_fk": { + "name": "price_request_lines_item_id_purchase_items_id_fk", + "tableFrom": "price_request_lines", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "price_request_lines_amount_ck": { + "name": "price_request_lines_amount_ck", + "value": "\"price_request_lines\".\"amount\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.price_request_offers": { + "name": "price_request_offers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "request_supplier_id": { + "name": "request_supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "line_id": { + "name": "line_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "unit_price_ht": { + "name": "unit_price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": false + }, + "awarded": { + "name": "awarded", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "price_request_offers_uq": { + "name": "price_request_offers_uq", + "columns": [ + { + "expression": "request_supplier_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "line_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "price_request_offers_organization_id_organizations_id_fk": { + "name": "price_request_offers_organization_id_organizations_id_fk", + "tableFrom": "price_request_offers", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "price_request_offers_request_supplier_id_price_request_suppliers_id_fk": { + "name": "price_request_offers_request_supplier_id_price_request_suppliers_id_fk", + "tableFrom": "price_request_offers", + "tableTo": "price_request_suppliers", + "columnsFrom": [ + "request_supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "price_request_offers_line_id_price_request_lines_id_fk": { + "name": "price_request_offers_line_id_price_request_lines_id_fk", + "tableFrom": "price_request_offers", + "tableTo": "price_request_lines", + "columnsFrom": [ + "line_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "price_request_offers_price_ck": { + "name": "price_request_offers_price_ck", + "value": "\"price_request_offers\".\"unit_price_ht\" IS NULL OR \"price_request_offers\".\"unit_price_ht\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.price_request_suppliers": { + "name": "price_request_suppliers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "emailed": { + "name": "emailed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "answered_at": { + "name": "answered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "answered_via": { + "name": "answered_via", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "answered_name": { + "name": "answered_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "answer_note": { + "name": "answer_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "price_request_suppliers_uq": { + "name": "price_request_suppliers_uq", + "columns": [ + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "supplier_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "price_request_suppliers_token_uq": { + "name": "price_request_suppliers_token_uq", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "price_request_suppliers_organization_id_organizations_id_fk": { + "name": "price_request_suppliers_organization_id_organizations_id_fk", + "tableFrom": "price_request_suppliers", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "price_request_suppliers_request_id_price_requests_id_fk": { + "name": "price_request_suppliers_request_id_price_requests_id_fk", + "tableFrom": "price_request_suppliers", + "tableTo": "price_requests", + "columnsFrom": [ + "request_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "price_request_suppliers_supplier_id_suppliers_id_fk": { + "name": "price_request_suppliers_supplier_id_suppliers_id_fk", + "tableFrom": "price_request_suppliers", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "price_request_suppliers_via_ck": { + "name": "price_request_suppliers_via_ck", + "value": "\"price_request_suppliers\".\"answered_via\" IS NULL OR \"price_request_suppliers\".\"answered_via\" IN ('en_ligne', 'saisie')" + } + }, + "isRLSEnabled": false + }, + "public.price_requests": { + "name": "price_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reply_by": { + "name": "reply_by", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "needed_by": { + "name": "needed_by", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'brouillon'" + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "awarded_at": { + "name": "awarded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "price_requests_number_uq": { + "name": "price_requests_number_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "price_requests_est_idx": { + "name": "price_requests_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "price_requests_organization_id_organizations_id_fk": { + "name": "price_requests_organization_id_organizations_id_fk", + "tableFrom": "price_requests", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "price_requests_establishment_id_establishments_id_fk": { + "name": "price_requests_establishment_id_establishments_id_fk", + "tableFrom": "price_requests", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "price_requests_created_by_users_id_fk": { + "name": "price_requests_created_by_users_id_fk", + "tableFrom": "price_requests", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "price_requests_status_ck": { + "name": "price_requests_status_ck", + "value": "\"price_requests\".\"status\" IN ('brouillon', 'envoyee', 'attribuee', 'annulee')" + } + }, + "isRLSEnabled": false + }, + "public.privacy_requests": { + "name": "privacy_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subject_kind": { + "name": "subject_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "customer_id": { + "name": "customer_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subject_label": { + "name": "subject_label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_type": { + "name": "request_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "received_on": { + "name": "received_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "target_on": { + "name": "target_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'recue'" + }, + "responded_on": { + "name": "responded_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "handled_by": { + "name": "handled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "privacy_requests_org_idx": { + "name": "privacy_requests_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "received_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "privacy_requests_organization_id_organizations_id_fk": { + "name": "privacy_requests_organization_id_organizations_id_fk", + "tableFrom": "privacy_requests", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "privacy_requests_establishment_id_establishments_id_fk": { + "name": "privacy_requests_establishment_id_establishments_id_fk", + "tableFrom": "privacy_requests", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "privacy_requests_employee_id_employees_id_fk": { + "name": "privacy_requests_employee_id_employees_id_fk", + "tableFrom": "privacy_requests", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "privacy_requests_customer_id_customers_id_fk": { + "name": "privacy_requests_customer_id_customers_id_fk", + "tableFrom": "privacy_requests", + "tableTo": "customers", + "columnsFrom": [ + "customer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "privacy_requests_handled_by_users_id_fk": { + "name": "privacy_requests_handled_by_users_id_fk", + "tableFrom": "privacy_requests", + "tableTo": "users", + "columnsFrom": [ + "handled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "privacy_requests_created_by_users_id_fk": { + "name": "privacy_requests_created_by_users_id_fk", + "tableFrom": "privacy_requests", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "privacy_requests_kind_ck": { + "name": "privacy_requests_kind_ck", + "value": "\"privacy_requests\".\"subject_kind\" IN ('salarie', 'client', 'autre')" + }, + "privacy_requests_type_ck": { + "name": "privacy_requests_type_ck", + "value": "\"privacy_requests\".\"request_type\" IN ('acces', 'rectification', 'effacement', 'opposition')" + }, + "privacy_requests_channel_ck": { + "name": "privacy_requests_channel_ck", + "value": "\"privacy_requests\".\"channel\" IN ('email', 'courrier', 'oral', 'sur_place', 'autre')" + }, + "privacy_requests_status_ck": { + "name": "privacy_requests_status_ck", + "value": "\"privacy_requests\".\"status\" IN ('recue', 'en_cours', 'traitee', 'refusee', 'sans_suite')" + }, + "privacy_requests_done_ck": { + "name": "privacy_requests_done_ck", + "value": "\"privacy_requests\".\"status\" NOT IN ('traitee', 'refusee') OR \"privacy_requests\".\"responded_on\" IS NOT NULL" + }, + "privacy_requests_refused_ck": { + "name": "privacy_requests_refused_ck", + "value": "\"privacy_requests\".\"status\" <> 'refusee' OR \"privacy_requests\".\"outcome\" IS NOT NULL" + }, + "privacy_requests_dates_ck": { + "name": "privacy_requests_dates_ck", + "value": "\"privacy_requests\".\"responded_on\" IS NULL OR \"privacy_requests\".\"responded_on\" >= \"privacy_requests\".\"received_on\"" + } + }, + "isRLSEnabled": false + }, + "public.product_recalls": { + "name": "product_recalls", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source_id": { + "name": "source_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "fiche_number": { + "name": "fiche_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "brand": { + "name": "brand", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "subcategory": { + "name": "subcategory", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "references": { + "name": "references", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "gtins": { + "name": "gtins", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "lots": { + "name": "lots", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "risks": { + "name": "risks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "consumer_actions": { + "name": "consumer_actions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sale_area": { + "name": "sale_area", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "distributors": { + "name": "distributors", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fiche_url": { + "name": "fiche_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "image_url": { + "name": "image_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ends_on": { + "name": "ends_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "fetched_at": { + "name": "fetched_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "product_recalls_source_uq": { + "name": "product_recalls_source_uq", + "columns": [ + { + "expression": "source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "product_recalls_published_idx": { + "name": "product_recalls_published_idx", + "columns": [ + { + "expression": "published_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.product_temperatures": { + "name": "product_temperatures", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "product_label": { + "name": "product_label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "start_at": { + "name": "start_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "start_temp": { + "name": "start_temp", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": true + }, + "end_at": { + "name": "end_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "end_temp": { + "name": "end_temp", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "conform": { + "name": "conform", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "corrective_action": { + "name": "corrective_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "completed_by": { + "name": "completed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "product_temperatures_est_idx": { + "name": "product_temperatures_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "start_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "product_temperatures_organization_id_organizations_id_fk": { + "name": "product_temperatures_organization_id_organizations_id_fk", + "tableFrom": "product_temperatures", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "product_temperatures_establishment_id_establishments_id_fk": { + "name": "product_temperatures_establishment_id_establishments_id_fk", + "tableFrom": "product_temperatures", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "product_temperatures_recorded_by_users_id_fk": { + "name": "product_temperatures_recorded_by_users_id_fk", + "tableFrom": "product_temperatures", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "product_temperatures_completed_by_users_id_fk": { + "name": "product_temperatures_completed_by_users_id_fk", + "tableFrom": "product_temperatures", + "tableTo": "users", + "columnsFrom": [ + "completed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "product_temperatures_cancelled_by_users_id_fk": { + "name": "product_temperatures_cancelled_by_users_id_fk", + "tableFrom": "product_temperatures", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "product_temperatures_kind_ck": { + "name": "product_temperatures_kind_ck", + "value": "\"product_temperatures\".\"kind\" IN ('refroidissement', 'remise_en_temperature', 'coeur_chaud', 'coeur_froid')" + }, + "product_temperatures_status_ck": { + "name": "product_temperatures_status_ck", + "value": "\"product_temperatures\".\"status\" IN ('en_cours', 'termine')" + }, + "product_temperatures_action_ck": { + "name": "product_temperatures_action_ck", + "value": "\"product_temperatures\".\"conform\" IS NOT FALSE OR \"product_temperatures\".\"corrective_action\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.purchase_control_settings": { + "name": "purchase_control_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "rise_threshold_pct": { + "name": "rise_threshold_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "rise_window_days": { + "name": "rise_window_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "reception_tolerance_pct": { + "name": "reception_tolerance_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "purchase_control_settings_org_uq": { + "name": "purchase_control_settings_org_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"purchase_control_settings\".\"establishment_id\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_control_settings_est_uq": { + "name": "purchase_control_settings_est_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"purchase_control_settings\".\"establishment_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "purchase_control_settings_organization_id_organizations_id_fk": { + "name": "purchase_control_settings_organization_id_organizations_id_fk", + "tableFrom": "purchase_control_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_control_settings_establishment_id_establishments_id_fk": { + "name": "purchase_control_settings_establishment_id_establishments_id_fk", + "tableFrom": "purchase_control_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_control_settings_updated_by_users_id_fk": { + "name": "purchase_control_settings_updated_by_users_id_fk", + "tableFrom": "purchase_control_settings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "purchase_control_settings_ck": { + "name": "purchase_control_settings_ck", + "value": "(\"purchase_control_settings\".\"rise_threshold_pct\" IS NULL OR (\"purchase_control_settings\".\"rise_threshold_pct\" > 0 AND \"purchase_control_settings\".\"rise_threshold_pct\" <= 100)) AND (\"purchase_control_settings\".\"rise_window_days\" IS NULL OR \"purchase_control_settings\".\"rise_window_days\" BETWEEN 7 AND 365) AND (\"purchase_control_settings\".\"reception_tolerance_pct\" IS NULL OR (\"purchase_control_settings\".\"reception_tolerance_pct\" >= 0 AND \"purchase_control_settings\".\"reception_tolerance_pct\" <= 50))" + } + }, + "isRLSEnabled": false + }, + "public.purchase_invoice_lines": { + "name": "purchase_invoice_lines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "invoice_id": { + "name": "invoice_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unit_price_ht": { + "name": "unit_price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": true + }, + "vat_rate": { + "name": "vat_rate", + "type": "numeric(6, 4)", + "primaryKey": false, + "notNull": true + }, + "line_ht": { + "name": "line_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "purchase_lines_invoice_idx": { + "name": "purchase_lines_invoice_idx", + "columns": [ + { + "expression": "invoice_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_lines_item_idx": { + "name": "purchase_lines_item_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "purchase_invoice_lines_organization_id_organizations_id_fk": { + "name": "purchase_invoice_lines_organization_id_organizations_id_fk", + "tableFrom": "purchase_invoice_lines", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_invoice_lines_invoice_id_purchase_invoices_id_fk": { + "name": "purchase_invoice_lines_invoice_id_purchase_invoices_id_fk", + "tableFrom": "purchase_invoice_lines", + "tableTo": "purchase_invoices", + "columnsFrom": [ + "invoice_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_invoice_lines_item_id_purchase_items_id_fk": { + "name": "purchase_invoice_lines_item_id_purchase_items_id_fk", + "tableFrom": "purchase_invoice_lines", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "purchase_lines_qty_ck": { + "name": "purchase_lines_qty_ck", + "value": "\"purchase_invoice_lines\".\"quantity\" > 0" + }, + "purchase_lines_price_ck": { + "name": "purchase_lines_price_ck", + "value": "\"purchase_invoice_lines\".\"unit_price_ht\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.purchase_invoices": { + "name": "purchase_invoices", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "invoice_number": { + "name": "invoice_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'invoice'" + }, + "invoice_date": { + "name": "invoice_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "total_ht": { + "name": "total_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "total_vat": { + "name": "total_vat", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "total_ttc": { + "name": "total_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "printed_ttc": { + "name": "printed_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "purchase_order_id": { + "name": "purchase_order_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "credit_request_id": { + "name": "credit_request_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "data_status": { + "name": "data_status", + "type": "data_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'real_unvalidated'" + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "paid_at": { + "name": "paid_at", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancellation_reason": { + "name": "cancellation_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "purchase_invoices_period_idx": { + "name": "purchase_invoices_period_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "invoice_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_invoices_number_uq": { + "name": "purchase_invoices_number_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "supplier_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"invoice_number\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"purchase_invoices\".\"cancelled_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_invoices_credit_request_uq": { + "name": "purchase_invoices_credit_request_uq", + "columns": [ + { + "expression": "credit_request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"purchase_invoices\".\"cancelled_at\" IS NULL AND \"purchase_invoices\".\"credit_request_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_invoices_order_uq": { + "name": "purchase_invoices_order_uq", + "columns": [ + { + "expression": "purchase_order_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"purchase_invoices\".\"cancelled_at\" IS NULL AND \"purchase_invoices\".\"kind\" = 'invoice' AND \"purchase_invoices\".\"purchase_order_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "purchase_invoices_organization_id_organizations_id_fk": { + "name": "purchase_invoices_organization_id_organizations_id_fk", + "tableFrom": "purchase_invoices", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_invoices_establishment_id_establishments_id_fk": { + "name": "purchase_invoices_establishment_id_establishments_id_fk", + "tableFrom": "purchase_invoices", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "purchase_invoices_supplier_id_suppliers_id_fk": { + "name": "purchase_invoices_supplier_id_suppliers_id_fk", + "tableFrom": "purchase_invoices", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "purchase_invoices_purchase_order_id_purchase_orders_id_fk": { + "name": "purchase_invoices_purchase_order_id_purchase_orders_id_fk", + "tableFrom": "purchase_invoices", + "tableTo": "purchase_orders", + "columnsFrom": [ + "purchase_order_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "purchase_invoices_credit_request_id_credit_requests_id_fk": { + "name": "purchase_invoices_credit_request_id_credit_requests_id_fk", + "tableFrom": "purchase_invoices", + "tableTo": "credit_requests", + "columnsFrom": [ + "credit_request_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "purchase_invoices_created_by_users_id_fk": { + "name": "purchase_invoices_created_by_users_id_fk", + "tableFrom": "purchase_invoices", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "purchase_invoices_cancelled_by_users_id_fk": { + "name": "purchase_invoices_cancelled_by_users_id_fk", + "tableFrom": "purchase_invoices", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "purchase_invoices_kind_ck": { + "name": "purchase_invoices_kind_ck", + "value": "\"purchase_invoices\".\"kind\" IN ('invoice', 'credit_note')" + }, + "purchase_invoices_ttc_ck": { + "name": "purchase_invoices_ttc_ck", + "value": "\"purchase_invoices\".\"total_ttc\" = \"purchase_invoices\".\"total_ht\" + \"purchase_invoices\".\"total_vat\"" + }, + "purchase_invoices_due_ck": { + "name": "purchase_invoices_due_ck", + "value": "\"purchase_invoices\".\"due_date\" IS NULL OR \"purchase_invoices\".\"due_date\" >= \"purchase_invoices\".\"invoice_date\"" + } + }, + "isRLSEnabled": false + }, + "public.purchase_items": { + "name": "purchase_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "family": { + "name": "family", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "storage_zone": { + "name": "storage_zone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pack_label": { + "name": "pack_label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pack_size": { + "name": "pack_size", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "default_supplier_id": { + "name": "default_supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "supplier_ref": { + "name": "supplier_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "barcode": { + "name": "barcode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "catalog_price_ht": { + "name": "catalog_price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": false + }, + "catalog_price_date": { + "name": "catalog_price_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "allergens": { + "name": "allergens", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "allergen_traces": { + "name": "allergen_traces", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "purchase_items_org_idx": { + "name": "purchase_items_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_items_org_name_unit_uq": { + "name": "purchase_items_org_name_unit_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "unit", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_items_org_barcode_uq": { + "name": "purchase_items_org_barcode_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "barcode", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"purchase_items\".\"barcode\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "purchase_items_organization_id_organizations_id_fk": { + "name": "purchase_items_organization_id_organizations_id_fk", + "tableFrom": "purchase_items", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_items_default_supplier_id_suppliers_id_fk": { + "name": "purchase_items_default_supplier_id_suppliers_id_fk", + "tableFrom": "purchase_items", + "tableTo": "suppliers", + "columnsFrom": [ + "default_supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "purchase_items_pack_ck": { + "name": "purchase_items_pack_ck", + "value": "\"purchase_items\".\"pack_size\" IS NULL OR \"purchase_items\".\"pack_size\" > 0" + }, + "purchase_items_catalog_ck": { + "name": "purchase_items_catalog_ck", + "value": "\"purchase_items\".\"catalog_price_ht\" IS NULL OR \"purchase_items\".\"catalog_price_ht\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.purchase_order_groups": { + "name": "purchase_order_groups", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expected_date": { + "name": "expected_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "purchase_order_groups_number_uq": { + "name": "purchase_order_groups_number_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "purchase_order_groups_organization_id_organizations_id_fk": { + "name": "purchase_order_groups_organization_id_organizations_id_fk", + "tableFrom": "purchase_order_groups", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_order_groups_supplier_id_suppliers_id_fk": { + "name": "purchase_order_groups_supplier_id_suppliers_id_fk", + "tableFrom": "purchase_order_groups", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "purchase_order_groups_created_by_users_id_fk": { + "name": "purchase_order_groups_created_by_users_id_fk", + "tableFrom": "purchase_order_groups", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "purchase_order_groups_status_ck": { + "name": "purchase_order_groups_status_ck", + "value": "\"purchase_order_groups\".\"status\" IN ('draft', 'sent', 'cancelled')" + } + }, + "isRLSEnabled": false + }, + "public.purchase_order_lines": { + "name": "purchase_order_lines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "order_id": { + "name": "order_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "packs": { + "name": "packs", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "pack_size": { + "name": "pack_size", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "pack_label": { + "name": "pack_label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "unit_price_ht": { + "name": "unit_price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": true + }, + "line_ht": { + "name": "line_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "received_quantity": { + "name": "received_quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "received_unit_price_ht": { + "name": "received_unit_price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": false + }, + "received_line_ht": { + "name": "received_line_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "reception_note": { + "name": "reception_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "purchase_order_lines_order_idx": { + "name": "purchase_order_lines_order_idx", + "columns": [ + { + "expression": "order_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_order_lines_item_uq": { + "name": "purchase_order_lines_item_uq", + "columns": [ + { + "expression": "order_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "purchase_order_lines_organization_id_organizations_id_fk": { + "name": "purchase_order_lines_organization_id_organizations_id_fk", + "tableFrom": "purchase_order_lines", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_order_lines_order_id_purchase_orders_id_fk": { + "name": "purchase_order_lines_order_id_purchase_orders_id_fk", + "tableFrom": "purchase_order_lines", + "tableTo": "purchase_orders", + "columnsFrom": [ + "order_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_order_lines_item_id_purchase_items_id_fk": { + "name": "purchase_order_lines_item_id_purchase_items_id_fk", + "tableFrom": "purchase_order_lines", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "purchase_order_lines_qty_ck": { + "name": "purchase_order_lines_qty_ck", + "value": "\"purchase_order_lines\".\"quantity\" > 0 AND \"purchase_order_lines\".\"unit_price_ht\" >= 0 AND (\"purchase_order_lines\".\"received_quantity\" IS NULL OR \"purchase_order_lines\".\"received_quantity\" >= 0)" + } + }, + "isRLSEnabled": false + }, + "public.purchase_orders": { + "name": "purchase_orders", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "expected_date": { + "name": "expected_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lines_ht": { + "name": "lines_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "delivery_fee_ht": { + "name": "delivery_fee_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "total_ht": { + "name": "total_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "ordered_at": { + "name": "ordered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "received_date": { + "name": "received_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "received_time": { + "name": "received_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_note_number": { + "name": "delivery_note_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "supplier_gaps_ack_at": { + "name": "supplier_gaps_ack_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "supplier_gaps_ack_by": { + "name": "supplier_gaps_ack_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "received_ht": { + "name": "received_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "reception_comment": { + "name": "reception_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "received_by": { + "name": "received_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "price_request_id": { + "name": "price_request_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "group_id": { + "name": "group_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "purchase_orders_group_idx": { + "name": "purchase_orders_group_idx", + "columns": [ + { + "expression": "group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_orders_est_idx": { + "name": "purchase_orders_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "purchase_orders_number_uq": { + "name": "purchase_orders_number_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "purchase_orders_organization_id_organizations_id_fk": { + "name": "purchase_orders_organization_id_organizations_id_fk", + "tableFrom": "purchase_orders", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "purchase_orders_establishment_id_establishments_id_fk": { + "name": "purchase_orders_establishment_id_establishments_id_fk", + "tableFrom": "purchase_orders", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "purchase_orders_supplier_id_suppliers_id_fk": { + "name": "purchase_orders_supplier_id_suppliers_id_fk", + "tableFrom": "purchase_orders", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "purchase_orders_supplier_gaps_ack_by_users_id_fk": { + "name": "purchase_orders_supplier_gaps_ack_by_users_id_fk", + "tableFrom": "purchase_orders", + "tableTo": "users", + "columnsFrom": [ + "supplier_gaps_ack_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "purchase_orders_received_by_users_id_fk": { + "name": "purchase_orders_received_by_users_id_fk", + "tableFrom": "purchase_orders", + "tableTo": "users", + "columnsFrom": [ + "received_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "purchase_orders_price_request_id_price_requests_id_fk": { + "name": "purchase_orders_price_request_id_price_requests_id_fk", + "tableFrom": "purchase_orders", + "tableTo": "price_requests", + "columnsFrom": [ + "price_request_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "purchase_orders_group_id_purchase_order_groups_id_fk": { + "name": "purchase_orders_group_id_purchase_order_groups_id_fk", + "tableFrom": "purchase_orders", + "tableTo": "purchase_order_groups", + "columnsFrom": [ + "group_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "purchase_orders_created_by_users_id_fk": { + "name": "purchase_orders_created_by_users_id_fk", + "tableFrom": "purchase_orders", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "purchase_orders_status_ck": { + "name": "purchase_orders_status_ck", + "value": "\"purchase_orders\".\"status\" IN ('draft', 'sent', 'confirmed', 'received', 'cancelled')" + }, + "purchase_orders_time_ck": { + "name": "purchase_orders_time_ck", + "value": "\"purchase_orders\".\"received_time\" IS NULL OR \"purchase_orders\".\"received_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$'" + } + }, + "isRLSEnabled": false + }, + "public.push_subscriptions": { + "name": "push_subscriptions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "p256dh": { + "name": "p256dh", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth": { + "name": "auth", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'Appareil'" + }, + "last_success_at": { + "name": "last_success_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "push_subscriptions_endpoint_uq": { + "name": "push_subscriptions_endpoint_uq", + "columns": [ + { + "expression": "endpoint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "push_subscriptions_user_idx": { + "name": "push_subscriptions_user_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "push_subscriptions_organization_id_organizations_id_fk": { + "name": "push_subscriptions_organization_id_organizations_id_fk", + "tableFrom": "push_subscriptions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "push_subscriptions_user_id_users_id_fk": { + "name": "push_subscriptions_user_id_users_id_fk", + "tableFrom": "push_subscriptions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.quotes": { + "name": "quotes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_kind": { + "name": "event_kind", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "event_date": { + "name": "event_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "event_time": { + "name": "event_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "guests": { + "name": "guests", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "customer_id": { + "name": "customer_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "client_name": { + "name": "client_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_company": { + "name": "client_company", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "client_email": { + "name": "client_email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "client_phone": { + "name": "client_phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "client_address": { + "name": "client_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'brouillon'" + }, + "issued_on": { + "name": "issued_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "valid_until": { + "name": "valid_until", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "lines": { + "name": "lines", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "total_ht": { + "name": "total_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "total_vat": { + "name": "total_vat", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "total_ttc": { + "name": "total_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "deposit_percent": { + "name": "deposit_percent", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "deposit_amount": { + "name": "deposit_amount", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "deposit_received_on": { + "name": "deposit_received_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "terms": { + "name": "terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "viewed_at": { + "name": "viewed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "accepted_name": { + "name": "accepted_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "accepted_via": { + "name": "accepted_via", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "accepted_meta": { + "name": "accepted_meta", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "refused_reason": { + "name": "refused_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reservation_id": { + "name": "reservation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lead_id": { + "name": "lead_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "quotes_number_uq": { + "name": "quotes_number_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "quotes_token_uq": { + "name": "quotes_token_uq", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"quotes\".\"token_hash\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "quotes_org_idx": { + "name": "quotes_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "quotes_organization_id_organizations_id_fk": { + "name": "quotes_organization_id_organizations_id_fk", + "tableFrom": "quotes", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "quotes_establishment_id_establishments_id_fk": { + "name": "quotes_establishment_id_establishments_id_fk", + "tableFrom": "quotes", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "quotes_customer_id_customers_id_fk": { + "name": "quotes_customer_id_customers_id_fk", + "tableFrom": "quotes", + "tableTo": "customers", + "columnsFrom": [ + "customer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "quotes_reservation_id_reservations_id_fk": { + "name": "quotes_reservation_id_reservations_id_fk", + "tableFrom": "quotes", + "tableTo": "reservations", + "columnsFrom": [ + "reservation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "quotes_lead_id_leads_id_fk": { + "name": "quotes_lead_id_leads_id_fk", + "tableFrom": "quotes", + "tableTo": "leads", + "columnsFrom": [ + "lead_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "quotes_created_by_users_id_fk": { + "name": "quotes_created_by_users_id_fk", + "tableFrom": "quotes", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "quotes_status_ck": { + "name": "quotes_status_ck", + "value": "\"quotes\".\"status\" IN ('brouillon', 'envoye', 'accepte', 'refuse', 'annule')" + }, + "quotes_valid_ck": { + "name": "quotes_valid_ck", + "value": "\"quotes\".\"valid_until\" >= \"quotes\".\"issued_on\"" + }, + "quotes_guests_ck": { + "name": "quotes_guests_ck", + "value": "\"quotes\".\"guests\" IS NULL OR \"quotes\".\"guests\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.reception_control_lines": { + "name": "reception_control_lines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "control_id": { + "name": "control_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "temperature": { + "name": "temperature", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "temp_max": { + "name": "temp_max", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "dlc": { + "name": "dlc", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "lot_number": { + "name": "lot_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "stock_lot_id": { + "name": "stock_lot_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "packaging_ok": { + "name": "packaging_ok", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "label_ok": { + "name": "label_ok", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "conform": { + "name": "conform", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "reception_control_lines_ctl_idx": { + "name": "reception_control_lines_ctl_idx", + "columns": [ + { + "expression": "control_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reception_control_lines_organization_id_organizations_id_fk": { + "name": "reception_control_lines_organization_id_organizations_id_fk", + "tableFrom": "reception_control_lines", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reception_control_lines_control_id_reception_controls_id_fk": { + "name": "reception_control_lines_control_id_reception_controls_id_fk", + "tableFrom": "reception_control_lines", + "tableTo": "reception_controls", + "columnsFrom": [ + "control_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reception_control_lines_item_id_purchase_items_id_fk": { + "name": "reception_control_lines_item_id_purchase_items_id_fk", + "tableFrom": "reception_control_lines", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "reception_control_lines_stock_lot_id_stock_expiry_lots_id_fk": { + "name": "reception_control_lines_stock_lot_id_stock_expiry_lots_id_fk", + "tableFrom": "reception_control_lines", + "tableTo": "stock_expiry_lots", + "columnsFrom": [ + "stock_lot_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.reception_controls": { + "name": "reception_controls", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "supplier_name": { + "name": "supplier_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "purchase_order_id": { + "name": "purchase_order_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "received_at": { + "name": "received_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "delivery_note": { + "name": "delivery_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "truck_temperature": { + "name": "truck_temperature", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "vehicle_clean": { + "name": "vehicle_clean", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "conform": { + "name": "conform", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "decision": { + "name": "decision", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "corrective_action": { + "name": "corrective_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reception_controls_est_idx": { + "name": "reception_controls_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "received_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reception_controls_organization_id_organizations_id_fk": { + "name": "reception_controls_organization_id_organizations_id_fk", + "tableFrom": "reception_controls", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reception_controls_establishment_id_establishments_id_fk": { + "name": "reception_controls_establishment_id_establishments_id_fk", + "tableFrom": "reception_controls", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "reception_controls_supplier_id_suppliers_id_fk": { + "name": "reception_controls_supplier_id_suppliers_id_fk", + "tableFrom": "reception_controls", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "reception_controls_purchase_order_id_purchase_orders_id_fk": { + "name": "reception_controls_purchase_order_id_purchase_orders_id_fk", + "tableFrom": "reception_controls", + "tableTo": "purchase_orders", + "columnsFrom": [ + "purchase_order_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "reception_controls_recorded_by_users_id_fk": { + "name": "reception_controls_recorded_by_users_id_fk", + "tableFrom": "reception_controls", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "reception_controls_cancelled_by_users_id_fk": { + "name": "reception_controls_cancelled_by_users_id_fk", + "tableFrom": "reception_controls", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "reception_controls_decision_ck": { + "name": "reception_controls_decision_ck", + "value": "\"reception_controls\".\"decision\" IN ('accepte', 'accepte_reserve', 'refuse')" + }, + "reception_controls_action_ck": { + "name": "reception_controls_action_ck", + "value": "\"reception_controls\".\"conform\" OR \"reception_controls\".\"corrective_action\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.recipe_lines": { + "name": "recipe_lines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "recipe_id": { + "name": "recipe_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "sub_recipe_id": { + "name": "sub_recipe_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "waste_pct": { + "name": "waste_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "recipe_lines_recipe_idx": { + "name": "recipe_lines_recipe_idx", + "columns": [ + { + "expression": "recipe_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "recipe_lines_sub_idx": { + "name": "recipe_lines_sub_idx", + "columns": [ + { + "expression": "sub_recipe_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "recipe_lines_organization_id_organizations_id_fk": { + "name": "recipe_lines_organization_id_organizations_id_fk", + "tableFrom": "recipe_lines", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "recipe_lines_recipe_id_recipes_id_fk": { + "name": "recipe_lines_recipe_id_recipes_id_fk", + "tableFrom": "recipe_lines", + "tableTo": "recipes", + "columnsFrom": [ + "recipe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "recipe_lines_item_id_purchase_items_id_fk": { + "name": "recipe_lines_item_id_purchase_items_id_fk", + "tableFrom": "recipe_lines", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "recipe_lines_sub_recipe_id_recipes_id_fk": { + "name": "recipe_lines_sub_recipe_id_recipes_id_fk", + "tableFrom": "recipe_lines", + "tableTo": "recipes", + "columnsFrom": [ + "sub_recipe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "recipe_lines_waste_ck": { + "name": "recipe_lines_waste_ck", + "value": "\"recipe_lines\".\"waste_pct\" IS NULL OR (\"recipe_lines\".\"waste_pct\" >= 0 AND \"recipe_lines\".\"waste_pct\" < 100)" + }, + "recipe_lines_qty_ck": { + "name": "recipe_lines_qty_ck", + "value": "\"recipe_lines\".\"quantity\" > 0" + }, + "recipe_lines_source_ck": { + "name": "recipe_lines_source_ck", + "value": "(\"recipe_lines\".\"item_id\" IS NULL) <> (\"recipe_lines\".\"sub_recipe_id\" IS NULL)" + }, + "recipe_lines_self_ck": { + "name": "recipe_lines_self_ck", + "value": "\"recipe_lines\".\"sub_recipe_id\" IS NULL OR \"recipe_lines\".\"sub_recipe_id\" <> \"recipe_lines\".\"recipe_id\"" + } + }, + "isRLSEnabled": false + }, + "public.recipe_versions": { + "name": "recipe_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "recipe_id": { + "name": "recipe_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "effective_from": { + "name": "effective_from", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "portions": { + "name": "portions", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": true + }, + "yield_quantity": { + "name": "yield_quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "yield_unit": { + "name": "yield_unit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lines": { + "name": "lines", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "recipe_versions_no_uq": { + "name": "recipe_versions_no_uq", + "columns": [ + { + "expression": "recipe_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "recipe_versions_from_uq": { + "name": "recipe_versions_from_uq", + "columns": [ + { + "expression": "recipe_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "effective_from", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "recipe_versions_origin_uq": { + "name": "recipe_versions_origin_uq", + "columns": [ + { + "expression": "recipe_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"recipe_versions\".\"effective_from\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "recipe_versions_org_idx": { + "name": "recipe_versions_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "effective_from", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "recipe_versions_organization_id_organizations_id_fk": { + "name": "recipe_versions_organization_id_organizations_id_fk", + "tableFrom": "recipe_versions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "recipe_versions_recipe_id_recipes_id_fk": { + "name": "recipe_versions_recipe_id_recipes_id_fk", + "tableFrom": "recipe_versions", + "tableTo": "recipes", + "columnsFrom": [ + "recipe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "recipe_versions_created_by_users_id_fk": { + "name": "recipe_versions_created_by_users_id_fk", + "tableFrom": "recipe_versions", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "recipe_versions_ck": { + "name": "recipe_versions_ck", + "value": "\"recipe_versions\".\"version\" >= 1 AND \"recipe_versions\".\"portions\" > 0 AND ((\"recipe_versions\".\"version\" = 1) = (\"recipe_versions\".\"effective_from\" IS NULL))" + } + }, + "isRLSEnabled": false + }, + "public.recipes": { + "name": "recipes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "course": { + "name": "course", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'plat'" + }, + "portions": { + "name": "portions", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": true, + "default": "'1'" + }, + "selling_price_ttc": { + "name": "selling_price_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "vat_rate": { + "name": "vat_rate", + "type": "numeric(6, 4)", + "primaryKey": false, + "notNull": true, + "default": "'0.10'" + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "yield_quantity": { + "name": "yield_quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "yield_unit": { + "name": "yield_unit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "steps": { + "name": "steps", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "target_margin_pct": { + "name": "target_margin_pct", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "allergens": { + "name": "allergens", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "allergen_traces": { + "name": "allergen_traces", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "portion_weight_g": { + "name": "portion_weight_g", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "quality_tolerance_pct": { + "name": "quality_tolerance_pct", + "type": "smallint", + "primaryKey": false, + "notNull": false + }, + "plating_standard": { + "name": "plating_standard", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "recipes_org_idx": { + "name": "recipes_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "recipes_org_name_uq": { + "name": "recipes_org_name_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "recipes_organization_id_organizations_id_fk": { + "name": "recipes_organization_id_organizations_id_fk", + "tableFrom": "recipes", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "recipes_created_by_users_id_fk": { + "name": "recipes_created_by_users_id_fk", + "tableFrom": "recipes", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "recipes_portions_ck": { + "name": "recipes_portions_ck", + "value": "\"recipes\".\"portions\" > 0" + }, + "recipes_yield_ck": { + "name": "recipes_yield_ck", + "value": "(\"recipes\".\"yield_quantity\" IS NULL AND \"recipes\".\"yield_unit\" IS NULL) OR (\"recipes\".\"yield_quantity\" > 0 AND \"recipes\".\"yield_unit\" IS NOT NULL)" + }, + "recipes_margin_ck": { + "name": "recipes_margin_ck", + "value": "\"recipes\".\"target_margin_pct\" IS NULL OR (\"recipes\".\"target_margin_pct\" >= 0 AND \"recipes\".\"target_margin_pct\" < 100)" + }, + "recipes_quality_ck": { + "name": "recipes_quality_ck", + "value": "(\"recipes\".\"portion_weight_g\" IS NULL OR \"recipes\".\"portion_weight_g\" BETWEEN 1 AND 20000) AND (\"recipes\".\"quality_tolerance_pct\" IS NULL OR \"recipes\".\"quality_tolerance_pct\" BETWEEN 1 AND 50)" + } + }, + "isRLSEnabled": false + }, + "public.recovery_codes": { + "name": "recovery_codes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "code_hash": { + "name": "code_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "recovery_codes_user_idx": { + "name": "recovery_codes_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "recovery_codes_user_id_users_id_fk": { + "name": "recovery_codes_user_id_users_id_fk", + "tableFrom": "recovery_codes", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.register_entries": { + "name": "register_entries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "topic": { + "name": "topic", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "organism": { + "name": "organism", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "performed_on": { + "name": "performed_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "next_due_on": { + "name": "next_due_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "participants": { + "name": "participants", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "duration_minutes": { + "name": "duration_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "observations": { + "name": "observations", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "document_id": { + "name": "document_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'saisie'" + }, + "source_ref": { + "name": "source_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "register_entries_est_idx": { + "name": "register_entries_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "performed_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "register_entries_source_uq": { + "name": "register_entries_source_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_ref", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"register_entries\".\"source_ref\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "register_entries_organization_id_organizations_id_fk": { + "name": "register_entries_organization_id_organizations_id_fk", + "tableFrom": "register_entries", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "register_entries_establishment_id_establishments_id_fk": { + "name": "register_entries_establishment_id_establishments_id_fk", + "tableFrom": "register_entries", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "register_entries_employee_id_employees_id_fk": { + "name": "register_entries_employee_id_employees_id_fk", + "tableFrom": "register_entries", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "register_entries_supplier_id_suppliers_id_fk": { + "name": "register_entries_supplier_id_suppliers_id_fk", + "tableFrom": "register_entries", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "register_entries_document_id_business_documents_id_fk": { + "name": "register_entries_document_id_business_documents_id_fk", + "tableFrom": "register_entries", + "tableTo": "business_documents", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "register_entries_created_by_users_id_fk": { + "name": "register_entries_created_by_users_id_fk", + "tableFrom": "register_entries", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "register_entries_cancelled_by_users_id_fk": { + "name": "register_entries_cancelled_by_users_id_fk", + "tableFrom": "register_entries", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "register_entries_kind_ck": { + "name": "register_entries_kind_ck", + "value": "\"register_entries\".\"kind\" IN ('epi', 'exercice_incendie', 'controle', 'vigilance')" + }, + "register_entries_result_ck": { + "name": "register_entries_result_ck", + "value": "\"register_entries\".\"result\" IS NULL OR \"register_entries\".\"result\" IN ('conforme', 'reserves', 'non_conforme')" + }, + "register_entries_source_ck": { + "name": "register_entries_source_ck", + "value": "\"register_entries\".\"source\" IN ('saisie', 'document')" + }, + "register_entries_due_ck": { + "name": "register_entries_due_ck", + "value": "\"register_entries\".\"next_due_on\" IS NULL OR \"register_entries\".\"next_due_on\" >= \"register_entries\".\"performed_on\"" + }, + "register_entries_counts_ck": { + "name": "register_entries_counts_ck", + "value": "(\"register_entries\".\"quantity\" IS NULL OR \"register_entries\".\"quantity\" BETWEEN 1 AND 1000) AND (\"register_entries\".\"participants\" IS NULL OR \"register_entries\".\"participants\" BETWEEN 0 AND 10000) AND (\"register_entries\".\"duration_minutes\" IS NULL OR \"register_entries\".\"duration_minutes\" BETWEEN 1 AND 1440)" + }, + "register_entries_cancel_ck": { + "name": "register_entries_cancel_ck", + "value": "\"register_entries\".\"cancelled_at\" IS NULL OR (\"register_entries\".\"cancelled_by\" IS NOT NULL AND \"register_entries\".\"cancel_reason\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.regulatory_obligations": { + "name": "regulatory_obligations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "applicability": { + "name": "applicability", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "source_status": { + "name": "source_status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_reference": { + "name": "source_reference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_url": { + "name": "source_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference_origin": { + "name": "reference_origin", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "catalogued_on": { + "name": "catalogued_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "verified_at": { + "name": "verified_at", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "validation_status": { + "name": "validation_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'non_validee'" + }, + "validator_name": { + "name": "validator_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "validator_quality": { + "name": "validator_quality", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "validated_on": { + "name": "validated_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "legal_delay_text": { + "name": "legal_delay_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "hr_check": { + "name": "hr_check", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "regulatory_obligations_code_uq": { + "name": "regulatory_obligations_code_uq", + "columns": [ + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "regulatory_obligations_domain_ck": { + "name": "regulatory_obligations_domain_ck", + "value": "\"regulatory_obligations\".\"domain\" IN ('hygiene', 'social', 'securite', 'fiscal', 'affichage', 'licences', 'consommateurs', 'environnement', 'donnees_personnelles')" + }, + "regulatory_obligations_source_ck": { + "name": "regulatory_obligations_source_ck", + "value": "\"regulatory_obligations\".\"source_status\" IN ('documentee', 'a_documenter') AND (\"regulatory_obligations\".\"source_status\" = 'a_documenter' OR \"regulatory_obligations\".\"source_reference\" IS NOT NULL)" + }, + "regulatory_obligations_validation_ck": { + "name": "regulatory_obligations_validation_ck", + "value": "\"regulatory_obligations\".\"validation_status\" IN ('non_validee', 'validee_par_professionnel') AND (\"regulatory_obligations\".\"validation_status\" = 'non_validee' OR (\"regulatory_obligations\".\"validator_name\" IS NOT NULL AND \"regulatory_obligations\".\"validator_quality\" IS NOT NULL AND \"regulatory_obligations\".\"validated_on\" IS NOT NULL))" + }, + "regulatory_obligations_active_ck": { + "name": "regulatory_obligations_active_ck", + "value": "NOT \"regulatory_obligations\".\"active\" OR (\"regulatory_obligations\".\"validation_status\" = 'validee_par_professionnel' AND \"regulatory_obligations\".\"source_status\" = 'documentee' AND \"regulatory_obligations\".\"source_url\" IS NOT NULL AND \"regulatory_obligations\".\"verified_at\" IS NOT NULL)" + }, + "regulatory_obligations_hr_ck": { + "name": "regulatory_obligations_hr_ck", + "value": "\"regulatory_obligations\".\"hr_check\" IS NULL OR \"regulatory_obligations\".\"hr_check\" IN ('work_permit', 'medical_visit', 'dpae')" + } + }, + "isRLSEnabled": false + }, + "public.report_schedules": { + "name": "report_schedules", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "frequency": { + "name": "frequency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'gestion'" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'Rapport de gestion'" + }, + "send_time": { + "name": "send_time", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'07:00'" + }, + "weekdays": { + "name": "weekdays", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "attach_pdf": { + "name": "attach_pdf", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "notify_in_app": { + "name": "notify_in_app", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "recipients": { + "name": "recipients", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "last_period_from": { + "name": "last_period_from", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "last_sent_at": { + "name": "last_sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "indicators": { + "name": "indicators", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "audience": { + "name": "audience", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "send_condition": { + "name": "send_condition", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "report_schedules_org_idx": { + "name": "report_schedules_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "report_schedules_organization_id_organizations_id_fk": { + "name": "report_schedules_organization_id_organizations_id_fk", + "tableFrom": "report_schedules", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "report_schedules_establishment_id_establishments_id_fk": { + "name": "report_schedules_establishment_id_establishments_id_fk", + "tableFrom": "report_schedules", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "report_schedules_created_by_users_id_fk": { + "name": "report_schedules_created_by_users_id_fk", + "tableFrom": "report_schedules", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "report_schedules_audience_ck": { + "name": "report_schedules_audience_ck", + "value": "\"report_schedules\".\"audience\" IS NULL OR \"report_schedules\".\"audience\" IN ('proprietaire', 'direction', 'comptable', 'equipe', 'cuisine')" + }, + "report_schedules_freq_ck": { + "name": "report_schedules_freq_ck", + "value": "\"report_schedules\".\"frequency\" IN ('daily', 'weekly', 'monthly')" + }, + "report_schedules_time_ck": { + "name": "report_schedules_time_ck", + "value": "\"report_schedules\".\"send_time\" ~ '^(0[5-9]|1[0-9]|2[0-2]):(00|15|30|45)$'" + }, + "report_schedules_days_ck": { + "name": "report_schedules_days_ck", + "value": "\"report_schedules\".\"frequency\" <> 'daily' OR (CASE WHEN jsonb_typeof(\"report_schedules\".\"weekdays\") = 'array' THEN jsonb_array_length(\"report_schedules\".\"weekdays\") >= 1 ELSE false END)" + }, + "report_schedules_kind_ck": { + "name": "report_schedules_kind_ck", + "value": "\"report_schedules\".\"kind\" IN ('gestion', 'fermeture', 'groupe')" + }, + "report_schedules_closing_ck": { + "name": "report_schedules_closing_ck", + "value": "\"report_schedules\".\"kind\" <> 'fermeture' OR (\"report_schedules\".\"frequency\" = 'daily' AND \"report_schedules\".\"establishment_id\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.reputation_policies": { + "name": "reputation_policies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "levels": { + "name": "levels", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "tone": { + "name": "tone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "language": { + "name": "language", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "forbidden_words": { + "name": "forbidden_words", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "email_alerts": { + "name": "email_alerts", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "escalate_to": { + "name": "escalate_to", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reputation_policies_org_uq": { + "name": "reputation_policies_org_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"reputation_policies\".\"establishment_id\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "reputation_policies_est_uq": { + "name": "reputation_policies_est_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"reputation_policies\".\"establishment_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reputation_policies_organization_id_organizations_id_fk": { + "name": "reputation_policies_organization_id_organizations_id_fk", + "tableFrom": "reputation_policies", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reputation_policies_establishment_id_establishments_id_fk": { + "name": "reputation_policies_establishment_id_establishments_id_fk", + "tableFrom": "reputation_policies", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reputation_policies_escalate_to_users_id_fk": { + "name": "reputation_policies_escalate_to_users_id_fk", + "tableFrom": "reputation_policies", + "tableTo": "users", + "columnsFrom": [ + "escalate_to" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "reputation_policies_updated_by_users_id_fk": { + "name": "reputation_policies_updated_by_users_id_fk", + "tableFrom": "reputation_policies", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "reputation_policies_tone_ck": { + "name": "reputation_policies_tone_ck", + "value": "\"reputation_policies\".\"tone\" IS NULL OR \"reputation_policies\".\"tone\" IN ('formel', 'chaleureux', 'sobre')" + }, + "reputation_policies_lang_ck": { + "name": "reputation_policies_lang_ck", + "value": "\"reputation_policies\".\"language\" IS NULL OR \"reputation_policies\".\"language\" IN ('fr', 'en')" + } + }, + "isRLSEnabled": false + }, + "public.reputation_settings": { + "name": "reputation_settings", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "review_url": { + "name": "review_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "signature": { + "name": "signature", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "reputation_settings_establishment_id_establishments_id_fk": { + "name": "reputation_settings_establishment_id_establishments_id_fk", + "tableFrom": "reputation_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reputation_settings_organization_id_organizations_id_fk": { + "name": "reputation_settings_organization_id_organizations_id_fk", + "tableFrom": "reputation_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reputation_settings_updated_by_users_id_fk": { + "name": "reputation_settings_updated_by_users_id_fk", + "tableFrom": "reputation_settings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.reservation_exceptions": { + "name": "reservation_exceptions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "service_id": { + "name": "service_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "closed": { + "name": "closed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "service_capacity": { + "name": "service_capacity", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reservation_exceptions_day_idx": { + "name": "reservation_exceptions_day_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reservation_exceptions_organization_id_organizations_id_fk": { + "name": "reservation_exceptions_organization_id_organizations_id_fk", + "tableFrom": "reservation_exceptions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_exceptions_establishment_id_establishments_id_fk": { + "name": "reservation_exceptions_establishment_id_establishments_id_fk", + "tableFrom": "reservation_exceptions", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "reservation_exceptions_service_id_reservation_services_id_fk": { + "name": "reservation_exceptions_service_id_reservation_services_id_fk", + "tableFrom": "reservation_exceptions", + "tableTo": "reservation_services", + "columnsFrom": [ + "service_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_exceptions_created_by_users_id_fk": { + "name": "reservation_exceptions_created_by_users_id_fk", + "tableFrom": "reservation_exceptions", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "reservation_exceptions_cap_ck": { + "name": "reservation_exceptions_cap_ck", + "value": "\"reservation_exceptions\".\"closed\" OR \"reservation_exceptions\".\"service_capacity\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.reservation_services": { + "name": "reservation_services", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "weekdays": { + "name": "weekdays", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "first_time": { + "name": "first_time", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_time": { + "name": "last_time", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slot_minutes": { + "name": "slot_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 30 + }, + "slot_capacity": { + "name": "slot_capacity", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "service_capacity": { + "name": "service_capacity", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "duration_minutes": { + "name": "duration_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 120 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reservation_services_est_idx": { + "name": "reservation_services_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reservation_services_organization_id_organizations_id_fk": { + "name": "reservation_services_organization_id_organizations_id_fk", + "tableFrom": "reservation_services", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_services_establishment_id_establishments_id_fk": { + "name": "reservation_services_establishment_id_establishments_id_fk", + "tableFrom": "reservation_services", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "reservation_services_time_ck": { + "name": "reservation_services_time_ck", + "value": "\"reservation_services\".\"first_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"reservation_services\".\"last_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$'" + }, + "reservation_services_slot_ck": { + "name": "reservation_services_slot_ck", + "value": "\"reservation_services\".\"slot_minutes\" IN (15, 30, 60) AND \"reservation_services\".\"duration_minutes\" BETWEEN 15 AND 720" + }, + "reservation_services_cap_ck": { + "name": "reservation_services_cap_ck", + "value": "(\"reservation_services\".\"slot_capacity\" IS NULL OR \"reservation_services\".\"slot_capacity\" > 0) AND (\"reservation_services\".\"service_capacity\" IS NULL OR \"reservation_services\".\"service_capacity\" > 0)" + } + }, + "isRLSEnabled": false + }, + "public.reservation_settings": { + "name": "reservation_settings", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "reminder_email": { + "name": "reminder_email", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "reminder_hour": { + "name": "reminder_hour", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 10 + }, + "online_enabled": { + "name": "online_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "online_token": { + "name": "online_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "online_by": { + "name": "online_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "online_max_covers": { + "name": "online_max_covers", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 8 + }, + "waitlist_auto_offer": { + "name": "waitlist_auto_offer", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "online_auto_confirm": { + "name": "online_auto_confirm", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "online_lead_minutes": { + "name": "online_lead_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 120 + }, + "online_days": { + "name": "online_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 60 + }, + "online_message": { + "name": "online_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "online_groups": { + "name": "online_groups", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reservation_settings_online_token_uq": { + "name": "reservation_settings_online_token_uq", + "columns": [ + { + "expression": "online_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reservation_settings_establishment_id_establishments_id_fk": { + "name": "reservation_settings_establishment_id_establishments_id_fk", + "tableFrom": "reservation_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_settings_organization_id_organizations_id_fk": { + "name": "reservation_settings_organization_id_organizations_id_fk", + "tableFrom": "reservation_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_settings_online_by_users_id_fk": { + "name": "reservation_settings_online_by_users_id_fk", + "tableFrom": "reservation_settings", + "tableTo": "users", + "columnsFrom": [ + "online_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "reservation_settings_hour_ck": { + "name": "reservation_settings_hour_ck", + "value": "\"reservation_settings\".\"reminder_hour\" BETWEEN 7 AND 21" + }, + "reservation_settings_online_ck": { + "name": "reservation_settings_online_ck", + "value": "\"reservation_settings\".\"online_max_covers\" BETWEEN 1 AND 50 AND \"reservation_settings\".\"online_lead_minutes\" BETWEEN 0 AND 2880 AND \"reservation_settings\".\"online_days\" BETWEEN 1 AND 365" + } + }, + "isRLSEnabled": false + }, + "public.reservation_tables": { + "name": "reservation_tables", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "reservation_id": { + "name": "reservation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "table_id": { + "name": "table_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "starts_at": { + "name": "starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "released_at": { + "name": "released_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reservation_tables_res_idx": { + "name": "reservation_tables_res_idx", + "columns": [ + { + "expression": "reservation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reservation_tables_table_idx": { + "name": "reservation_tables_table_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "starts_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reservation_tables_organization_id_organizations_id_fk": { + "name": "reservation_tables_organization_id_organizations_id_fk", + "tableFrom": "reservation_tables", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_tables_establishment_id_establishments_id_fk": { + "name": "reservation_tables_establishment_id_establishments_id_fk", + "tableFrom": "reservation_tables", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "reservation_tables_reservation_id_reservations_id_fk": { + "name": "reservation_tables_reservation_id_reservations_id_fk", + "tableFrom": "reservation_tables", + "tableTo": "reservations", + "columnsFrom": [ + "reservation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_tables_table_id_floor_items_id_fk": { + "name": "reservation_tables_table_id_floor_items_id_fk", + "tableFrom": "reservation_tables", + "tableTo": "floor_items", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "reservation_tables_range_ck": { + "name": "reservation_tables_range_ck", + "value": "\"reservation_tables\".\"ends_at\" > \"reservation_tables\".\"starts_at\"" + } + }, + "isRLSEnabled": false + }, + "public.reservation_waitlist": { + "name": "reservation_waitlist", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "time_from": { + "name": "time_from", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "time_to": { + "name": "time_to", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "covers": { + "name": "covers", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en_attente'" + }, + "offered_at": { + "name": "offered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "offered_from_reservation_id": { + "name": "offered_from_reservation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "offered_time": { + "name": "offered_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reservation_id": { + "name": "reservation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "close_reason": { + "name": "close_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reservation_waitlist_day_idx": { + "name": "reservation_waitlist_day_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reservation_waitlist_organization_id_organizations_id_fk": { + "name": "reservation_waitlist_organization_id_organizations_id_fk", + "tableFrom": "reservation_waitlist", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_waitlist_establishment_id_establishments_id_fk": { + "name": "reservation_waitlist_establishment_id_establishments_id_fk", + "tableFrom": "reservation_waitlist", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_waitlist_offered_from_reservation_id_reservations_id_fk": { + "name": "reservation_waitlist_offered_from_reservation_id_reservations_id_fk", + "tableFrom": "reservation_waitlist", + "tableTo": "reservations", + "columnsFrom": [ + "offered_from_reservation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "reservation_waitlist_reservation_id_reservations_id_fk": { + "name": "reservation_waitlist_reservation_id_reservations_id_fk", + "tableFrom": "reservation_waitlist", + "tableTo": "reservations", + "columnsFrom": [ + "reservation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "reservation_waitlist_created_by_users_id_fk": { + "name": "reservation_waitlist_created_by_users_id_fk", + "tableFrom": "reservation_waitlist", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "reservation_waitlist_status_ck": { + "name": "reservation_waitlist_status_ck", + "value": "\"reservation_waitlist\".\"status\" IN ('en_attente', 'proposee', 'convertie', 'annulee')" + }, + "reservation_waitlist_covers_ck": { + "name": "reservation_waitlist_covers_ck", + "value": "\"reservation_waitlist\".\"covers\" BETWEEN 1 AND 500" + }, + "reservation_waitlist_time_ck": { + "name": "reservation_waitlist_time_ck", + "value": "\"reservation_waitlist\".\"time_from\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"reservation_waitlist\".\"time_to\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"reservation_waitlist\".\"time_to\" >= \"reservation_waitlist\".\"time_from\"" + }, + "reservation_waitlist_contact_ck": { + "name": "reservation_waitlist_contact_ck", + "value": "\"reservation_waitlist\".\"phone\" IS NOT NULL OR \"reservation_waitlist\".\"email\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.reservations": { + "name": "reservations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "service_id": { + "name": "service_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "customer_id": { + "name": "customer_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "time": { + "name": "time", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "starts_at": { + "name": "starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "covers": { + "name": "covers", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'confirmee'" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'telephone'" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request": { + "name": "request", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "internal_note": { + "name": "internal_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "arrived_at": { + "name": "arrived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "confirmation_sent_at": { + "name": "confirmation_sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "reminder_sent_at": { + "name": "reminder_sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "external_ref": { + "name": "external_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reservations_day_idx": { + "name": "reservations_day_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reservations_customer_idx": { + "name": "reservations_customer_idx", + "columns": [ + { + "expression": "customer_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reservations_external_ref_uq": { + "name": "reservations_external_ref_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_ref", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"reservations\".\"external_ref\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reservations_organization_id_organizations_id_fk": { + "name": "reservations_organization_id_organizations_id_fk", + "tableFrom": "reservations", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservations_establishment_id_establishments_id_fk": { + "name": "reservations_establishment_id_establishments_id_fk", + "tableFrom": "reservations", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "reservations_service_id_reservation_services_id_fk": { + "name": "reservations_service_id_reservation_services_id_fk", + "tableFrom": "reservations", + "tableTo": "reservation_services", + "columnsFrom": [ + "service_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "reservations_customer_id_customers_id_fk": { + "name": "reservations_customer_id_customers_id_fk", + "tableFrom": "reservations", + "tableTo": "customers", + "columnsFrom": [ + "customer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "reservations_created_by_users_id_fk": { + "name": "reservations_created_by_users_id_fk", + "tableFrom": "reservations", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "reservations_status_ck": { + "name": "reservations_status_ck", + "value": "\"reservations\".\"status\" IN ('en_attente', 'confirmee', 'arrivee', 'terminee', 'no_show', 'annulee')" + }, + "reservations_covers_ck": { + "name": "reservations_covers_ck", + "value": "\"reservations\".\"covers\" BETWEEN 1 AND 500" + }, + "reservations_time_ck": { + "name": "reservations_time_ck", + "value": "\"reservations\".\"time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"reservations\".\"ends_at\" > \"reservations\".\"starts_at\"" + } + }, + "isRLSEnabled": false + }, + "public.review_autopublish": { + "name": "review_autopublish", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "levels": { + "name": "levels", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "enabled_by": { + "name": "enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "enabled_at": { + "name": "enabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "confirmation": { + "name": "confirmation", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "paused_reason": { + "name": "paused_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "review_autopublish_establishment_id_establishments_id_fk": { + "name": "review_autopublish_establishment_id_establishments_id_fk", + "tableFrom": "review_autopublish", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "review_autopublish_organization_id_organizations_id_fk": { + "name": "review_autopublish_organization_id_organizations_id_fk", + "tableFrom": "review_autopublish", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "review_autopublish_enabled_by_users_id_fk": { + "name": "review_autopublish_enabled_by_users_id_fk", + "tableFrom": "review_autopublish", + "tableTo": "users", + "columnsFrom": [ + "enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "review_autopublish_updated_by_users_id_fk": { + "name": "review_autopublish_updated_by_users_id_fk", + "tableFrom": "review_autopublish", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.review_publications": { + "name": "review_publications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "review_id": { + "name": "review_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scheduled_for": { + "name": "scheduled_for", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "blocked_words": { + "name": "blocked_words", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "google_reply_state": { + "name": "google_reply_state", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "review_publications_review_uq": { + "name": "review_publications_review_uq", + "columns": [ + { + "expression": "review_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "review_publications_due_idx": { + "name": "review_publications_due_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_attempt_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "review_publications_organization_id_organizations_id_fk": { + "name": "review_publications_organization_id_organizations_id_fk", + "tableFrom": "review_publications", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "review_publications_establishment_id_establishments_id_fk": { + "name": "review_publications_establishment_id_establishments_id_fk", + "tableFrom": "review_publications", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "review_publications_review_id_reviews_id_fk": { + "name": "review_publications_review_id_reviews_id_fk", + "tableFrom": "review_publications", + "tableTo": "reviews", + "columnsFrom": [ + "review_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "review_publications_status_ck": { + "name": "review_publications_status_ck", + "value": "\"review_publications\".\"status\" IN ('scheduled', 'publishing', 'published', 'failed', 'blocked', 'cancelled', 'skipped')" + } + }, + "isRLSEnabled": false + }, + "public.reviews": { + "name": "reviews", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reviewed_on": { + "name": "reviewed_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "author": { + "name": "author", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fingerprint": { + "name": "fingerprint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reply_text": { + "name": "reply_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "replied_at": { + "name": "replied_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "replied_by": { + "name": "replied_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "internal_note": { + "name": "internal_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assigned_to": { + "name": "assigned_to", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "assigned_at": { + "name": "assigned_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "assigned_by": { + "name": "assigned_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "rule_action": { + "name": "rule_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "alerted_at": { + "name": "alerted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_name": { + "name": "external_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_updated_at": { + "name": "external_updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "reply_origin": { + "name": "reply_origin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reviews_fingerprint_uq": { + "name": "reviews_fingerprint_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "fingerprint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reviews_external_uq": { + "name": "reviews_external_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"reviews\".\"external_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "reviews_est_day_idx": { + "name": "reviews_est_day_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "reviewed_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reviews_assigned_idx": { + "name": "reviews_assigned_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "assigned_to", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"reviews\".\"assigned_to\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reviews_organization_id_organizations_id_fk": { + "name": "reviews_organization_id_organizations_id_fk", + "tableFrom": "reviews", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reviews_establishment_id_establishments_id_fk": { + "name": "reviews_establishment_id_establishments_id_fk", + "tableFrom": "reviews", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reviews_replied_by_users_id_fk": { + "name": "reviews_replied_by_users_id_fk", + "tableFrom": "reviews", + "tableTo": "users", + "columnsFrom": [ + "replied_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "reviews_assigned_to_users_id_fk": { + "name": "reviews_assigned_to_users_id_fk", + "tableFrom": "reviews", + "tableTo": "users", + "columnsFrom": [ + "assigned_to" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "reviews_assigned_by_users_id_fk": { + "name": "reviews_assigned_by_users_id_fk", + "tableFrom": "reviews", + "tableTo": "users", + "columnsFrom": [ + "assigned_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "reviews_created_by_users_id_fk": { + "name": "reviews_created_by_users_id_fk", + "tableFrom": "reviews", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "reviews_reply_origin_ck": { + "name": "reviews_reply_origin_ck", + "value": "\"reviews\".\"reply_origin\" IS NULL OR \"reviews\".\"reply_origin\" IN ('manuel', 'google', 'auto')" + }, + "reviews_rating_ck": { + "name": "reviews_rating_ck", + "value": "\"reviews\".\"rating\" BETWEEN 1 AND 5" + }, + "reviews_source_ck": { + "name": "reviews_source_ck", + "value": "\"reviews\".\"source\" IN ('google', 'tripadvisor', 'thefork', 'facebook', 'direct', 'autre')" + }, + "reviews_rule_action_ck": { + "name": "reviews_rule_action_ck", + "value": "\"reviews\".\"rule_action\" IS NULL OR \"reviews\".\"rule_action\" IN ('remercier', 'remercier_inviter', 'demander_retour', 'transmettre', 'alerte')" + } + }, + "isRLSEnabled": false + }, + "public.sales_challenges": { + "name": "sales_challenges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "preset": { + "name": "preset", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'perso'" + }, + "metric": { + "name": "metric", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "keywords": { + "name": "keywords", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "categories": { + "name": "categories", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "from_day": { + "name": "from_day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "to_day": { + "name": "to_day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "rewards": { + "name": "rewards", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "target_value": { + "name": "target_value", + "type": "numeric(14, 3)", + "primaryKey": false, + "notNull": false + }, + "results": { + "name": "results", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_challenges_org_idx": { + "name": "sales_challenges_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "to_day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_challenges_organization_id_organizations_id_fk": { + "name": "sales_challenges_organization_id_organizations_id_fk", + "tableFrom": "sales_challenges", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_challenges_establishment_id_establishments_id_fk": { + "name": "sales_challenges_establishment_id_establishments_id_fk", + "tableFrom": "sales_challenges", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_challenges_created_by_users_id_fk": { + "name": "sales_challenges_created_by_users_id_fk", + "tableFrom": "sales_challenges", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "sales_challenges_metric_ck": { + "name": "sales_challenges_metric_ck", + "value": "\"sales_challenges\".\"metric\" IN ('quantite', 'ca_ht', 'ca_heure')" + }, + "sales_challenges_range_ck": { + "name": "sales_challenges_range_ck", + "value": "\"sales_challenges\".\"to_day\" >= \"sales_challenges\".\"from_day\" AND \"sales_challenges\".\"to_day\" - \"sales_challenges\".\"from_day\" <= 366" + }, + "sales_challenges_target_ck": { + "name": "sales_challenges_target_ck", + "value": "\"sales_challenges\".\"target_value\" IS NULL OR \"sales_challenges\".\"target_value\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.sales_entries": { + "name": "sales_entries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "batch_id": { + "name": "batch_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "business_date": { + "name": "business_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "ticket_ref": { + "name": "ticket_ref", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "amount_ht": { + "name": "amount_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "vat_rate": { + "name": "vat_rate", + "type": "numeric(6, 4)", + "primaryKey": false, + "notNull": true + }, + "vat_amount": { + "name": "vat_amount", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "amount_ttc": { + "name": "amount_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "covers": { + "name": "covers", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "payment_method": { + "name": "payment_method", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "data_status": { + "name": "data_status", + "type": "data_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'real_unvalidated'" + }, + "row_hash": { + "name": "row_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "format_version": { + "name": "format_version", + "type": "smallint", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "line_ref": { + "name": "line_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sold_time": { + "name": "sold_time", + "type": "time", + "primaryKey": false, + "notNull": false + }, + "service": { + "name": "service", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "product": { + "name": "product", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 3)", + "primaryKey": false, + "notNull": false + }, + "server_name": { + "name": "server_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "table_label": { + "name": "table_label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "discount_ttc": { + "name": "discount_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "comp_ttc": { + "name": "comp_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "product_code": { + "name": "product_code", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "sales_entries_row_uq": { + "name": "sales_entries_row_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "row_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sales_entries_period_idx": { + "name": "sales_entries_period_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "business_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sales_entries_ticket_idx": { + "name": "sales_entries_ticket_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "business_date", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "ticket_ref", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_entries_organization_id_organizations_id_fk": { + "name": "sales_entries_organization_id_organizations_id_fk", + "tableFrom": "sales_entries", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_entries_establishment_id_establishments_id_fk": { + "name": "sales_entries_establishment_id_establishments_id_fk", + "tableFrom": "sales_entries", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "sales_entries_batch_id_sales_import_batches_id_fk": { + "name": "sales_entries_batch_id_sales_import_batches_id_fk", + "tableFrom": "sales_entries", + "tableTo": "sales_import_batches", + "columnsFrom": [ + "batch_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "sales_ttc_consistency_ck": { + "name": "sales_ttc_consistency_ck", + "value": "\"sales_entries\".\"amount_ttc\" = \"sales_entries\".\"amount_ht\" + \"sales_entries\".\"vat_amount\"" + }, + "sales_format_version_ck": { + "name": "sales_format_version_ck", + "value": "\"sales_entries\".\"format_version\" IN (1, 2)" + }, + "sales_channel_ck": { + "name": "sales_channel_ck", + "value": "\"sales_entries\".\"channel\" IS NULL OR \"sales_entries\".\"channel\" IN ('sur_place', 'emporter', 'livraison', 'click_collect', 'autre')" + }, + "sales_discount_ck": { + "name": "sales_discount_ck", + "value": "\"sales_entries\".\"discount_ttc\" IS NULL OR \"sales_entries\".\"discount_ttc\" >= 0" + }, + "sales_comp_ck": { + "name": "sales_comp_ck", + "value": "\"sales_entries\".\"comp_ttc\" IS NULL OR \"sales_entries\".\"comp_ttc\" >= 0" + }, + "sales_quantity_ck": { + "name": "sales_quantity_ck", + "value": "\"sales_entries\".\"quantity\" IS NULL OR \"sales_entries\".\"quantity\" <> 0" + } + }, + "isRLSEnabled": false + }, + "public.sales_families": { + "name": "sales_families", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_families_name_uq": { + "name": "sales_families_name_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_families_organization_id_organizations_id_fk": { + "name": "sales_families_organization_id_organizations_id_fk", + "tableFrom": "sales_families", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_families_created_by_users_id_fk": { + "name": "sales_families_created_by_users_id_fk", + "tableFrom": "sales_families", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sales_family_rules": { + "name": "sales_family_rules", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "family_id": { + "name": "family_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "match_kind": { + "name": "match_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "match_key": { + "name": "match_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "match_label": { + "name": "match_label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_family_rules_uq": { + "name": "sales_family_rules_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "match_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "match_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_family_rules_organization_id_organizations_id_fk": { + "name": "sales_family_rules_organization_id_organizations_id_fk", + "tableFrom": "sales_family_rules", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_family_rules_family_id_sales_families_id_fk": { + "name": "sales_family_rules_family_id_sales_families_id_fk", + "tableFrom": "sales_family_rules", + "tableTo": "sales_families", + "columnsFrom": [ + "family_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_family_rules_created_by_users_id_fk": { + "name": "sales_family_rules_created_by_users_id_fk", + "tableFrom": "sales_family_rules", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "sales_family_rules_kind_ck": { + "name": "sales_family_rules_kind_ck", + "value": "\"sales_family_rules\".\"match_kind\" IN ('category', 'product')" + } + }, + "isRLSEnabled": false + }, + "public.sales_import_batches": { + "name": "sales_import_batches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_sha256": { + "name": "file_sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "row_count": { + "name": "row_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "total_ht": { + "name": "total_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "total_ttc": { + "name": "total_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "period_from": { + "name": "period_from", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "period_to": { + "name": "period_to", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "import_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "imported_by": { + "name": "imported_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "reverted_at": { + "name": "reverted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "reverted_by": { + "name": "reverted_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "payment_count": { + "name": "payment_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_batches_file_uq": { + "name": "sales_batches_file_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "file_sha256", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_import_batches_organization_id_organizations_id_fk": { + "name": "sales_import_batches_organization_id_organizations_id_fk", + "tableFrom": "sales_import_batches", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_import_batches_establishment_id_establishments_id_fk": { + "name": "sales_import_batches_establishment_id_establishments_id_fk", + "tableFrom": "sales_import_batches", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "sales_import_batches_imported_by_users_id_fk": { + "name": "sales_import_batches_imported_by_users_id_fk", + "tableFrom": "sales_import_batches", + "tableTo": "users", + "columnsFrom": [ + "imported_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "sales_import_batches_reverted_by_users_id_fk": { + "name": "sales_import_batches_reverted_by_users_id_fk", + "tableFrom": "sales_import_batches", + "tableTo": "users", + "columnsFrom": [ + "reverted_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sales_import_profiles": { + "name": "sales_import_profiles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "header_signature": { + "name": "header_signature", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "headers": { + "name": "headers", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "mapping": { + "name": "mapping", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "use_count": { + "name": "use_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_import_profiles_sig_uq": { + "name": "sales_import_profiles_sig_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "header_signature", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_import_profiles_organization_id_organizations_id_fk": { + "name": "sales_import_profiles_organization_id_organizations_id_fk", + "tableFrom": "sales_import_profiles", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_import_profiles_created_by_users_id_fk": { + "name": "sales_import_profiles_created_by_users_id_fk", + "tableFrom": "sales_import_profiles", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "sales_import_profiles_name_ck": { + "name": "sales_import_profiles_name_ck", + "value": "length(\"sales_import_profiles\".\"name\") BETWEEN 1 AND 80" + } + }, + "isRLSEnabled": false + }, + "public.sales_payments": { + "name": "sales_payments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "batch_id": { + "name": "batch_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "business_date": { + "name": "business_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "ticket_ref": { + "name": "ticket_ref", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount_ttc": { + "name": "amount_ttc", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "row_hash": { + "name": "row_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data_status": { + "name": "data_status", + "type": "data_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'real_unvalidated'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_payments_row_uq": { + "name": "sales_payments_row_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "row_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sales_payments_period_idx": { + "name": "sales_payments_period_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "business_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_payments_organization_id_organizations_id_fk": { + "name": "sales_payments_organization_id_organizations_id_fk", + "tableFrom": "sales_payments", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_payments_establishment_id_establishments_id_fk": { + "name": "sales_payments_establishment_id_establishments_id_fk", + "tableFrom": "sales_payments", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "sales_payments_batch_id_sales_import_batches_id_fk": { + "name": "sales_payments_batch_id_sales_import_batches_id_fk", + "tableFrom": "sales_payments", + "tableTo": "sales_import_batches", + "columnsFrom": [ + "batch_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sales_product_recipe_history": { + "name": "sales_product_recipe_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "match_key": { + "name": "match_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "match_label": { + "name": "match_label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "recipe_id": { + "name": "recipe_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "portions_per_sale": { + "name": "portions_per_sale", + "type": "numeric(10, 4)", + "primaryKey": false, + "notNull": false + }, + "valid_until": { + "name": "valid_until", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_product_recipe_history_uq": { + "name": "sales_product_recipe_history_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "match_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "valid_until", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_product_recipe_history_organization_id_organizations_id_fk": { + "name": "sales_product_recipe_history_organization_id_organizations_id_fk", + "tableFrom": "sales_product_recipe_history", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_product_recipe_history_recipe_id_recipes_id_fk": { + "name": "sales_product_recipe_history_recipe_id_recipes_id_fk", + "tableFrom": "sales_product_recipe_history", + "tableTo": "recipes", + "columnsFrom": [ + "recipe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "sales_product_recipe_history_created_by_users_id_fk": { + "name": "sales_product_recipe_history_created_by_users_id_fk", + "tableFrom": "sales_product_recipe_history", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sales_product_recipes": { + "name": "sales_product_recipes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "match_key": { + "name": "match_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "match_label": { + "name": "match_label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "recipe_id": { + "name": "recipe_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "portions_per_sale": { + "name": "portions_per_sale", + "type": "numeric(10, 4)", + "primaryKey": false, + "notNull": false + }, + "match_code": { + "name": "match_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_product_recipes_key_uq": { + "name": "sales_product_recipes_key_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "match_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sales_product_recipes_code_uq": { + "name": "sales_product_recipes_code_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "match_code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"sales_product_recipes\".\"match_code\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "sales_product_recipes_recipe_idx": { + "name": "sales_product_recipes_recipe_idx", + "columns": [ + { + "expression": "recipe_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_product_recipes_organization_id_organizations_id_fk": { + "name": "sales_product_recipes_organization_id_organizations_id_fk", + "tableFrom": "sales_product_recipes", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_product_recipes_recipe_id_recipes_id_fk": { + "name": "sales_product_recipes_recipe_id_recipes_id_fk", + "tableFrom": "sales_product_recipes", + "tableTo": "recipes", + "columnsFrom": [ + "recipe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "sales_product_recipes_created_by_users_id_fk": { + "name": "sales_product_recipes_created_by_users_id_fk", + "tableFrom": "sales_product_recipes", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "sales_product_recipes_updated_by_users_id_fk": { + "name": "sales_product_recipes_updated_by_users_id_fk", + "tableFrom": "sales_product_recipes", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "sales_product_recipes_ck": { + "name": "sales_product_recipes_ck", + "value": "(\"sales_product_recipes\".\"recipe_id\" IS NULL AND \"sales_product_recipes\".\"portions_per_sale\" IS NULL) OR (\"sales_product_recipes\".\"recipe_id\" IS NOT NULL AND \"sales_product_recipes\".\"portions_per_sale\" > 0)" + } + }, + "isRLSEnabled": false + }, + "public.sales_server_links": { + "name": "sales_server_links", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "server_key": { + "name": "server_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "server_label": { + "name": "server_label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_server_links_uq": { + "name": "sales_server_links_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "server_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sales_server_links_org_idx": { + "name": "sales_server_links_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_server_links_organization_id_organizations_id_fk": { + "name": "sales_server_links_organization_id_organizations_id_fk", + "tableFrom": "sales_server_links", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_server_links_establishment_id_establishments_id_fk": { + "name": "sales_server_links_establishment_id_establishments_id_fk", + "tableFrom": "sales_server_links", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_server_links_employee_id_employees_id_fk": { + "name": "sales_server_links_employee_id_employees_id_fk", + "tableFrom": "sales_server_links", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_server_links_created_by_users_id_fk": { + "name": "sales_server_links_created_by_users_id_fk", + "tableFrom": "sales_server_links", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "sales_server_links_key_ck": { + "name": "sales_server_links_key_ck", + "value": "length(\"sales_server_links\".\"server_key\") BETWEEN 1 AND 120" + } + }, + "isRLSEnabled": false + }, + "public.sales_service_periods": { + "name": "sales_service_periods", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "end_time": { + "name": "end_time", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sales_service_periods_name_uq": { + "name": "sales_service_periods_name_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sales_service_periods_organization_id_organizations_id_fk": { + "name": "sales_service_periods_organization_id_organizations_id_fk", + "tableFrom": "sales_service_periods", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_service_periods_establishment_id_establishments_id_fk": { + "name": "sales_service_periods_establishment_id_establishments_id_fk", + "tableFrom": "sales_service_periods", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sales_service_periods_created_by_users_id_fk": { + "name": "sales_service_periods_created_by_users_id_fk", + "tableFrom": "sales_service_periods", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "sales_service_periods_time_ck": { + "name": "sales_service_periods_time_ck", + "value": "\"sales_service_periods\".\"start_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"sales_service_periods\".\"end_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"sales_service_periods\".\"start_time\" <> \"sales_service_periods\".\"end_time\"" + } + }, + "isRLSEnabled": false + }, + "public.sensitive_views": { + "name": "sensitive_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "area": { + "name": "area", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "viewed_at": { + "name": "viewed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sensitive_views_org_idx": { + "name": "sensitive_views_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "viewed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sensitive_views_user_idx": { + "name": "sensitive_views_user_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "viewed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sensitive_views_organization_id_organizations_id_fk": { + "name": "sensitive_views_organization_id_organizations_id_fk", + "tableFrom": "sensitive_views", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sensitive_views_user_id_users_id_fk": { + "name": "sensitive_views_user_id_users_id_fk", + "tableFrom": "sensitive_views", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.seo_listings": { + "name": "seo_listings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "directory": { + "name": "directory", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nap_hash": { + "name": "nap_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "checked_by": { + "name": "checked_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "seo_listings_est_dir_uq": { + "name": "seo_listings_est_dir_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "directory", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "seo_listings_org_idx": { + "name": "seo_listings_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "seo_listings_organization_id_organizations_id_fk": { + "name": "seo_listings_organization_id_organizations_id_fk", + "tableFrom": "seo_listings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "seo_listings_establishment_id_establishments_id_fk": { + "name": "seo_listings_establishment_id_establishments_id_fk", + "tableFrom": "seo_listings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "seo_listings_checked_by_users_id_fk": { + "name": "seo_listings_checked_by_users_id_fk", + "tableFrom": "seo_listings", + "tableTo": "users", + "columnsFrom": [ + "checked_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "seo_listings_status_ck": { + "name": "seo_listings_status_ck", + "value": "\"seo_listings\".\"status\" IN ('en_ligne', 'absent', 'non_concerne')" + } + }, + "isRLSEnabled": false + }, + "public.seo_profiles": { + "name": "seo_profiles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cuisines": { + "name": "cuisines", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "price_range": { + "name": "price_range", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "website": { + "name": "website", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "menu_url": { + "name": "menu_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "links": { + "name": "links", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "keywords": { + "name": "keywords", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "seo_profiles_est_uq": { + "name": "seo_profiles_est_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "seo_profiles_org_idx": { + "name": "seo_profiles_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "seo_profiles_organization_id_organizations_id_fk": { + "name": "seo_profiles_organization_id_organizations_id_fk", + "tableFrom": "seo_profiles", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "seo_profiles_establishment_id_establishments_id_fk": { + "name": "seo_profiles_establishment_id_establishments_id_fk", + "tableFrom": "seo_profiles", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "seo_profiles_updated_by_users_id_fk": { + "name": "seo_profiles_updated_by_users_id_fk", + "tableFrom": "seo_profiles", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "seo_profiles_price_ck": { + "name": "seo_profiles_price_ck", + "value": "\"seo_profiles\".\"price_range\" IS NULL OR \"seo_profiles\".\"price_range\" IN ('€', '€€', '€€€', '€€€€')" + } + }, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sessions_user_idx": { + "name": "sessions_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sessions_organization_id_organizations_id_fk": { + "name": "sessions_organization_id_organizations_id_fk", + "tableFrom": "sessions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.set_menus": { + "name": "set_menus", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "occasion": { + "name": "occasion", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lines": { + "name": "lines", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "min_guests": { + "name": "min_guests", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "max_guests": { + "name": "max_guests", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "available_from": { + "name": "available_from", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "available_to": { + "name": "available_to", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "recipe_ids": { + "name": "recipe_ids", + "type": "uuid[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::uuid[]" + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "set_menus_est_idx": { + "name": "set_menus_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "category", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "set_menus_organization_id_organizations_id_fk": { + "name": "set_menus_organization_id_organizations_id_fk", + "tableFrom": "set_menus", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "set_menus_establishment_id_establishments_id_fk": { + "name": "set_menus_establishment_id_establishments_id_fk", + "tableFrom": "set_menus", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "set_menus_created_by_users_id_fk": { + "name": "set_menus_created_by_users_id_fk", + "tableFrom": "set_menus", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "set_menus_category_ck": { + "name": "set_menus_category_ck", + "value": "\"set_menus\".\"category\" IN ('carte', 'groupe', 'evenement')" + }, + "set_menus_guests_ck": { + "name": "set_menus_guests_ck", + "value": "(\"set_menus\".\"min_guests\" IS NULL OR \"set_menus\".\"min_guests\" > 0) AND (\"set_menus\".\"max_guests\" IS NULL OR \"set_menus\".\"max_guests\" > 0) AND (\"set_menus\".\"min_guests\" IS NULL OR \"set_menus\".\"max_guests\" IS NULL OR \"set_menus\".\"min_guests\" <= \"set_menus\".\"max_guests\")" + }, + "set_menus_dates_ck": { + "name": "set_menus_dates_ck", + "value": "\"set_menus\".\"available_from\" IS NULL OR \"set_menus\".\"available_to\" IS NULL OR \"set_menus\".\"available_from\" <= \"set_menus\".\"available_to\"" + } + }, + "isRLSEnabled": false + }, + "public.shift_swaps": { + "name": "shift_swaps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "shift_id": { + "name": "shift_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "from_employee_id": { + "name": "from_employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "to_employee_id": { + "name": "to_employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "counter_shift_id": { + "name": "counter_shift_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "shift_snapshot": { + "name": "shift_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter_snapshot": { + "name": "counter_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'attente_collegue'" + }, + "colleague_answered_at": { + "name": "colleague_answered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "decided_by": { + "name": "decided_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "decision_note": { + "name": "decision_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "shift_swaps_est_status_idx": { + "name": "shift_swaps_est_status_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "shift_swaps_from_idx": { + "name": "shift_swaps_from_idx", + "columns": [ + { + "expression": "from_employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "shift_swaps_to_idx": { + "name": "shift_swaps_to_idx", + "columns": [ + { + "expression": "to_employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "shift_swaps_organization_id_organizations_id_fk": { + "name": "shift_swaps_organization_id_organizations_id_fk", + "tableFrom": "shift_swaps", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shift_swaps_establishment_id_establishments_id_fk": { + "name": "shift_swaps_establishment_id_establishments_id_fk", + "tableFrom": "shift_swaps", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shift_swaps_shift_id_shifts_id_fk": { + "name": "shift_swaps_shift_id_shifts_id_fk", + "tableFrom": "shift_swaps", + "tableTo": "shifts", + "columnsFrom": [ + "shift_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "shift_swaps_from_employee_id_employees_id_fk": { + "name": "shift_swaps_from_employee_id_employees_id_fk", + "tableFrom": "shift_swaps", + "tableTo": "employees", + "columnsFrom": [ + "from_employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shift_swaps_to_employee_id_employees_id_fk": { + "name": "shift_swaps_to_employee_id_employees_id_fk", + "tableFrom": "shift_swaps", + "tableTo": "employees", + "columnsFrom": [ + "to_employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shift_swaps_counter_shift_id_shifts_id_fk": { + "name": "shift_swaps_counter_shift_id_shifts_id_fk", + "tableFrom": "shift_swaps", + "tableTo": "shifts", + "columnsFrom": [ + "counter_shift_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "shift_swaps_decided_by_users_id_fk": { + "name": "shift_swaps_decided_by_users_id_fk", + "tableFrom": "shift_swaps", + "tableTo": "users", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "shift_swaps_created_by_users_id_fk": { + "name": "shift_swaps_created_by_users_id_fk", + "tableFrom": "shift_swaps", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "shift_swaps_status_ck": { + "name": "shift_swaps_status_ck", + "value": "\"shift_swaps\".\"status\" IN ('attente_collegue', 'attente_responsable', 'acceptee', 'refusee', 'annulee', 'expiree')" + }, + "shift_swaps_people_ck": { + "name": "shift_swaps_people_ck", + "value": "\"shift_swaps\".\"from_employee_id\" <> \"shift_swaps\".\"to_employee_id\"" + } + }, + "isRLSEnabled": false + }, + "public.shift_templates": { + "name": "shift_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "team": { + "name": "team", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "end_time": { + "name": "end_time", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "break_minutes": { + "name": "break_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "shift_templates_est_idx": { + "name": "shift_templates_est_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "shift_templates_organization_id_organizations_id_fk": { + "name": "shift_templates_organization_id_organizations_id_fk", + "tableFrom": "shift_templates", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shift_templates_establishment_id_establishments_id_fk": { + "name": "shift_templates_establishment_id_establishments_id_fk", + "tableFrom": "shift_templates", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shift_templates_created_by_users_id_fk": { + "name": "shift_templates_created_by_users_id_fk", + "tableFrom": "shift_templates", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "shift_templates_time_ck": { + "name": "shift_templates_time_ck", + "value": "\"shift_templates\".\"start_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"shift_templates\".\"end_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"shift_templates\".\"start_time\" <> \"shift_templates\".\"end_time\"" + }, + "shift_templates_break_ck": { + "name": "shift_templates_break_ck", + "value": "\"shift_templates\".\"break_minutes\" >= 0 AND \"shift_templates\".\"break_minutes\" <= 240" + } + }, + "isRLSEnabled": false + }, + "public.shifts": { + "name": "shifts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "team": { + "name": "team", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "end_time": { + "name": "end_time", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "break_minutes": { + "name": "break_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actual_start": { + "name": "actual_start", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actual_end": { + "name": "actual_end", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actual_break_minutes": { + "name": "actual_break_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "meals": { + "name": "meals", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "no_show": { + "name": "no_show", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "validated_at": { + "name": "validated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "validated_by": { + "name": "validated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "shifts_est_date_idx": { + "name": "shifts_est_date_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "shifts_emp_date_idx": { + "name": "shifts_emp_date_idx", + "columns": [ + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "shifts_organization_id_organizations_id_fk": { + "name": "shifts_organization_id_organizations_id_fk", + "tableFrom": "shifts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shifts_establishment_id_establishments_id_fk": { + "name": "shifts_establishment_id_establishments_id_fk", + "tableFrom": "shifts", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shifts_employee_id_employees_id_fk": { + "name": "shifts_employee_id_employees_id_fk", + "tableFrom": "shifts", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shifts_validated_by_users_id_fk": { + "name": "shifts_validated_by_users_id_fk", + "tableFrom": "shifts", + "tableTo": "users", + "columnsFrom": [ + "validated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "shifts_created_by_users_id_fk": { + "name": "shifts_created_by_users_id_fk", + "tableFrom": "shifts", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "shifts_meals_ck": { + "name": "shifts_meals_ck", + "value": "\"shifts\".\"meals\" >= 0 AND \"shifts\".\"meals\" <= 3" + }, + "shifts_time_ck": { + "name": "shifts_time_ck", + "value": "\"shifts\".\"start_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"shifts\".\"end_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"shifts\".\"start_time\" <> \"shifts\".\"end_time\"" + }, + "shifts_break_ck": { + "name": "shifts_break_ck", + "value": "\"shifts\".\"break_minutes\" >= 0 AND \"shifts\".\"break_minutes\" <= 240" + } + }, + "isRLSEnabled": false + }, + "public.signature_requests": { + "name": "signature_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "document_pdf": { + "name": "document_pdf", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "document_sha256": { + "name": "document_sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en_attente'" + }, + "signer_email": { + "name": "signer_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "employer_name": { + "name": "employer_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "code_hash": { + "name": "code_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "code_expires_at": { + "name": "code_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "code_sent_at": { + "name": "code_sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "codes_sent": { + "name": "codes_sent", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "code_attempts": { + "name": "code_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "signed_at": { + "name": "signed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "signed_name": { + "name": "signed_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "signed_pdf": { + "name": "signed_pdf", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "signed_sha256": { + "name": "signed_sha256", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refusal_note": { + "name": "refusal_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "events": { + "name": "events", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "file_id": { + "name": "file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "drawn_signature": { + "name": "drawn_signature", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "reminders_sent": { + "name": "reminders_sent", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_reminder_at": { + "name": "last_reminder_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "signature_requests_token_uq": { + "name": "signature_requests_token_uq", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "signature_requests_emp_idx": { + "name": "signature_requests_emp_idx", + "columns": [ + { + "expression": "employee_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "signature_requests_organization_id_organizations_id_fk": { + "name": "signature_requests_organization_id_organizations_id_fk", + "tableFrom": "signature_requests", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "signature_requests_establishment_id_establishments_id_fk": { + "name": "signature_requests_establishment_id_establishments_id_fk", + "tableFrom": "signature_requests", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "signature_requests_employee_id_employees_id_fk": { + "name": "signature_requests_employee_id_employees_id_fk", + "tableFrom": "signature_requests", + "tableTo": "employees", + "columnsFrom": [ + "employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "signature_requests_file_id_employee_files_id_fk": { + "name": "signature_requests_file_id_employee_files_id_fk", + "tableFrom": "signature_requests", + "tableTo": "employee_files", + "columnsFrom": [ + "file_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "signature_requests_created_by_users_id_fk": { + "name": "signature_requests_created_by_users_id_fk", + "tableFrom": "signature_requests", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "signature_requests_status_ck": { + "name": "signature_requests_status_ck", + "value": "\"signature_requests\".\"status\" IN ('en_attente', 'signe', 'refuse', 'annule')" + } + }, + "isRLSEnabled": false + }, + "public.skills": { + "name": "skills", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "team": { + "name": "team", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "skills_name_uq": { + "name": "skills_name_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"skills\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "skills_organization_id_organizations_id_fk": { + "name": "skills_organization_id_organizations_id_fk", + "tableFrom": "skills", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.social_posts": { + "name": "social_posts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "visual_id": { + "name": "visual_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_key": { + "name": "source_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "networks": { + "name": "networks", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "caption": { + "name": "caption", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scheduled_at": { + "name": "scheduled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "image_mime": { + "name": "image_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "image": { + "name": "image", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "image_format": { + "name": "image_format", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "public_token": { + "name": "public_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "approved_by": { + "name": "approved_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external": { + "name": "external", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "stats": { + "name": "stats", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "stats_at": { + "name": "stats_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "social_posts_cal_idx": { + "name": "social_posts_cal_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scheduled_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "social_posts_due_idx": { + "name": "social_posts_due_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scheduled_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "social_posts_source_uq": { + "name": "social_posts_source_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"social_posts\".\"source_key\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "social_posts_token_uq": { + "name": "social_posts_token_uq", + "columns": [ + { + "expression": "public_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "social_posts_organization_id_organizations_id_fk": { + "name": "social_posts_organization_id_organizations_id_fk", + "tableFrom": "social_posts", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "social_posts_establishment_id_establishments_id_fk": { + "name": "social_posts_establishment_id_establishments_id_fk", + "tableFrom": "social_posts", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "social_posts_visual_id_studio_visuals_id_fk": { + "name": "social_posts_visual_id_studio_visuals_id_fk", + "tableFrom": "social_posts", + "tableTo": "studio_visuals", + "columnsFrom": [ + "visual_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "social_posts_approved_by_users_id_fk": { + "name": "social_posts_approved_by_users_id_fk", + "tableFrom": "social_posts", + "tableTo": "users", + "columnsFrom": [ + "approved_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "social_posts_created_by_users_id_fk": { + "name": "social_posts_created_by_users_id_fk", + "tableFrom": "social_posts", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "social_posts_source_ck": { + "name": "social_posts_source_ck", + "value": "\"social_posts\".\"source\" IN ('manuel', 'menu_du_jour', 'evenement', 'fermeture', 'avis')" + }, + "social_posts_status_ck": { + "name": "social_posts_status_ck", + "value": "\"social_posts\".\"status\" IN ('a_valider', 'planifie', 'publie', 'partiel', 'echec', 'annule')" + }, + "social_posts_networks_ck": { + "name": "social_posts_networks_ck", + "value": "\"social_posts\".\"networks\" <@ ARRAY['instagram','facebook']::text[] AND cardinality(\"social_posts\".\"networks\") >= 1" + }, + "social_posts_image_ck": { + "name": "social_posts_image_ck", + "value": "(\"social_posts\".\"image\" IS NULL) = (\"social_posts\".\"image_mime\" IS NULL) AND (\"social_posts\".\"image_mime\" IS NULL OR \"social_posts\".\"image_mime\" = 'image/png')" + }, + "social_posts_format_ck": { + "name": "social_posts_format_ck", + "value": "\"social_posts\".\"image_format\" IS NULL OR \"social_posts\".\"image_format\" IN ('carre', 'portrait', 'facebook')" + }, + "social_posts_caption_ck": { + "name": "social_posts_caption_ck", + "value": "char_length(\"social_posts\".\"caption\") BETWEEN 1 AND 2200" + } + }, + "isRLSEnabled": false + }, + "public.social_settings": { + "name": "social_settings", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "networks": { + "name": "networks", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "ARRAY['instagram','facebook']::text[]" + }, + "require_approval": { + "name": "require_approval", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "auto_menu": { + "name": "auto_menu", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "menu_time": { + "name": "menu_time", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'11:00'" + }, + "auto_events": { + "name": "auto_events", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "event_time": { + "name": "event_time", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'18:00'" + }, + "closure_days_before": { + "name": "closure_days_before", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 3 + }, + "auto_reviews": { + "name": "auto_reviews", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "review_min_rating": { + "name": "review_min_rating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 5 + }, + "review_time": { + "name": "review_time", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'17:30'" + }, + "hashtags": { + "name": "hashtags", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "max_posts_per_day": { + "name": "max_posts_per_day", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 2 + }, + "repeat_days": { + "name": "repeat_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 14 + }, + "auto_best_times": { + "name": "auto_best_times", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "social_settings_org_idx": { + "name": "social_settings_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "social_settings_establishment_id_establishments_id_fk": { + "name": "social_settings_establishment_id_establishments_id_fk", + "tableFrom": "social_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "social_settings_organization_id_organizations_id_fk": { + "name": "social_settings_organization_id_organizations_id_fk", + "tableFrom": "social_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "social_settings_updated_by_users_id_fk": { + "name": "social_settings_updated_by_users_id_fk", + "tableFrom": "social_settings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "social_settings_repeat_ck": { + "name": "social_settings_repeat_ck", + "value": "\"social_settings\".\"max_posts_per_day\" BETWEEN 1 AND 5 AND \"social_settings\".\"repeat_days\" BETWEEN 0 AND 90" + }, + "social_settings_networks_ck": { + "name": "social_settings_networks_ck", + "value": "\"social_settings\".\"networks\" <@ ARRAY['instagram','facebook']::text[] AND cardinality(\"social_settings\".\"networks\") >= 1" + }, + "social_settings_times_ck": { + "name": "social_settings_times_ck", + "value": "\"social_settings\".\"menu_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"social_settings\".\"event_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$' AND \"social_settings\".\"review_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$'" + }, + "social_settings_rating_ck": { + "name": "social_settings_rating_ck", + "value": "\"social_settings\".\"review_min_rating\" BETWEEN 4 AND 5" + }, + "social_settings_days_ck": { + "name": "social_settings_days_ck", + "value": "\"social_settings\".\"closure_days_before\" BETWEEN 0 AND 14" + } + }, + "isRLSEnabled": false + }, + "public.stock_expiry_lots": { + "name": "stock_expiry_lots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_on": { + "name": "expires_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "received_on": { + "name": "received_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "lot_number": { + "name": "lot_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "order_line_id": { + "name": "order_line_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "closed_reason": { + "name": "closed_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "closed_by": { + "name": "closed_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "loss_id": { + "name": "loss_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "stock_expiry_lots_loss_idx": { + "name": "stock_expiry_lots_loss_idx", + "columns": [ + { + "expression": "loss_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"stock_expiry_lots\".\"loss_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "stock_expiry_lots_open_idx": { + "name": "stock_expiry_lots_open_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "expires_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"stock_expiry_lots\".\"closed_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "stock_expiry_lots_item_idx": { + "name": "stock_expiry_lots_item_idx", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "stock_expiry_lots_organization_id_organizations_id_fk": { + "name": "stock_expiry_lots_organization_id_organizations_id_fk", + "tableFrom": "stock_expiry_lots", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stock_expiry_lots_establishment_id_establishments_id_fk": { + "name": "stock_expiry_lots_establishment_id_establishments_id_fk", + "tableFrom": "stock_expiry_lots", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stock_expiry_lots_item_id_purchase_items_id_fk": { + "name": "stock_expiry_lots_item_id_purchase_items_id_fk", + "tableFrom": "stock_expiry_lots", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stock_expiry_lots_order_line_id_purchase_order_lines_id_fk": { + "name": "stock_expiry_lots_order_line_id_purchase_order_lines_id_fk", + "tableFrom": "stock_expiry_lots", + "tableTo": "purchase_order_lines", + "columnsFrom": [ + "order_line_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "stock_expiry_lots_closed_by_users_id_fk": { + "name": "stock_expiry_lots_closed_by_users_id_fk", + "tableFrom": "stock_expiry_lots", + "tableTo": "users", + "columnsFrom": [ + "closed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "stock_expiry_lots_loss_id_stock_losses_id_fk": { + "name": "stock_expiry_lots_loss_id_stock_losses_id_fk", + "tableFrom": "stock_expiry_lots", + "tableTo": "stock_losses", + "columnsFrom": [ + "loss_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "stock_expiry_lots_created_by_users_id_fk": { + "name": "stock_expiry_lots_created_by_users_id_fk", + "tableFrom": "stock_expiry_lots", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "stock_expiry_lots_kind_ck": { + "name": "stock_expiry_lots_kind_ck", + "value": "\"stock_expiry_lots\".\"kind\" IN ('dlc', 'ddm')" + }, + "stock_expiry_lots_qty_ck": { + "name": "stock_expiry_lots_qty_ck", + "value": "\"stock_expiry_lots\".\"quantity\" > 0" + }, + "stock_expiry_lots_close_ck": { + "name": "stock_expiry_lots_close_ck", + "value": "(\"stock_expiry_lots\".\"closed_at\" IS NULL) = (\"stock_expiry_lots\".\"closed_reason\" IS NULL) AND (\"stock_expiry_lots\".\"closed_reason\" IS NULL OR \"stock_expiry_lots\".\"closed_reason\" IN ('ecoule', 'perte', 'retour', 'erreur'))" + } + }, + "isRLSEnabled": false + }, + "public.stock_losses": { + "name": "stock_losses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "loss_date": { + "name": "loss_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "unit_cost": { + "name": "unit_cost", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": false + }, + "value": { + "name": "value", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credit_request_id": { + "name": "credit_request_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "stock_losses_est_idx": { + "name": "stock_losses_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "loss_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "stock_losses_organization_id_organizations_id_fk": { + "name": "stock_losses_organization_id_organizations_id_fk", + "tableFrom": "stock_losses", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stock_losses_establishment_id_establishments_id_fk": { + "name": "stock_losses_establishment_id_establishments_id_fk", + "tableFrom": "stock_losses", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "stock_losses_item_id_purchase_items_id_fk": { + "name": "stock_losses_item_id_purchase_items_id_fk", + "tableFrom": "stock_losses", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "stock_losses_created_by_users_id_fk": { + "name": "stock_losses_created_by_users_id_fk", + "tableFrom": "stock_losses", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "stock_losses_cancelled_by_users_id_fk": { + "name": "stock_losses_cancelled_by_users_id_fk", + "tableFrom": "stock_losses", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "stock_losses_credit_request_id_credit_requests_id_fk": { + "name": "stock_losses_credit_request_id_credit_requests_id_fk", + "tableFrom": "stock_losses", + "tableTo": "credit_requests", + "columnsFrom": [ + "credit_request_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "stock_losses_qty_ck": { + "name": "stock_losses_qty_ck", + "value": "\"stock_losses\".\"quantity\" > 0" + }, + "stock_losses_reason_ck": { + "name": "stock_losses_reason_ck", + "value": "\"stock_losses\".\"reason\" IN ('peremption', 'casse', 'erreur_production', 'retour_client', 'repas_personnel', 'offert', 'vol', 'retour_fournisseur', 'autre')" + } + }, + "isRLSEnabled": false + }, + "public.stock_rotation_settings": { + "name": "stock_rotation_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "overstock_days": { + "name": "overstock_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "lookback_days": { + "name": "lookback_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 28 + }, + "level_basis": { + "name": "level_basis", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'compte'" + }, + "expiry_alert_days": { + "name": "expiry_alert_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 2 + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "stock_rotation_settings_est_uq": { + "name": "stock_rotation_settings_est_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "stock_rotation_settings_organization_id_organizations_id_fk": { + "name": "stock_rotation_settings_organization_id_organizations_id_fk", + "tableFrom": "stock_rotation_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stock_rotation_settings_establishment_id_establishments_id_fk": { + "name": "stock_rotation_settings_establishment_id_establishments_id_fk", + "tableFrom": "stock_rotation_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stock_rotation_settings_updated_by_users_id_fk": { + "name": "stock_rotation_settings_updated_by_users_id_fk", + "tableFrom": "stock_rotation_settings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "stock_rotation_overstock_ck": { + "name": "stock_rotation_overstock_ck", + "value": "\"stock_rotation_settings\".\"overstock_days\" IS NULL OR \"stock_rotation_settings\".\"overstock_days\" BETWEEN 1 AND 365" + }, + "stock_rotation_lookback_ck": { + "name": "stock_rotation_lookback_ck", + "value": "\"stock_rotation_settings\".\"lookback_days\" BETWEEN 7 AND 365" + }, + "stock_rotation_basis_ck": { + "name": "stock_rotation_basis_ck", + "value": "\"stock_rotation_settings\".\"level_basis\" IN ('compte', 'theorique')" + }, + "stock_rotation_expiry_ck": { + "name": "stock_rotation_expiry_ck", + "value": "\"stock_rotation_settings\".\"expiry_alert_days\" BETWEEN 0 AND 30" + } + }, + "isRLSEnabled": false + }, + "public.stock_transfer_lines": { + "name": "stock_transfer_lines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "transfer_id": { + "name": "transfer_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "unit_cost": { + "name": "unit_cost", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "stock_transfer_lines_item_uq": { + "name": "stock_transfer_lines_item_uq", + "columns": [ + { + "expression": "transfer_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "stock_transfer_lines_item_idx": { + "name": "stock_transfer_lines_item_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "stock_transfer_lines_organization_id_organizations_id_fk": { + "name": "stock_transfer_lines_organization_id_organizations_id_fk", + "tableFrom": "stock_transfer_lines", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stock_transfer_lines_transfer_id_stock_transfers_id_fk": { + "name": "stock_transfer_lines_transfer_id_stock_transfers_id_fk", + "tableFrom": "stock_transfer_lines", + "tableTo": "stock_transfers", + "columnsFrom": [ + "transfer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stock_transfer_lines_item_id_purchase_items_id_fk": { + "name": "stock_transfer_lines_item_id_purchase_items_id_fk", + "tableFrom": "stock_transfer_lines", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "stock_transfer_lines_ck": { + "name": "stock_transfer_lines_ck", + "value": "\"stock_transfer_lines\".\"quantity\" > 0 AND \"stock_transfer_lines\".\"unit_cost\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.stock_transfers": { + "name": "stock_transfers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "from_establishment_id": { + "name": "from_establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "to_establishment_id": { + "name": "to_establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "transfer_date": { + "name": "transfer_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "total_value": { + "name": "total_value", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "stock_transfers_number_uq": { + "name": "stock_transfers_number_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "stock_transfers_from_idx": { + "name": "stock_transfers_from_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "from_establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "transfer_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "stock_transfers_to_idx": { + "name": "stock_transfers_to_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "to_establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "transfer_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "stock_transfers_organization_id_organizations_id_fk": { + "name": "stock_transfers_organization_id_organizations_id_fk", + "tableFrom": "stock_transfers", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stock_transfers_from_establishment_id_establishments_id_fk": { + "name": "stock_transfers_from_establishment_id_establishments_id_fk", + "tableFrom": "stock_transfers", + "tableTo": "establishments", + "columnsFrom": [ + "from_establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "stock_transfers_to_establishment_id_establishments_id_fk": { + "name": "stock_transfers_to_establishment_id_establishments_id_fk", + "tableFrom": "stock_transfers", + "tableTo": "establishments", + "columnsFrom": [ + "to_establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "stock_transfers_created_by_users_id_fk": { + "name": "stock_transfers_created_by_users_id_fk", + "tableFrom": "stock_transfers", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "stock_transfers_cancelled_by_users_id_fk": { + "name": "stock_transfers_cancelled_by_users_id_fk", + "tableFrom": "stock_transfers", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "stock_transfers_distinct_ck": { + "name": "stock_transfers_distinct_ck", + "value": "\"stock_transfers\".\"from_establishment_id\" <> \"stock_transfers\".\"to_establishment_id\"" + } + }, + "isRLSEnabled": false + }, + "public.studio_brands": { + "name": "studio_brands", + "schema": "", + "columns": { + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "handle": { + "name": "handle", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contact": { + "name": "contact", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "background": { + "name": "background", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'#1f2a24'" + }, + "primary": { + "name": "primary", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'#d9a441'" + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'#fbf7ee'" + }, + "font": { + "name": "font", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'classique'" + }, + "logo_mime": { + "name": "logo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "logo": { + "name": "logo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "studio_brands_org_idx": { + "name": "studio_brands_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "studio_brands_establishment_id_establishments_id_fk": { + "name": "studio_brands_establishment_id_establishments_id_fk", + "tableFrom": "studio_brands", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "studio_brands_organization_id_organizations_id_fk": { + "name": "studio_brands_organization_id_organizations_id_fk", + "tableFrom": "studio_brands", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "studio_brands_updated_by_users_id_fk": { + "name": "studio_brands_updated_by_users_id_fk", + "tableFrom": "studio_brands", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "studio_brands_colors_ck": { + "name": "studio_brands_colors_ck", + "value": "\"studio_brands\".\"background\" ~ '^#[0-9a-f]{6}$' AND \"studio_brands\".\"primary\" ~ '^#[0-9a-f]{6}$' AND \"studio_brands\".\"text\" ~ '^#[0-9a-f]{6}$'" + }, + "studio_brands_font_ck": { + "name": "studio_brands_font_ck", + "value": "\"studio_brands\".\"font\" IN ('classique', 'moderne', 'elegant')" + }, + "studio_brands_logo_ck": { + "name": "studio_brands_logo_ck", + "value": "(\"studio_brands\".\"logo\" IS NULL) = (\"studio_brands\".\"logo_mime\" IS NULL) AND (\"studio_brands\".\"logo_mime\" IS NULL OR \"studio_brands\".\"logo_mime\" IN ('image/jpeg', 'image/png', 'image/webp'))" + } + }, + "isRLSEnabled": false + }, + "public.studio_visuals": { + "name": "studio_visuals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "template": { + "name": "template", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "format": { + "name": "format", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "caption": { + "name": "caption", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "studio_visuals_est_idx": { + "name": "studio_visuals_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "studio_visuals_organization_id_organizations_id_fk": { + "name": "studio_visuals_organization_id_organizations_id_fk", + "tableFrom": "studio_visuals", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "studio_visuals_establishment_id_establishments_id_fk": { + "name": "studio_visuals_establishment_id_establishments_id_fk", + "tableFrom": "studio_visuals", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "studio_visuals_created_by_users_id_fk": { + "name": "studio_visuals_created_by_users_id_fk", + "tableFrom": "studio_visuals", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "studio_visuals_template_ck": { + "name": "studio_visuals_template_ck", + "value": "\"studio_visuals\".\"template\" IN ('menu_du_jour', 'plat', 'evenement', 'avis')" + }, + "studio_visuals_format_ck": { + "name": "studio_visuals_format_ck", + "value": "\"studio_visuals\".\"format\" IN ('carre', 'portrait', 'story', 'facebook')" + }, + "studio_visuals_photo_ck": { + "name": "studio_visuals_photo_ck", + "value": "(\"studio_visuals\".\"photo\" IS NULL) = (\"studio_visuals\".\"photo_mime\" IS NULL) AND (\"studio_visuals\".\"photo_mime\" IS NULL OR \"studio_visuals\".\"photo_mime\" IN ('image/jpeg', 'image/png', 'image/webp'))" + } + }, + "isRLSEnabled": false + }, + "public.supplier_offer_prices": { + "name": "supplier_offer_prices", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "offer_id": { + "name": "offer_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "price_ht": { + "name": "price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": true + }, + "content_quantity": { + "name": "content_quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "content_unit": { + "name": "content_unit", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "effective_date": { + "name": "effective_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "supplier_offer_prices_offer_idx": { + "name": "supplier_offer_prices_offer_idx", + "columns": [ + { + "expression": "offer_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "effective_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "supplier_offer_prices_organization_id_organizations_id_fk": { + "name": "supplier_offer_prices_organization_id_organizations_id_fk", + "tableFrom": "supplier_offer_prices", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "supplier_offer_prices_offer_id_supplier_offers_id_fk": { + "name": "supplier_offer_prices_offer_id_supplier_offers_id_fk", + "tableFrom": "supplier_offer_prices", + "tableTo": "supplier_offers", + "columnsFrom": [ + "offer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "supplier_offer_prices_created_by_users_id_fk": { + "name": "supplier_offer_prices_created_by_users_id_fk", + "tableFrom": "supplier_offer_prices", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "supplier_offer_prices_source_ck": { + "name": "supplier_offer_prices_source_ck", + "value": "\"supplier_offer_prices\".\"source\" IN ('manual', 'import', 'migration', 'demande_prix')" + }, + "supplier_offer_prices_price_ck": { + "name": "supplier_offer_prices_price_ck", + "value": "\"supplier_offer_prices\".\"price_ht\" >= 0 AND \"supplier_offer_prices\".\"content_quantity\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.supplier_offers": { + "name": "supplier_offers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "supplier_id": { + "name": "supplier_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "supplier_ref": { + "name": "supplier_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "price_ht": { + "name": "price_ht", + "type": "numeric(19, 6)", + "primaryKey": false, + "notNull": true + }, + "content_quantity": { + "name": "content_quantity", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": true + }, + "content_unit": { + "name": "content_unit", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "price_date": { + "name": "price_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "supplier_offers_item_idx": { + "name": "supplier_offers_item_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "supplier_offers_supplier_idx": { + "name": "supplier_offers_supplier_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "supplier_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "supplier_offers_active_uq": { + "name": "supplier_offers_active_uq", + "columns": [ + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "supplier_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(coalesce(\"supplier_ref\", ''))", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"supplier_offers\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "supplier_offers_organization_id_organizations_id_fk": { + "name": "supplier_offers_organization_id_organizations_id_fk", + "tableFrom": "supplier_offers", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "supplier_offers_item_id_purchase_items_id_fk": { + "name": "supplier_offers_item_id_purchase_items_id_fk", + "tableFrom": "supplier_offers", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "supplier_offers_supplier_id_suppliers_id_fk": { + "name": "supplier_offers_supplier_id_suppliers_id_fk", + "tableFrom": "supplier_offers", + "tableTo": "suppliers", + "columnsFrom": [ + "supplier_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "supplier_offers_created_by_users_id_fk": { + "name": "supplier_offers_created_by_users_id_fk", + "tableFrom": "supplier_offers", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "supplier_offers_updated_by_users_id_fk": { + "name": "supplier_offers_updated_by_users_id_fk", + "tableFrom": "supplier_offers", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "supplier_offers_price_ck": { + "name": "supplier_offers_price_ck", + "value": "\"supplier_offers\".\"price_ht\" >= 0 AND \"supplier_offers\".\"content_quantity\" > 0" + }, + "supplier_offers_unit_ck": { + "name": "supplier_offers_unit_ck", + "value": "\"supplier_offers\".\"content_unit\" IN ('kg', 'g', 'L', 'cl', 'pièce', 'botte', 'carton', 'colis', 'bouteille', 'fût', 'lot', 'heure', 'forfait')" + }, + "supplier_offers_source_ck": { + "name": "supplier_offers_source_ck", + "value": "\"supplier_offers\".\"source\" IN ('manual', 'import', 'migration', 'demande_prix')" + } + }, + "isRLSEnabled": false + }, + "public.suppliers": { + "name": "suppliers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "siret": { + "name": "siret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vat_number": { + "name": "vat_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contact_name": { + "name": "contact_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "address_line": { + "name": "address_line", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "postal_code": { + "name": "postal_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "city": { + "name": "city", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payment_terms_days": { + "name": "payment_terms_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "default_category": { + "name": "default_category", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'food'" + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "min_order_ht": { + "name": "min_order_ht", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "order_cutoff": { + "name": "order_cutoff", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lead_time_days": { + "name": "lead_time_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "delivery_fee_mode": { + "name": "delivery_fee_mode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "delivery_fee_fixed": { + "name": "delivery_fee_fixed", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "delivery_fee_percent": { + "name": "delivery_fee_percent", + "type": "numeric(7, 4)", + "primaryKey": false, + "notNull": false + }, + "delivery_fee_tiers": { + "name": "delivery_fee_tiers", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "suppliers_org_idx": { + "name": "suppliers_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "suppliers_org_name_uq": { + "name": "suppliers_org_name_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"name\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "suppliers_organization_id_organizations_id_fk": { + "name": "suppliers_organization_id_organizations_id_fk", + "tableFrom": "suppliers", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "suppliers_created_by_users_id_fk": { + "name": "suppliers_created_by_users_id_fk", + "tableFrom": "suppliers", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "suppliers_fee_mode_ck": { + "name": "suppliers_fee_mode_ck", + "value": "\"suppliers\".\"delivery_fee_mode\" IN ('none', 'fixed', 'tiers', 'percent')" + }, + "suppliers_cutoff_ck": { + "name": "suppliers_cutoff_ck", + "value": "\"suppliers\".\"order_cutoff\" IS NULL OR \"suppliers\".\"order_cutoff\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$'" + }, + "suppliers_siret_ck": { + "name": "suppliers_siret_ck", + "value": "\"suppliers\".\"siret\" IS NULL OR \"suppliers\".\"siret\" ~ '^[0-9]{14}$'" + }, + "suppliers_terms_ck": { + "name": "suppliers_terms_ck", + "value": "\"suppliers\".\"payment_terms_days\" IS NULL OR (\"suppliers\".\"payment_terms_days\" >= 0 AND \"suppliers\".\"payment_terms_days\" <= 365)" + } + }, + "isRLSEnabled": false + }, + "public.tablet_devices": { + "name": "tablet_devices", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "mode": { + "name": "mode", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "photo_on_punch": { + "name": "photo_on_punch", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "pairing_code_hash": { + "name": "pairing_code_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pairing_expires_at": { + "name": "pairing_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "paired_at": { + "name": "paired_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "operator_employee_id": { + "name": "operator_employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "operator_token_hash": { + "name": "operator_token_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "operator_until": { + "name": "operator_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "tablet_devices_org_idx": { + "name": "tablet_devices_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tablet_devices_token_uq": { + "name": "tablet_devices_token_uq", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tablet_devices_pairing_uq": { + "name": "tablet_devices_pairing_uq", + "columns": [ + { + "expression": "pairing_code_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tablet_devices_organization_id_organizations_id_fk": { + "name": "tablet_devices_organization_id_organizations_id_fk", + "tableFrom": "tablet_devices", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tablet_devices_establishment_id_establishments_id_fk": { + "name": "tablet_devices_establishment_id_establishments_id_fk", + "tableFrom": "tablet_devices", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tablet_devices_operator_employee_id_employees_id_fk": { + "name": "tablet_devices_operator_employee_id_employees_id_fk", + "tableFrom": "tablet_devices", + "tableTo": "employees", + "columnsFrom": [ + "operator_employee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tablet_devices_created_by_users_id_fk": { + "name": "tablet_devices_created_by_users_id_fk", + "tableFrom": "tablet_devices", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "tablet_devices_mode_ck": { + "name": "tablet_devices_mode_ck", + "value": "\"tablet_devices\".\"mode\" IN ('pointeuse', 'haccp')" + } + }, + "isRLSEnabled": false + }, + "public.task_completions": { + "name": "task_completions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "occurrence": { + "name": "occurrence", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "done_at": { + "name": "done_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "done_by": { + "name": "done_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_completions_est_idx": { + "name": "task_completions_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurrence", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_completions_once_uq": { + "name": "task_completions_once_uq", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurrence", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"task_completions\".\"cancelled_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_completions_organization_id_organizations_id_fk": { + "name": "task_completions_organization_id_organizations_id_fk", + "tableFrom": "task_completions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_completions_establishment_id_establishments_id_fk": { + "name": "task_completions_establishment_id_establishments_id_fk", + "tableFrom": "task_completions", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "task_completions_task_id_task_definitions_id_fk": { + "name": "task_completions_task_id_task_definitions_id_fk", + "tableFrom": "task_completions", + "tableTo": "task_definitions", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "task_completions_done_by_users_id_fk": { + "name": "task_completions_done_by_users_id_fk", + "tableFrom": "task_completions", + "tableTo": "users", + "columnsFrom": [ + "done_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "task_completions_cancelled_by_users_id_fk": { + "name": "task_completions_cancelled_by_users_id_fk", + "tableFrom": "task_completions", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_definitions": { + "name": "task_definitions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "instructions": { + "name": "instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'autre'" + }, + "frequency": { + "name": "frequency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "weekdays": { + "name": "weekdays", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "month_day": { + "name": "month_day", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "once_date": { + "name": "once_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "due_time": { + "name": "due_time", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assignee_user_id": { + "name": "assignee_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "team": { + "name": "team", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo_required": { + "name": "photo_required", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "starts_on": { + "name": "starts_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_definitions_est_idx": { + "name": "task_definitions_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_definitions_organization_id_organizations_id_fk": { + "name": "task_definitions_organization_id_organizations_id_fk", + "tableFrom": "task_definitions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_definitions_establishment_id_establishments_id_fk": { + "name": "task_definitions_establishment_id_establishments_id_fk", + "tableFrom": "task_definitions", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "task_definitions_assignee_user_id_users_id_fk": { + "name": "task_definitions_assignee_user_id_users_id_fk", + "tableFrom": "task_definitions", + "tableTo": "users", + "columnsFrom": [ + "assignee_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "task_definitions_created_by_users_id_fk": { + "name": "task_definitions_created_by_users_id_fk", + "tableFrom": "task_definitions", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "task_definitions_freq_ck": { + "name": "task_definitions_freq_ck", + "value": "\"task_definitions\".\"frequency\" IN ('once', 'daily', 'weekly', 'monthly')" + }, + "task_definitions_due_ck": { + "name": "task_definitions_due_ck", + "value": "\"task_definitions\".\"due_time\" IS NULL OR \"task_definitions\".\"due_time\" ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$'" + }, + "task_definitions_month_ck": { + "name": "task_definitions_month_ck", + "value": "\"task_definitions\".\"month_day\" IS NULL OR \"task_definitions\".\"month_day\" BETWEEN 1 AND 31" + } + }, + "isRLSEnabled": false + }, + "public.temperature_readings": { + "name": "temperature_readings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "equipment_id": { + "name": "equipment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "temperature": { + "name": "temperature", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": true + }, + "temp_min": { + "name": "temp_min", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "temp_max": { + "name": "temp_max", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "conform": { + "name": "conform", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "corrective_action": { + "name": "corrective_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "sensor_id": { + "name": "sensor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "client_ref": { + "name": "client_ref", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "entered_offline": { + "name": "entered_offline", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "temperature_readings_est_idx": { + "name": "temperature_readings_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "read_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "temperature_readings_eq_idx": { + "name": "temperature_readings_eq_idx", + "columns": [ + { + "expression": "equipment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "read_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "temperature_readings_sensor_idx": { + "name": "temperature_readings_sensor_idx", + "columns": [ + { + "expression": "sensor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "read_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "temperature_readings_client_ref_uq": { + "name": "temperature_readings_client_ref_uq", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "client_ref", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"temperature_readings\".\"client_ref\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "temperature_readings_organization_id_organizations_id_fk": { + "name": "temperature_readings_organization_id_organizations_id_fk", + "tableFrom": "temperature_readings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "temperature_readings_establishment_id_establishments_id_fk": { + "name": "temperature_readings_establishment_id_establishments_id_fk", + "tableFrom": "temperature_readings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "temperature_readings_equipment_id_equipment_id_fk": { + "name": "temperature_readings_equipment_id_equipment_id_fk", + "tableFrom": "temperature_readings", + "tableTo": "equipment", + "columnsFrom": [ + "equipment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "temperature_readings_recorded_by_users_id_fk": { + "name": "temperature_readings_recorded_by_users_id_fk", + "tableFrom": "temperature_readings", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "temperature_readings_sensor_id_temperature_sensors_id_fk": { + "name": "temperature_readings_sensor_id_temperature_sensors_id_fk", + "tableFrom": "temperature_readings", + "tableTo": "temperature_sensors", + "columnsFrom": [ + "sensor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "temperature_readings_cancelled_by_users_id_fk": { + "name": "temperature_readings_cancelled_by_users_id_fk", + "tableFrom": "temperature_readings", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "temperature_readings_action_ck": { + "name": "temperature_readings_action_ck", + "value": "\"temperature_readings\".\"conform\" OR \"temperature_readings\".\"corrective_action\" IS NOT NULL OR \"temperature_readings\".\"sensor_id\" IS NOT NULL" + }, + "temperature_readings_author_ck": { + "name": "temperature_readings_author_ck", + "value": "\"temperature_readings\".\"recorded_by\" IS NOT NULL OR \"temperature_readings\".\"sensor_id\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.temperature_sensors": { + "name": "temperature_sensors", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "equipment_id": { + "name": "equipment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_hint": { + "name": "token_hint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "keep_every_minutes": { + "name": "keep_every_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 15 + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_temperature": { + "name": "last_temperature", + "type": "numeric(5, 1)", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "temperature_sensors_token_uq": { + "name": "temperature_sensors_token_uq", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "temperature_sensors_est_idx": { + "name": "temperature_sensors_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "temperature_sensors_organization_id_organizations_id_fk": { + "name": "temperature_sensors_organization_id_organizations_id_fk", + "tableFrom": "temperature_sensors", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "temperature_sensors_establishment_id_establishments_id_fk": { + "name": "temperature_sensors_establishment_id_establishments_id_fk", + "tableFrom": "temperature_sensors", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "temperature_sensors_equipment_id_equipment_id_fk": { + "name": "temperature_sensors_equipment_id_equipment_id_fk", + "tableFrom": "temperature_sensors", + "tableTo": "equipment", + "columnsFrom": [ + "equipment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "temperature_sensors_created_by_users_id_fk": { + "name": "temperature_sensors_created_by_users_id_fk", + "tableFrom": "temperature_sensors", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "temperature_sensors_keep_ck": { + "name": "temperature_sensors_keep_ck", + "value": "\"temperature_sensors\".\"keep_every_minutes\" BETWEEN 1 AND 240" + } + }, + "isRLSEnabled": false + }, + "public.trace_labels": { + "name": "trace_labels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "taken_at": { + "name": "taken_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "photo": { + "name": "photo", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "photo_mime": { + "name": "photo_mime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "photo_size": { + "name": "photo_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "item_id": { + "name": "item_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "product_label": { + "name": "product_label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "brand": { + "name": "brand", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "supplier_name": { + "name": "supplier_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "weight": { + "name": "weight", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dlc": { + "name": "dlc", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "usage": { + "name": "usage", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "lot_number": { + "name": "lot_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "allergens": { + "name": "allergens", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "production_name": { + "name": "production_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "trace_labels_est_idx": { + "name": "trace_labels_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "taken_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "trace_labels_organization_id_organizations_id_fk": { + "name": "trace_labels_organization_id_organizations_id_fk", + "tableFrom": "trace_labels", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "trace_labels_establishment_id_establishments_id_fk": { + "name": "trace_labels_establishment_id_establishments_id_fk", + "tableFrom": "trace_labels", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "trace_labels_item_id_purchase_items_id_fk": { + "name": "trace_labels_item_id_purchase_items_id_fk", + "tableFrom": "trace_labels", + "tableTo": "purchase_items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "trace_labels_recorded_by_users_id_fk": { + "name": "trace_labels_recorded_by_users_id_fk", + "tableFrom": "trace_labels", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "trace_labels_cancelled_by_users_id_fk": { + "name": "trace_labels_cancelled_by_users_id_fk", + "tableFrom": "trace_labels", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "trace_labels_usage_ck": { + "name": "trace_labels_usage_ck", + "value": "\"trace_labels\".\"usage\" IN ('reception', 'ouverture', 'production')" + }, + "trace_labels_size_ck": { + "name": "trace_labels_size_ck", + "value": "\"trace_labels\".\"photo_size\" IS NULL OR \"trace_labels\".\"photo_size\" <= 5242880" + } + }, + "isRLSEnabled": false + }, + "public.treasury_settings": { + "name": "treasury_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "vat_regime": { + "name": "vat_regime", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vat_due_day": { + "name": "vat_due_day", + "type": "smallint", + "primaryKey": false, + "notNull": false + }, + "alert_threshold": { + "name": "alert_threshold", + "type": "numeric(19, 4)", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "treasury_settings_est_uq": { + "name": "treasury_settings_est_uq", + "columns": [ + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "treasury_settings_organization_id_organizations_id_fk": { + "name": "treasury_settings_organization_id_organizations_id_fk", + "tableFrom": "treasury_settings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "treasury_settings_establishment_id_establishments_id_fk": { + "name": "treasury_settings_establishment_id_establishments_id_fk", + "tableFrom": "treasury_settings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "treasury_settings_updated_by_users_id_fk": { + "name": "treasury_settings_updated_by_users_id_fk", + "tableFrom": "treasury_settings", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "treasury_settings_vat_ck": { + "name": "treasury_settings_vat_ck", + "value": "(\"treasury_settings\".\"vat_regime\" IS NULL OR \"treasury_settings\".\"vat_regime\" IN ('monthly', 'quarterly')) AND (\"treasury_settings\".\"vat_due_day\" IS NULL OR \"treasury_settings\".\"vat_due_day\" BETWEEN 1 AND 31)" + } + }, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "totp_secret_enc": { + "name": "totp_secret_enc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "totp_enabled_at": { + "name": "totp_enabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "totp_last_step": { + "name": "totp_last_step", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "password_changed_at": { + "name": "password_changed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "failed_login_count": { + "name": "failed_login_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "locked_until": { + "name": "locked_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "disabled_at": { + "name": "disabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "message_emails": { + "name": "message_emails", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "notification_phone": { + "name": "notification_phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "seen_release": { + "name": "seen_release", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_login_at": { + "name": "last_login_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "platform_admin": { + "name": "platform_admin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email_verification_pending": { + "name": "email_verification_pending", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by_organization_id": { + "name": "created_by_organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "users_email_lower_uq": { + "name": "users_email_lower_uq", + "columns": [ + { + "expression": "lower(\"email\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "users_created_by_organization_id_organizations_id_fk": { + "name": "users_created_by_organization_id_organizations_id_fk", + "tableFrom": "users", + "tableTo": "organizations", + "columnsFrom": [ + "created_by_organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.waiter_closings": { + "name": "waiter_closings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "establishment_id": { + "name": "establishment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "business_day": { + "name": "business_day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "waiter_label": { + "name": "waiter_label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "waiter_key": { + "name": "waiter_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "groupe": { + "name": "groupe", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "cb": { + "name": "cb", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "especes": { + "name": "especes", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "autre": { + "name": "autre", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": true + }, + "recorded_by": { + "name": "recorded_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "recorded_at": { + "name": "recorded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_by": { + "name": "cancelled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "waiter_closings_est_idx": { + "name": "waiter_closings_est_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "establishment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "business_day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "waiter_closings_organization_id_organizations_id_fk": { + "name": "waiter_closings_organization_id_organizations_id_fk", + "tableFrom": "waiter_closings", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "waiter_closings_establishment_id_establishments_id_fk": { + "name": "waiter_closings_establishment_id_establishments_id_fk", + "tableFrom": "waiter_closings", + "tableTo": "establishments", + "columnsFrom": [ + "establishment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "waiter_closings_recorded_by_users_id_fk": { + "name": "waiter_closings_recorded_by_users_id_fk", + "tableFrom": "waiter_closings", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "waiter_closings_cancelled_by_users_id_fk": { + "name": "waiter_closings_cancelled_by_users_id_fk", + "tableFrom": "waiter_closings", + "tableTo": "users", + "columnsFrom": [ + "cancelled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "waiter_closings_amounts_ck": { + "name": "waiter_closings_amounts_ck", + "value": "\"waiter_closings\".\"groupe\" >= 0 AND \"waiter_closings\".\"cb\" >= 0 AND \"waiter_closings\".\"especes\" >= 0 AND \"waiter_closings\".\"autre\" >= 0" + }, + "waiter_closings_key_ck": { + "name": "waiter_closings_key_ck", + "value": "length(\"waiter_closings\".\"waiter_key\") BETWEEN 1 AND 120" + } + }, + "isRLSEnabled": false + } + }, + "enums": { + "public.connection_status": { + "name": "connection_status", + "schema": "public", + "values": [ + "not_configured", + "pending_verification", + "connected", + "error", + "disabled" + ] + }, + "public.data_status": { + "name": "data_status", + "schema": "public", + "values": [ + "real_validated", + "real_unvalidated", + "provisional", + "estimated", + "forecast", + "missing" + ] + }, + "public.import_status": { + "name": "import_status", + "schema": "public", + "values": [ + "completed", + "rejected", + "reverted" + ] + }, + "public.member_role": { + "name": "member_role", + "schema": "public", + "values": [ + "owner", + "admin", + "director", + "manager", + "accountant", + "chef", + "staff", + "cuisine", + "viewer", + "rh", + "controller", + "purchasing" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index c9430745..a6b4fb9c 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -869,6 +869,13 @@ "when": 1796132436678, "tag": "0123_automatisations_avancees", "breakpoints": true + }, + { + "idx": 124, + "version": "7", + "when": 1796142642755, + "tag": "0124_hygiene_rappels_nuisibles", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/app/(app)/haccp/hygiene-actions.ts b/src/app/(app)/haccp/hygiene-actions.ts new file mode 100644 index 00000000..8313069a --- /dev/null +++ b/src/app/(app)/haccp/hygiene-actions.ts @@ -0,0 +1,23 @@ +"use server"; +import { revalidatePath } from "next/cache"; +import { ZodError } from "zod"; +import { requirePage } from "@/lib/auth/session"; +import { PermissionDeniedError } from "@/lib/auth/permissions"; +import { HaccpError } from "@/lib/haccp/errors"; +import { checkRecallsNow } from "@/lib/services/product-recalls"; +import type { FormState } from "@/components/ui/action-form"; + +export async function toHygieneError(e: unknown): Promise { + if (e instanceof ZodError) return { status: "error", message: [...new Set(e.issues.map((i) => i.message))].slice(0, 3).join(" · ") }; + if (e instanceof HaccpError || e instanceof PermissionDeniedError) return { status: "error", message: e.message }; + console.error("[haccp hygiène]", e); + return { status: "error", message: "Erreur technique : rien n'a été enregistré." }; +} + +export async function checkRecallsNowAction(_p: FormState, f: FormData): Promise { + const s = await requirePage("haccp.record"); + let r: { opened: number; checked: number }; + try { r = await checkRecallsNow(s.ctx, String(f.get("establishmentId") ?? "")); } catch (e) { return toHygieneError(e); } + revalidatePath("/haccp", "layout"); + return { status: "success", message: r.opened ? `${r.opened} nouveau(x) rappel(s) concerne(nt) vos produits : voir ci-dessous.` : `${r.checked} rappel(s) récent(s) comparé(s) à vos produits : aucun nouveau produit concerné.` }; +} diff --git a/src/app/(app)/haccp/rappels/page.tsx b/src/app/(app)/haccp/rappels/page.tsx new file mode 100644 index 00000000..98ff3d25 --- /dev/null +++ b/src/app/(app)/haccp/rappels/page.tsx @@ -0,0 +1,111 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { requirePage } from "@/lib/auth/session"; +import { hasPermission } from "@/lib/auth/permissions"; +import { recallOverview, type RecallRow } from "@/lib/services/product-recalls"; +import { ActionForm } from "@/components/ui/action-form"; +import { Badge, Card, CardTitle, EmptyState, Input, PageHeader } from "@/components/ui/primitives"; +import { loadScope } from "../../scope-data"; +import { closeCorrectiveActionAction } from "../auto-actions"; +import { checkRecallsNowAction } from "../hygiene-actions"; +import { EstablishmentPicker, fmtDateTime } from "../ui"; + +export const metadata: Metadata = { title: "Rappels de produits" }; + +const day = (d: Date) => new Date(d).toLocaleDateString("fr-FR", { timeZone: "Europe/Paris", day: "numeric", month: "short", year: "numeric" }); + +function RecallCard({ r, canRecord }: { r: RecallRow; canRecord: boolean }) { + return ( + +
+
+

{r.label}

+

{[r.brand, r.subcategory, `publié le ${day(r.publishedAt)}`, r.ficheNumber ? `fiche ${r.ficheNumber}` : null].filter(Boolean).join(" · ")}

+
+ {r.action ? (r.action.closedAt ? traité : à traiter) : null} +
+ {r.action?.detail &&

{r.action.detail.split(" Motif :")[0]}

} +
+ {r.reason &&
Motif :
{r.reason}
} + {r.risks &&
Risque :
{r.risks}
} + {r.references &&
Références :
{r.references.replace(/¤/g, " · ")}
} + {r.lots.length > 0 &&
Lots :
{r.lots.slice(0, 12).join(", ")}{r.lots.length > 12 ? "…" : ""}
} + {r.gtins.length > 0 &&
Codes-barres :
{r.gtins.slice(0, 6).map((g) => g.replace(/^0+(?=\d{13})/, "")).join(", ")}{r.gtins.length > 6 ? "…" : ""}
} + {r.distributors &&
Distributeurs :
{r.distributors}
} +
+ {r.ficheUrl && Fiche officielle RappelConso} + {r.action && (r.action.closedAt ? ( +

Action menée : {r.action.actionTaken}{fmtDateTime(new Date(r.action.closedAt))}

+ ) : canRecord && ( + + ))} +
+ ); +} + +export default async function RecallsPage({ searchParams }: { searchParams: Promise> }) { + const s = await requirePage("haccp.view"); + const sp = await searchParams; + const scope = await loadScope(s.ctx, sp, { allowAll: false }); + const est = scope.establishments.find((e) => e.id === scope.selection) ?? scope.establishments[0]; + const q = typeof sp.q === "string" ? sp.q : ""; + const canRecord = hasPermission(s.ctx.role, "haccp.record"); + const data = est ? await recallOverview(s.ctx, est.id, { search: q }) : null; + const open = data?.mine.filter((r) => !r.action?.closedAt) ?? []; + const closed = data?.mine.filter((r) => r.action?.closedAt) ?? []; + return ( + <> + } /> + {!est || !data ? : ( +
+
+ + +

Concernent vos produits ({open.length} à traiter)

+ {!data.mine.length ? ( + + {data.state?.lastSuccessAt ? `Dernière vérification le ${fmtDateTime(new Date(data.state.lastSuccessAt))}.` : "La veille démarre au premier passage du matin : Donnée manquante pour l'instant."} + + ) : [...open, ...closed].map((r) => )} +

{data.search ? `Résultats pour « ${data.search} »` : "Rappels alimentaires des 30 derniers jours"} ({data.recent.length})

+ {!data.recent.length ? {data.search ? "Aucune fiche récente ne correspond à cette recherche." : "Donnée manquante : la première lecture a lieu au premier passage du matin."} + : data.recent.map((r) => )} +
+
+ + Veille +
    +
  • Dernière lecture réussie : {data.state?.lastSuccessAt ? fmtDateTime(new Date(data.state.lastSuccessAt)) : "Donnée manquante"}
  • + {data.state?.lastError &&
  • Dernière erreur : {data.state.lastError}
  • } +
  • Rappels alimentaires publiés sur 30 jours : {data.last30}
  • +
+ {canRecord && ( +
+ + Chercher un produit +
+ + + +
+ {q && Effacer la recherche} +

Recherche dans les rappels de 30 jours lus par ALTAIR.

+
+
+
+ )} + + ); +} diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 270345ef..e0879af4 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -1734,6 +1734,9 @@ export const temperatureReadings = pgTable("temperature_readings", { recordedBy: uuid("recorded_by").references(() => users.id), /** Sonde connectée à l'origine du relevé (v0.136) : hors plage, l'action corrective est ouverte au registre (haccp_corrective_actions). */ sensorId: uuid("sensor_id").references((): AnyPgColumn => temperatureSensors.id, { onDelete: "restrict" }), + /** Relevé saisi sans réseau (v0.170) : identifiant tiré par l'appareil (renvoi sans doublon) ; l'heure est celle de la saisie. */ + clientRef: uuid("client_ref"), + enteredOffline: boolean("entered_offline").notNull().default(false), cancelledAt: timestamp("cancelled_at", { withTimezone: true }), cancelledBy: uuid("cancelled_by").references(() => users.id), cancelReason: text("cancel_reason"), @@ -1742,6 +1745,7 @@ export const temperatureReadings = pgTable("temperature_readings", { index("temperature_readings_est_idx").on(t.organizationId, t.establishmentId, t.readAt), index("temperature_readings_eq_idx").on(t.equipmentId, t.readAt), index("temperature_readings_sensor_idx").on(t.sensorId, t.readAt), + uniqueIndex("temperature_readings_client_ref_uq").on(t.organizationId, t.clientRef).where(sql`${t.clientRef} IS NOT NULL`), check("temperature_readings_action_ck", sql`${t.conform} OR ${t.correctiveAction} IS NOT NULL OR ${t.sensorId} IS NOT NULL`), check("temperature_readings_author_ck", sql`${t.recordedBy} IS NOT NULL OR ${t.sensorId} IS NOT NULL`), ]); @@ -1798,10 +1802,147 @@ export const haccpCorrectiveActions = pgTable("haccp_corrective_actions", { }, (t) => [ uniqueIndex("haccp_corrective_actions_dedup_uq").on(t.organizationId, t.dedupKey), index("haccp_corrective_actions_open_idx").on(t.organizationId, t.establishmentId, t.detectedAt).where(sql`${t.closedAt} IS NULL`), - check("haccp_corrective_actions_source_ck", sql`${t.source} IN ('sonde_hors_plage', 'sonde_muette', 'releves_manquants', 'nettoyage_manquant', 'date_limite', 'manuel')`), + check("haccp_corrective_actions_source_ck", sql`${t.source} IN ('sonde_hors_plage', 'sonde_muette', 'releves_manquants', 'nettoyage_manquant', 'date_limite', 'manuel', 'rappel_produit', 'nuisibles')`), check("haccp_corrective_actions_close_ck", sql`(${t.closedAt} IS NULL) = (${t.actionTaken} IS NULL) AND (${t.closedAt} IS NULL) = (${t.closedBy} IS NULL)`), ]); +/** + * Rappels de produits publiés par l'État (RappelConso, v0.170) : copie locale des fiches « alimentation », lue chaque jour + * sur l'API publique data.economie.gouv.fr (jeu rappelconso-v2-gtin-espaces), sans clé. Commune à toutes les organisations + * (aucune donnée de restaurant) ; le croisement avec les produits d'un restaurant ouvre une action corrective chez lui. + */ +export const productRecalls = pgTable("product_recalls", { + id: uuid("id").primaryKey().defaultRandom(), + /** Identifiant de la fiche chez RappelConso (champ id). */ + sourceId: integer("source_id").notNull(), + ficheNumber: text("fiche_number"), + version: integer("version"), + publishedAt: timestamp("published_at", { withTimezone: true }).notNull(), + label: text("label").notNull(), + brand: text("brand"), + subcategory: text("subcategory"), + references: text("references"), + /** Codes-barres (GTIN/EAN) et numéros de lot lus dans identification_produits. */ + gtins: text("gtins").array().notNull().default(sql`'{}'::text[]`), + lots: text("lots").array().notNull().default(sql`'{}'::text[]`), + reason: text("reason"), + risks: text("risks"), + consumerActions: text("consumer_actions"), + saleArea: text("sale_area"), + distributors: text("distributors"), + ficheUrl: text("fiche_url"), + imageUrl: text("image_url"), + endsOn: date("ends_on", { mode: "string" }), + fetchedAt: timestamp("fetched_at", { withTimezone: true }).notNull().defaultNow(), +}, (t) => [ + uniqueIndex("product_recalls_source_uq").on(t.sourceId), + index("product_recalls_published_idx").on(t.publishedAt), +]); + +/** Lutte contre les nuisibles (v0.170) : contrat du prestataire (n° Certibiocide, fréquence des visites, plan des pièges). */ +export const pestControlContracts = pgTable("pest_control_contracts", { + id: uuid("id").primaryKey().defaultRandom(), + organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }), + establishmentId: uuid("establishment_id").notNull().references(() => establishments.id, { onDelete: "cascade" }), + providerName: text("provider_name").notNull(), + /** Numéro du certificat individuel « Certibiocide » du technicien ou de l'entreprise (à vérifier par le restaurateur). */ + certibiocideNumber: text("certibiocide_number"), + contactPhone: text("contact_phone"), + contactEmail: text("contact_email"), + startsOn: date("starts_on", { mode: "string" }), + endsOn: date("ends_on", { mode: "string" }), + visitsPerYear: integer("visits_per_year"), + trapPlan: bytea("trap_plan"), + trapPlanMime: text("trap_plan_mime"), + trapPlanSize: integer("trap_plan_size"), + notes: text("notes"), + archivedAt: timestamp("archived_at", { withTimezone: true }), + createdBy: uuid("created_by").notNull().references(() => users.id), + updatedAt: timestamp("updated_at", { withTimezone: true }), + createdAt: createdAt(), +}, (t) => [ + index("pest_control_contracts_est_idx").on(t.organizationId, t.establishmentId), + check("pest_control_contracts_visits_ck", sql`${t.visitsPerYear} IS NULL OR (${t.visitsPerYear} BETWEEN 1 AND 52)`), + check("pest_control_contracts_plan_ck", sql`${t.trapPlanSize} IS NULL OR ${t.trapPlanSize} <= 5242880`), +]); + +/** + * Passage du prestataire nuisibles (v0.170) : constat, nuisibles vus, mesures, signé par le technicien sur un lien temporaire + * (empreinte du jeton seule en base, valable 7 jours). Une activité constatée ouvre une action corrective. + */ +export const pestControlVisits = pgTable("pest_control_visits", { + id: uuid("id").primaryKey().defaultRandom(), + organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }), + establishmentId: uuid("establishment_id").notNull().references(() => establishments.id, { onDelete: "cascade" }), + contractId: uuid("contract_id").references(() => pestControlContracts.id, { onDelete: "set null" }), + visitOn: date("visit_on", { mode: "string" }).notNull(), + /** contrat (visite prévue au contrat) ou curatif (appel ponctuel). */ + kind: text("kind").notNull().default("contrat"), + technicianName: text("technician_name"), + /** aucune, faible, forte (activité constatée). */ + activity: text("activity"), + pests: text("pests").array().notNull().default(sql`'{}'::text[]`), + findings: text("findings"), + actions: text("actions"), + recommendations: text("recommendations"), + products: text("products"), + signTokenHash: text("sign_token_hash"), + signTokenExpiresAt: timestamp("sign_token_expires_at", { withTimezone: true }), + signedAt: timestamp("signed_at", { withTimezone: true }), + signerName: text("signer_name"), + signature: bytea("signature"), + correctiveActionId: uuid("corrective_action_id").references(() => haccpCorrectiveActions.id, { onDelete: "set null" }), + recordedBy: uuid("recorded_by").notNull().references(() => users.id), + cancelledAt: timestamp("cancelled_at", { withTimezone: true }), + cancelledBy: uuid("cancelled_by").references(() => users.id), + cancelReason: text("cancel_reason"), + createdAt: createdAt(), +}, (t) => [ + index("pest_control_visits_est_idx").on(t.organizationId, t.establishmentId, t.visitOn), + uniqueIndex("pest_control_visits_token_uq").on(t.signTokenHash).where(sql`${t.signTokenHash} IS NOT NULL`), + check("pest_control_visits_kind_ck", sql`${t.kind} IN ('contrat', 'curatif')`), + check("pest_control_visits_activity_ck", sql`${t.activity} IS NULL OR ${t.activity} IN ('aucune', 'faible', 'forte')`), + check("pest_control_visits_signed_ck", sql`(${t.signedAt} IS NULL) = (${t.signature} IS NULL)`), +]); + +/** + * Registres HACCP scellés (v0.170) : empreinte SHA-256 du PDF exporté et jeton public de vérification (QR imprimé dans le PDF). + * Le PDF lui-même n'est pas gardé : la page /verifier/[jeton] compare l'empreinte d'un fichier présenté à celle-ci. + */ +export const haccpSealedExports = pgTable("haccp_sealed_exports", { + id: uuid("id").primaryKey().defaultRandom(), + organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }), + establishmentId: uuid("establishment_id").notNull().references(() => establishments.id, { onDelete: "cascade" }), + /** dossier (dossier HACCP complet) */ + kind: text("kind").notNull().default("dossier"), + periodFrom: date("period_from", { mode: "string" }).notNull(), + periodTo: date("period_to", { mode: "string" }).notNull(), + verifyToken: text("verify_token").notNull(), + sha256: text("sha256"), + bytes: integer("bytes"), + createdBy: uuid("created_by").notNull().references(() => users.id), + createdAt: createdAt(), +}, (t) => [ + uniqueIndex("haccp_sealed_exports_token_uq").on(t.verifyToken), + index("haccp_sealed_exports_est_idx").on(t.organizationId, t.establishmentId, t.createdAt), + check("haccp_sealed_exports_kind_ck", sql`${t.kind} IN ('dossier')`), +]); + +/** Page publique des allergènes (v0.170) : une adresse par établissement, imprimée en QR pour les clients ; désactivable. */ +export const allergenPages = pgTable("allergen_pages", { + id: uuid("id").primaryKey().defaultRandom(), + organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }), + establishmentId: uuid("establishment_id").notNull().references(() => establishments.id, { onDelete: "cascade" }), + token: text("token").notNull(), + enabled: boolean("enabled").notNull().default(true), + createdBy: uuid("created_by").notNull().references(() => users.id), + updatedAt: timestamp("updated_at", { withTimezone: true }), + createdAt: createdAt(), +}, (t) => [ + uniqueIndex("allergen_pages_token_uq").on(t.token), + uniqueIndex("allergen_pages_est_uq").on(t.establishmentId), +]); + /** Contrôles à réception des livraisons : température du camion et des produits, DLC, emballage, décision. */ export const receptionControls = pgTable("reception_controls", { id: uuid("id").primaryKey().defaultRandom(), diff --git a/src/lib/haccp/automation.ts b/src/lib/haccp/automation.ts index 8708d1ec..5c7e5031 100644 --- a/src/lib/haccp/automation.ts +++ b/src/lib/haccp/automation.ts @@ -92,6 +92,8 @@ export const CORRECTIVE_SOURCES = [ { code: "nettoyage_manquant", label: "Nettoyage non fait" }, { code: "date_limite", label: "Date limite dépassée en stock" }, { code: "manuel", label: "Signalée par l'équipe" }, + { code: "rappel_produit", label: "Rappel de produit (RappelConso)" }, + { code: "nuisibles", label: "Nuisibles constatés" }, ] as const; export type CorrectiveSource = (typeof CORRECTIVE_SOURCES)[number]["code"]; export const correctiveSourceLabel = (c: string) => CORRECTIVE_SOURCES.find((s) => s.code === c)?.label ?? c; diff --git a/src/lib/haccp/recalls.ts b/src/lib/haccp/recalls.ts new file mode 100644 index 00000000..9c507b61 --- /dev/null +++ b/src/lib/haccp/recalls.ts @@ -0,0 +1,135 @@ +/** + * RappelConso (v0.170) : lecture des fiches publiques et croisement avec les produits d'un restaurant. + * Fonctions pures (aucun accès base ni réseau) : testées dans tests/unit/recalls.test.ts. + * + * Source : API Explore v2.1 de data.economie.gouv.fr, jeu « rappelconso-v2-gtin-espaces » (vérifiée le 01/12/2026, + * INTEGRATION_REGISTRY.md). Champ identification_produits : « GTIN$lot$type de date$date$ » par produit. + */ + +export const RAPPELCONSO_DATASET = "rappelconso-v2-gtin-espaces"; +export const RAPPELCONSO_API = `https://data.economie.gouv.fr/api/explore/v2.1/catalog/datasets/${RAPPELCONSO_DATASET}/records`; + +/** Fiche telle que renvoyée par l'API (champs utilisés seulement ; tout est facultatif côté source). */ +export type RawRecall = { + id?: number | null; numero_fiche?: string | null; numero_version?: number | null; date_publication?: string | null; + categorie_produit?: string | null; sous_categorie_produit?: string | null; marque_produit?: string | null; + modeles_ou_references?: string | null; identification_produits?: string[] | string | null; libelle?: string | null; + motif_rappel?: string | null; risques_encourus?: string | null; conduites_a_tenir_par_le_consommateur?: string | null; + zone_geographique_de_vente?: string | null; distributeurs?: string | null; lien_vers_la_fiche_rappel?: string | null; + liens_vers_les_images?: string | null; date_de_fin_de_la_procedure_de_rappel?: string | null; +}; + +export type ParsedRecall = { + sourceId: number; ficheNumber: string | null; version: number | null; publishedAt: Date; label: string; brand: string | null; + subcategory: string | null; references: string | null; gtins: string[]; lots: string[]; reason: string | null; risks: string | null; + consumerActions: string | null; saleArea: string | null; distributors: string | null; ficheUrl: string | null; imageUrl: string | null; endsOn: string | null; +}; + +const clean = (v: unknown, max = 2000): string | null => { + if (typeof v !== "string") return null; + const t = v.replace(/\s+/g, " ").trim(); + return t ? t.slice(0, max) : null; +}; +const httpsOnly = (v: string | null) => (v && /^https:\/\/[^\s]+$/i.test(v) ? v : null); + +/** Ne garde que les chiffres ; un GTIN valide a 8, 12, 13 ou 14 chiffres. */ +export function normalizeGtin(v: string | null | undefined): string | null { + const d = (v ?? "").replace(/\D/g, ""); + if (![8, 12, 13, 14].includes(d.length)) return null; + // Forme commune sur 14 chiffres : un EAN-13 et le même GTIN-14 préfixé de 0 se comparent. + return d.padStart(14, "0"); +} + +/** Numéro de lot comparable : majuscules, sans espaces ni ponctuation. Trop court (moins de 3 caractères) : ignoré. */ +export function normalizeLot(v: string | null | undefined): string | null { + const t = (v ?? "").toUpperCase().replace(/[^0-9A-Z]/g, ""); + return t.length >= 3 ? t : null; +} + +/** Transforme une fiche brute ; renvoie null si elle est inutilisable (sans identifiant, date ou libellé) ou hors alimentation. */ +export function parseRecall(r: RawRecall): ParsedRecall | null { + if (typeof r.id !== "number" || !Number.isInteger(r.id)) return null; + if ((r.categorie_produit ?? "").toLowerCase().trim() !== "alimentation") return null; + const publishedAt = r.date_publication ? new Date(r.date_publication) : null; + if (!publishedAt || Number.isNaN(publishedAt.getTime())) return null; + const label = clean(r.libelle, 300) ?? clean(r.modeles_ou_references, 300); + if (!label) return null; + const ids = Array.isArray(r.identification_produits) ? r.identification_produits : typeof r.identification_produits === "string" ? [r.identification_produits] : []; + const gtins = new Set(), lots = new Set(); + for (const line of ids) { + if (typeof line !== "string") continue; + const [gtin, lot] = line.split("$"); + const g = normalizeGtin(gtin); + if (g) gtins.add(g); + // Un même champ peut porter plusieurs lots séparés par des espaces, virgules ou points-virgules. + for (const part of (lot ?? "").split(/[;,]| et /i)) { const l = normalizeLot(part); if (l) lots.add(l); } + } + const endsOn = clean(r.date_de_fin_de_la_procedure_de_rappel, 30); + return { + sourceId: r.id, ficheNumber: clean(r.numero_fiche, 40), version: typeof r.numero_version === "number" ? r.numero_version : null, publishedAt, label, + brand: clean(r.marque_produit, 200), subcategory: clean(r.sous_categorie_produit, 200), references: clean(r.modeles_ou_references, 1000), + gtins: [...gtins].slice(0, 200), lots: [...lots].slice(0, 500), reason: clean(r.motif_rappel), risks: clean(r.risques_encourus), + consumerActions: clean(r.conduites_a_tenir_par_le_consommateur, 600)?.replace(/\|/g, " · ") ?? null, + saleArea: clean(r.zone_geographique_de_vente, 600), distributors: clean(r.distributeurs, 1000), + ficheUrl: httpsOnly(clean(r.lien_vers_la_fiche_rappel, 500)), imageUrl: httpsOnly(clean(r.liens_vers_les_images?.split("|")[0], 500)), + endsOn: endsOn && /^\d{4}-\d{2}-\d{2}/.test(endsOn) ? endsOn.slice(0, 10) : null, + }; +} + +const STOP = new Set(["avec", "sans", "pour", "dans", "aux", "des", "les", "une", "sur", "par", "the", "and", "produit", "produits", "lot", "lots", + "frais", "fraiche", "fraiches", "nature", "sachet", "barquette", "boite", "pack", "gamme", "marque", "plusieurs", "references", "reference", "divers"]); + +/** Mots significatifs (4 lettres et plus, sans accents ni mots outils). */ +export function keywords(v: string | null | undefined): Set { + const out = new Set(); + for (const w of (v ?? "").toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").split(/[^a-z0-9]+/)) { + if (w.length >= 4 && !STOP.has(w) && !/^\d+$/.test(w)) out.add(w.endsWith("s") && w.length > 4 ? w.slice(0, -1) : w); + } + return out; +} + +export type RecallProduct = { + kind: "produit" | "etiquette" | "lot_stock"; + id: string; name: string; brand?: string | null; barcode?: string | null; lot?: string | null; when?: string | null; +}; +export type RecallMatch = { strength: "certain" | "probable" | "a_verifier"; reasons: string[]; products: RecallProduct[] }; + +/** + * Croise une fiche avec les produits d'un établissement : + * - même code-barres : « certain » si le lot correspond aussi ou si la fiche n'en cite pas, sinon « probable » ; + * - même numéro de lot seul (étiquette photographiée, lot en stock) : « probable » ; + * - même marque et au moins un mot du libellé sur une étiquette reçue : « à vérifier ». + * Rien du tout : null (aucune alerte). + */ +export function matchRecall(recall: Pick, products: RecallProduct[]): RecallMatch | null { + const gtins = new Set(recall.gtins), lots = new Set(recall.lots); + const brandKw = keywords(recall.brand); + const labelKw = new Set([...keywords(recall.label), ...keywords(recall.references)]); + for (const b of brandKw) labelKw.delete(b); + const hits: { p: RecallProduct; s: RecallMatch["strength"]; why: string }[] = []; + for (const p of products) { + const g = normalizeGtin(p.barcode); + const l = normalizeLot(p.lot); + const lotHit = !!l && lots.has(l); + if (g && gtins.has(g)) { + hits.push({ p, s: lotHit || !lots.size ? "certain" : "probable", why: lotHit ? `code-barres et lot ${p.lot} identiques` : `code-barres ${p.barcode} identique${lots.size ? " (lot à contrôler)" : ""}` }); + continue; + } + if (lotHit) { hits.push({ p, s: "probable", why: `lot ${p.lot} identique` }); continue; } + if (p.kind === "etiquette" && brandKw.size && labelKw.size) { + const pb = keywords(p.brand); + const sameBrand = [...brandKw].some((w) => pb.has(w)); + const nameKw = keywords(p.name); + const common = [...labelKw].filter((w) => nameKw.has(w)); + if (sameBrand && common.length) hits.push({ p, s: "a_verifier", why: `même marque et « ${common.slice(0, 3).join(", ")} » dans le nom` }); + } + } + if (!hits.length) return null; + const order = { certain: 0, probable: 1, a_verifier: 2 } as const; + hits.sort((a, b) => order[a.s] - order[b.s]); + const seen = new Set(); + const products2 = hits.filter((h) => !seen.has(`${h.p.kind}:${h.p.id}`) && seen.add(`${h.p.kind}:${h.p.id}`)); + return { strength: hits[0]!.s, reasons: [...new Set(products2.map((h) => `${h.p.name} : ${h.why}`))].slice(0, 8), products: products2.map((h) => h.p).slice(0, 20) }; +} + +export const STRENGTH_LABEL: Record = { certain: "Concerné", probable: "Probablement concerné", a_verifier: "À vérifier" }; diff --git a/src/lib/notify/catalog.ts b/src/lib/notify/catalog.ts index 058d8ae8..e195d831 100644 --- a/src/lib/notify/catalog.ts +++ b/src/lib/notify/catalog.ts @@ -50,6 +50,9 @@ export const CATEGORIES: readonly Category[] = [ { code: "maintenance", label: "Pannes et réparations", description: "Panne signalée, devis à valider, devis validé ou refusé, facture rattachée, panne réparée.", kinds: ["panne_signalee", "devis_a_valider", "devis_decide", "facture_rattachee", "panne_reparee"], channels: { in_app: on, email: on, push: on, sms: off } }, + { code: "hygiene", label: "Hygiène : rappels de produits et nuisibles", description: "Produit acheté rappelé par l'État (RappelConso), nuisibles signalés lors d'un passage du prestataire.", + kinds: ["rappel_produit", "nuisibles_activite"], + channels: { in_app: on, email: on, push: on, sms: off } }, { code: "courrier", label: "Boîte mail (factures reçues)", description: "Facture ou attestation reçue par e-mail à vérifier, boîte Gmail en échec.", kinds: ["facture_recue", "document_recu", "boite_mail_erreur"], channels: { in_app: on, email: on, push: on, sms: off } }, diff --git a/src/lib/scheduler.ts b/src/lib/scheduler.ts index 90314ba7..bacb382c 100644 --- a/src/lib/scheduler.ts +++ b/src/lib/scheduler.ts @@ -13,6 +13,7 @@ import { runHaccpAutomation } from "@/lib/services/haccp-corrective"; import { runClockAutoApply } from "@/lib/services/clock"; import { runAutoSyncs } from "@/lib/services/connect"; import { runContextSync } from "@/lib/services/context-data"; +import { runRecallWatch } from "@/lib/services/product-recalls"; import { runSignatureReminders } from "@/lib/services/signatures"; import { runGoogleReviews } from "@/lib/services/google-business"; import { runGooglePosts } from "@/lib/services/google-posts"; @@ -93,6 +94,12 @@ export async function tick(now = new Date()) { const cx = await runContextSync(now, { hour: parisHour(now) }); if (cx.insee !== null || cx.meteo !== null) console.info(`[planificateur] données publiques : INSEE ${cx.insee ?? "—"}, Météo-France ${cx.meteo ?? "—"}`); } catch (e) { console.error("[planificateur] données publiques", e); } + // Veille RappelConso (v0.170) : rappels « alimentation » lus une fois par jour (après 6 h), croisés à chaque passe avec + // les produits de chaque établissement ; un produit concerné ouvre une action corrective HACCP et prévient les responsables. + try { + const rc = await runRecallWatch(now, { hour: parisHour(now) }); + if (rc.fetched !== null || rc.opened) console.info(`[planificateur] RappelConso : ${rc.fetched ?? "—"} fiche(s) lue(s), ${rc.opened} établissement(s) concerné(s)`); + } catch (e) { console.error("[planificateur] RappelConso", e); } // ALTAIR Mail (v0.160) : boîtes Gmail reliées lues toutes les 30 minutes (factures, devis, attestations repérés). try { const mb = await runMailboxSyncs(now); diff --git a/src/lib/services/product-recalls.ts b/src/lib/services/product-recalls.ts new file mode 100644 index 00000000..888fbe33 --- /dev/null +++ b/src/lib/services/product-recalls.ts @@ -0,0 +1,184 @@ +/** + * Veille RappelConso (v0.170) : copie quotidienne des rappels « alimentation » publiés par l'État, puis croisement avec les + * produits de chaque établissement (codes-barres du catalogue, lots en stock, étiquettes photographiées à la réception). + * Un produit concerné ouvre une action corrective HACCP (source « rappel_produit », une seule par rappel et par établissement) + * et prévient les responsables HACCP. Rien n'est jamais retiré du stock automatiquement : la décision reste à l'équipe. + * + * Réseau : API publique sans clé (data.economie.gouv.fr). Jamais appelée pendant les tests sans lecture simulée fournie. + */ +import { and, desc, eq, gte, ilike, inArray, isNull, or, sql } from "drizzle-orm"; +import { db as defaultDb, schema, type DB } from "@/lib/db/pool"; +import { assertPermission, type AccessContext } from "@/lib/auth/permissions"; +import { RAPPELCONSO_API, STRENGTH_LABEL, keywords, matchRecall, parseRecall, type ParsedRecall, type RawRecall, type RecallMatch, type RecallProduct } from "@/lib/haccp/recalls"; +import { HaccpError } from "@/lib/haccp/errors"; +import { openCorrectiveActionTx } from "./haccp-corrective"; +import { dispatchNotification, membersWith } from "./notification-center"; +import { requireEstablishment } from "./scope"; + +type Fetch = typeof fetch; +const RC = schema.productRecalls, CA = schema.haccpCorrectiveActions; +const SOURCE = "rappelconso"; +const UA = { "User-Agent": "ALTAIR-restaurant-os (veille RappelConso)", Accept: "application/json" }; +/** Fenêtre de croisement : rappels publiés depuis 90 jours (un produit reçu il y a plus longtemps a été consommé). */ +export const MATCH_WINDOW_DAYS = 90; +/** Produits pris en compte : reçus, photographiés ou en stock depuis 120 jours. */ +const PRODUCT_WINDOW_DAYS = 120; +const MIN_INTERVAL_MS = 20 * 3600_000; + +async function markSource(dbx: DB, ok: boolean, rows: number | null, error: string | null, now: Date) { + const t = schema.contextSources; + await dbx.insert(t).values({ source: SOURCE, lastAttemptAt: now, lastSuccessAt: ok ? now : null, lastError: error, rows }) + .onConflictDoUpdate({ target: t.source, set: { lastAttemptAt: now, lastError: error, ...(ok ? { lastSuccessAt: now, rows } : {}) } }); +} + +/** Lit les fiches publiées depuis `since` (AAAA-MM-JJ) et les enregistre (une fiche mise à jour remplace l'ancienne version). */ +export async function syncRecalls(fetchImpl: Fetch, dbx: DB, now: Date, since: string): Promise { + let saved = 0; + for (let offset = 0; offset < 5000; offset += 100) { + const q = new URLSearchParams({ + where: `categorie_produit="alimentation" and date_publication>=date'${since}'`, + order_by: "date_publication desc", limit: "100", offset: String(offset), + }); + const res = await fetchImpl(`${RAPPELCONSO_API}?${q}`, { headers: UA, signal: AbortSignal.timeout(30_000) }); + if (!res.ok) throw new Error(`RappelConso : HTTP ${res.status}`); + const body = (await res.json()) as { total_count?: number; results?: RawRecall[] }; + const rows = (body.results ?? []).map(parseRecall).filter((r): r is ParsedRecall => !!r); + for (const r of rows) { + await dbx.insert(RC).values({ ...r, fetchedAt: now }).onConflictDoUpdate({ target: RC.sourceId, set: { ...r, fetchedAt: now } }); + saved++; + } + if (!body.results?.length || offset + 100 >= (body.total_count ?? 0)) break; + } + return saved; +} + +/** Produits d'un établissement à croiser : étiquettes photographiées, lots en stock, catalogue avec code-barres. */ +export async function establishmentProducts(dbx: DB, organizationId: string, establishmentId: string, now: Date): Promise { + const since = new Date(now.getTime() - PRODUCT_WINDOW_DAYS * 86_400_000); + const sinceDay = since.toISOString().slice(0, 10); + const I = schema.purchaseItems, T = schema.traceLabels, L = schema.stockExpiryLots; + const labels = await dbx.select({ id: T.id, name: T.productLabel, brand: T.brand, lot: T.lotNumber, when: T.takenAt, barcode: I.barcode }) + .from(T).leftJoin(I, eq(I.id, T.itemId)) + .where(and(eq(T.organizationId, organizationId), eq(T.establishmentId, establishmentId), isNull(T.cancelledAt), gte(T.takenAt, since))); + const lots = await dbx.select({ id: L.id, name: I.name, lot: L.lotNumber, when: L.receivedOn, barcode: I.barcode }) + .from(L).innerJoin(I, eq(I.id, L.itemId)) + .where(and(eq(L.organizationId, organizationId), eq(L.establishmentId, establishmentId), or(isNull(L.closedAt), gte(L.receivedOn, sinceDay)))); + const items = await dbx.select({ id: I.id, name: I.name, barcode: I.barcode }).from(I) + .where(and(eq(I.organizationId, organizationId), isNull(I.archivedAt), sql`${I.barcode} IS NOT NULL`)); + return [ + ...labels.map((l) => ({ kind: "etiquette" as const, id: l.id, name: l.name, brand: l.brand, lot: l.lot, barcode: l.barcode, when: new Date(l.when).toISOString().slice(0, 10) })), + ...lots.map((l) => ({ kind: "lot_stock" as const, id: l.id, name: l.name, lot: l.lot, barcode: l.barcode, when: l.when })), + ...items.map((i) => ({ kind: "produit" as const, id: i.id, name: i.name, barcode: i.barcode })), + ]; +} + +const fmtDay = (d: Date) => d.toLocaleDateString("fr-FR", { timeZone: "Europe/Paris" }); + +function detailOf(r: typeof RC.$inferSelect, m: RecallMatch) { + return [ + `${STRENGTH_LABEL[m.strength]} : ${m.reasons.join(" ; ")}.`, + r.reason ? `Motif : ${r.reason}.` : null, + r.risks ? `Risque : ${r.risks}.` : null, + "À faire : vérifier le stock (réserve, chambre froide, préparations), isoler et ne pas servir le produit concerné, noter le lot, contacter le fournisseur.", + r.ficheUrl ? `Fiche officielle : ${r.ficheUrl}` : null, + ].filter(Boolean).join(" "); +} + +/** + * Croise les rappels récents avec chaque établissement (toutes organisations, planificateur) : ouvre une action corrective + * par rappel et par établissement concerné, et prévient les responsables HACCP. Idempotent (clé de déduplication). + */ +export async function matchRecallsForAll(now = new Date(), dbx: DB = defaultDb, only?: { organizationId: string }) { + const recent = await dbx.select().from(RC).where(gte(RC.publishedAt, new Date(now.getTime() - MATCH_WINDOW_DAYS * 86_400_000))); + const ests = await dbx.select({ id: schema.establishments.id, org: schema.establishments.organizationId, name: schema.establishments.name }) + .from(schema.establishments).innerJoin(schema.organizations, eq(schema.organizations.id, schema.establishments.organizationId)) + .where(only ? eq(schema.establishments.organizationId, only.organizationId) : sql`true`); + let opened = 0; + if (!recent.length) return { opened, checked: 0 }; + for (const e of ests) { + const products = await establishmentProducts(dbx, e.org, e.id, now); + if (!products.length) continue; + for (const r of recent) { + const m = matchRecall(r, products); + if (!m) continue; + const dedupKey = `rappel:${r.id}:${e.id}`; + const [already] = await dbx.select({ id: CA.id }).from(CA).where(and(eq(CA.organizationId, e.org), eq(CA.dedupKey, dedupKey))); + if (already) continue; + await dbx.transaction(async (tx) => { + await openCorrectiveActionTx(tx, { organizationId: e.org, establishmentId: e.id, source: "rappel_produit", sourceId: r.id, dedupKey, + title: `Rappel produit (${STRENGTH_LABEL[m.strength].toLowerCase()}) : ${r.label}${r.brand ? ` · ${r.brand}` : ""}`, detail: detailOf(r, m), detectedAt: now }); + const who = await membersWith(tx, e.org, "haccp.manage", e.id); + await dispatchNotification(tx, e.org, who, { category: "hygiene", kind: "rappel_produit", + title: `${e.name} : produit rappelé ${m.strength === "a_verifier" ? "à vérifier" : "dans vos achats"}`, body: `${r.label}${r.brand ? ` (${r.brand})` : ""} · publié le ${fmtDay(r.publishedAt)}`, + href: `/haccp/rappels?e=${e.id}` }); + }); + opened++; + } + } + return { opened, checked: recent.length }; +} + +/** Passe du planificateur : lecture au plus une fois toutes les 20 h (après 6 h), puis croisement. Ne lève jamais. */ +export async function runRecallWatch(now = new Date(), opts: { fetchImpl?: Fetch; hour?: number; force?: boolean } = {}, dbx: DB = defaultDb) { + if (process.env.ALTAIR_RAPPELCONSO === "off" || (process.env.NODE_ENV === "test" && !opts.fetchImpl)) return { fetched: null, opened: 0 }; + if (!opts.force && (opts.hour ?? 12) < 6) return { fetched: null, opened: 0 }; + const [state] = await dbx.select().from(schema.contextSources).where(eq(schema.contextSources.source, SOURCE)); + let fetched: number | null = null; + const due = opts.force || !state || (!(state.lastError && state.lastAttemptAt && now.getTime() - state.lastAttemptAt.getTime() < 3 * 3600_000) + && (!state.lastSuccessAt || now.getTime() - state.lastSuccessAt.getTime() >= MIN_INTERVAL_MS)); + if (due) { + // Première lecture : 90 jours ; ensuite depuis la dernière réussite moins 3 jours (fiches mises à jour). + const from = state?.lastSuccessAt ? new Date(state.lastSuccessAt.getTime() - 3 * 86_400_000) : new Date(now.getTime() - MATCH_WINDOW_DAYS * 86_400_000); + try { + fetched = await syncRecalls(opts.fetchImpl ?? fetch, dbx, now, from.toISOString().slice(0, 10)); + await markSource(dbx, true, fetched, null, now); + } catch (e) { + await markSource(dbx, false, null, String((e as Error).message ?? e).slice(0, 300), now); + console.error("[rappelconso]", e); + } + } + // Le croisement tourne à chaque passe : une étiquette photographiée aujourd'hui est comparée aux rappels déjà connus. + let opened = 0; + try { opened = (await matchRecallsForAll(now, dbx)).opened; } catch (e) { console.error("[rappelconso] croisement", e); } + return { fetched, opened }; +} + +export type RecallRow = typeof RC.$inferSelect & { action: { id: string; closedAt: Date | null; actionTaken: string | null; title: string; detail: string | null } | null }; + +/** Page « Rappels produits » : rappels qui concernent l'établissement, rappels récents, état de la veille. */ +export async function recallOverview(ctx: AccessContext, establishmentId: string, opts: { search?: string | null; days?: number } = {}, dbx: DB = defaultDb) { + assertPermission(ctx, "haccp.view"); + await requireEstablishment(ctx, establishmentId, dbx); + const actions = await dbx.select().from(CA).where(and(eq(CA.organizationId, ctx.organizationId), eq(CA.establishmentId, establishmentId), eq(CA.source, "rappel_produit"))) + .orderBy(desc(CA.detectedAt)).limit(200); + const ids = [...new Set(actions.map((a) => a.sourceId).filter((x): x is string => !!x))]; + const concerned = ids.length ? await dbx.select().from(RC).where(inArray(RC.id, ids)) : []; + const byId = new Map(concerned.map((r) => [r.id, r])); + const mine = actions.filter((a) => a.sourceId && byId.has(a.sourceId)).map((a) => ({ ...byId.get(a.sourceId!)!, action: { id: a.id, closedAt: a.closedAt, actionTaken: a.actionTaken, title: a.title, detail: a.detail } })); + const days = Math.min(Math.max(opts.days ?? 30, 1), 365); + const s = (opts.search ?? "").trim().slice(0, 80); + const where = [gte(RC.publishedAt, new Date(Date.now() - days * 86_400_000))]; + if (s) { + const like = `%${s.replace(/[%_\\]/g, (c) => `\\${c}`)}%`; + const digits = s.replace(/\D/g, ""); + where.push(or(ilike(RC.label, like), ilike(RC.brand, like), ilike(RC.references, like), ilike(RC.subcategory, like), + ...(digits.length >= 8 ? [sql`${digits.padStart(14, "0")} = ANY(${RC.gtins})`] : []))!); + } + const recent = await dbx.select().from(RC).where(and(...where)).orderBy(desc(RC.publishedAt)).limit(s ? 100 : 60); + const [state] = await dbx.select().from(schema.contextSources).where(eq(schema.contextSources.source, SOURCE)); + const [cnt] = await dbx.select({ n: sql`count(*)::int` }).from(RC).where(gte(RC.publishedAt, new Date(Date.now() - 30 * 86_400_000))); + const n = cnt?.n ?? 0; + return { mine, recent: recent.map((r) => ({ ...r, action: null })) as RecallRow[], state: state ?? null, last30: n, search: s }; +} + +/** Vérification à la demande (bouton « Vérifier maintenant ») : croise les rappels connus avec cet établissement. */ +export async function checkRecallsNow(ctx: AccessContext, establishmentId: string, now = new Date(), dbx: DB = defaultDb) { + assertPermission(ctx, "haccp.record"); + await requireEstablishment(ctx, establishmentId, dbx); + const known = await dbx.select({ n: sql`count(*)::int` }).from(RC); + if (!known[0]?.n) throw new HaccpError("Aucun rappel lu pour l'instant : la veille RappelConso lit les fiches chaque matin (Donnée manquante)."); + return matchRecallsForAll(now, dbx, { organizationId: ctx.organizationId }); +} + +/** Mots d'un produit, exposés pour l'aide à la recherche (tests). */ +export const productKeywords = (name: string) => [...keywords(name)]; diff --git a/tests/integration/product-recalls.test.ts b/tests/integration/product-recalls.test.ts new file mode 100644 index 00000000..32c02b61 --- /dev/null +++ b/tests/integration/product-recalls.test.ts @@ -0,0 +1,83 @@ +import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { and, eq } from "drizzle-orm"; +import { db, pool, schema } from "@/lib/db/pool"; +import { createCompany, createEstablishment } from "@/lib/services/structure"; +import { createProduct } from "@/lib/services/products"; +import { recordTrace } from "@/lib/services/haccp-trace"; +import { checkRecallsNow, recallOverview, runRecallWatch } from "@/lib/services/product-recalls"; +import { closeCorrectiveAction } from "@/lib/services/haccp-corrective"; +import { makeTenant, resetTestDatabase } from "./helpers"; + +let A: Awaited>, B: Awaited>; +let est: string, estB: string; +const now = new Date("2026-12-01T09:00:00Z"); + +const record = (over: Record) => ({ + id: 1, numero_fiche: "2026-12-0001", numero_version: 1, date_publication: "2026-11-30T10:00:00+00:00", categorie_produit: "alimentation", + sous_categorie_produit: "lait et produits laitiers", marque_produit: "Fromagerie Dupont", libelle: "Comté AOP 18 mois", + identification_produits: ["3760001234565$L2401$date limite de consommation$2026-12-20$"], motif_rappel: "listeria", risques_encourus: "listériose", + lien_vers_la_fiche_rappel: "https://rappel.conso.gouv.fr/fiche-rappel/1/interne", ...over, +}); +const fakeFetch = (results: unknown[]) => (async (url: string | URL | Request) => { + expect(String(url)).toContain("data.economie.gouv.fr"); + return new Response(JSON.stringify({ total_count: results.length, results }), { status: 200, headers: { "content-type": "application/json" } }); +}) as typeof fetch; + +beforeAll(async () => { + await resetTestDatabase(); + A = await makeTenant("Rappels"); + B = await makeTenant("Voisin"); + const co = await createCompany(A.ctx, { legalName: "Rappels SAS" }); + est = (await createEstablishment(A.ctx, { companyId: co.id, name: "Le Comptoir" })).id; + const coB = await createCompany(B.ctx, { legalName: "Voisin SAS" }); + estB = (await createEstablishment(B.ctx, { companyId: coB.id, name: "Chez le voisin" })).id; + await createProduct(A.ctx, { name: "Comté 18 mois", unit: "kg", category: "food", barcode: "3760001234565" }); + await recordTrace(A.ctx, { establishmentId: est, productLabel: "Yaourt nature brebis", brand: "Ferme Martin", usage: "reception", lotNumber: "A77" }, null); + await recordTrace(B.ctx, { establishmentId: estB, productLabel: "Beurre doux", brand: "Laiterie X", usage: "reception", lotNumber: "B12" }, null); +}); +afterAll(async () => { await pool.end(); }); + +describe("veille RappelConso", () => { + it("lit les fiches et ouvre une action corrective seulement chez le restaurant concerné", async () => { + const r = await runRecallWatch(now, { fetchImpl: fakeFetch([record({}), record({ id: 2, libelle: "Yaourt brebis vanille", marque_produit: "Ferme Martin", identification_produits: [] }), record({ id: 3, categorie_produit: "maison-habitat" })]), force: true }); + expect(r.fetched).toBe(2); + expect(r.opened).toBe(2); + const acts = await db.select().from(schema.haccpCorrectiveActions).where(eq(schema.haccpCorrectiveActions.source, "rappel_produit")); + expect(acts.every((a) => a.organizationId === A.ctx.organizationId)).toBe(true); + expect(acts.map((a) => a.title).sort()).toEqual([ + "Rappel produit (probablement concerné) : Comté AOP 18 mois · Fromagerie Dupont", + "Rappel produit (à vérifier) : Yaourt brebis vanille · Ferme Martin", + ]); + const notes = await db.select().from(schema.notifications).where(eq(schema.notifications.kind, "rappel_produit")); + expect(notes.length).toBeGreaterThan(0); + }); + it("ne rouvre rien au passage suivant (une action par rappel et par établissement)", async () => { + const r = await runRecallWatch(new Date(now.getTime() + 3600_000), { fetchImpl: fakeFetch([record({})]), force: true }); + expect(r.opened).toBe(0); + await expect(checkRecallsNow(A.ctx, est, now)).resolves.toMatchObject({ opened: 0 }); + }); + it("affiche les rappels concernés, la recherche et l'état de la veille ; isolé par organisation", async () => { + const o = await recallOverview(A.ctx, est, { search: "comté", days: 365 }); + expect(o.mine).toHaveLength(2); + expect(o.recent.map((x) => x.label)).toEqual(["Comté AOP 18 mois"]); + expect(o.state?.lastSuccessAt).toBeTruthy(); + const byCode = await recallOverview(A.ctx, est, { search: "3760001234565", days: 365 }); + expect(byCode.recent).toHaveLength(1); + const ob = await recallOverview(B.ctx, estB, { days: 365 }); + expect(ob.mine).toHaveLength(0); + await expect(recallOverview(B.ctx, est)).rejects.toThrow(); + }); + it("la clôture garde l'action menée", async () => { + const [a] = await db.select().from(schema.haccpCorrectiveActions).where(and(eq(schema.haccpCorrectiveActions.source, "rappel_produit"), eq(schema.haccpCorrectiveActions.establishmentId, est))); + await closeCorrectiveAction(A.ctx, a!.id, "Stock vérifié : lot non présent"); + const o = await recallOverview(A.ctx, est, { days: 365 }); + expect(o.mine.find((x) => x.action?.id === a!.id)?.action?.closedAt).toBeTruthy(); + }); + it("note l'erreur sans rien casser quand la source est injoignable", async () => { + const down = (async () => new Response("", { status: 503 })) as typeof fetch; + const r = await runRecallWatch(now, { fetchImpl: down, force: true }); + expect(r.fetched).toBeNull(); + const [s] = await db.select().from(schema.contextSources).where(eq(schema.contextSources.source, "rappelconso")); + expect(s?.lastError).toMatch(/503/); + }); +}); diff --git a/tests/unit/recalls.test.ts b/tests/unit/recalls.test.ts new file mode 100644 index 00000000..66eadb3c --- /dev/null +++ b/tests/unit/recalls.test.ts @@ -0,0 +1,62 @@ +import { describe, expect, it } from "vitest"; +import { keywords, matchRecall, normalizeGtin, normalizeLot, parseRecall, type RecallProduct } from "@/lib/haccp/recalls"; + +const raw = { + id: 24226, numero_fiche: "2026-12-0001", numero_version: 1, date_publication: "2026-12-01T15:51:28+00:00", + categorie_produit: "alimentation", sous_categorie_produit: "plats préparés et snacks", marque_produit: "traiteur leclerc", + modeles_ou_references: "pizza maroilles (200001328866)¤pizza montagnarde (2000001328941)", + identification_produits: ["2000001328866$28/11/2026$date limite de consommation$2026-12-02$", "3250391631513$6 3130348$date limite de consommation$2026-12-04$"], + libelle: "pizza maroilles et pizza montagnarde", motif_rappel: "risque bactériologique", risques_encourus: "bacillus cereus", + conduites_a_tenir_par_le_consommateur: "ne plus consommer|rapporter le produit au point de vente", + lien_vers_la_fiche_rappel: "https://rappel.conso.gouv.fr/fiche-rappel/24226/interne", liens_vers_les_images: "https://rappel.conso.gouv.fr/image/a.jpg|https://x/b.jpg", +}; + +describe("RappelConso : lecture des fiches", () => { + it("lit codes-barres, lots, liens et conduite à tenir", () => { + const r = parseRecall(raw)!; + expect(r.sourceId).toBe(24226); + expect(r.gtins).toEqual(["02000001328866", "03250391631513"]); + expect(r.lots).toContain("28112026"); + expect(r.lots).toContain("63130348"); + expect(r.consumerActions).toBe("ne plus consommer · rapporter le produit au point de vente"); + expect(r.imageUrl).toBe("https://rappel.conso.gouv.fr/image/a.jpg"); + }); + it("écarte les fiches hors alimentation ou incomplètes", () => { + expect(parseRecall({ ...raw, categorie_produit: "maison-habitat" })).toBeNull(); + expect(parseRecall({ ...raw, id: null })).toBeNull(); + expect(parseRecall({ ...raw, date_publication: "n'importe quoi" })).toBeNull(); + expect(parseRecall({ ...raw, libelle: null, modeles_ou_references: null })).toBeNull(); + }); + it("refuse un lien non https", () => { + expect(parseRecall({ ...raw, lien_vers_la_fiche_rappel: "javascript:alert(1)" })!.ficheUrl).toBeNull(); + }); + it("normalise GTIN et lots", () => { + expect(normalizeGtin("3 250391 631513")).toBe("03250391631513"); + expect(normalizeGtin("123")).toBeNull(); + expect(normalizeLot(" l-24 ")).toBe("L24"); + expect(normalizeLot("ab")).toBeNull(); + expect([...keywords("Pizzas Montagnardes au fromage")]).toEqual(["pizza", "montagnarde", "fromage"]); + }); +}); + +describe("RappelConso : croisement avec les produits", () => { + const r = parseRecall(raw)!; + it("même code-barres et même lot : concerné", () => { + const p: RecallProduct[] = [{ kind: "etiquette", id: "1", name: "Ravioles", barcode: "3250391631513", lot: "6 3130348" }]; + expect(matchRecall(r, p)?.strength).toBe("certain"); + }); + it("même code-barres, autre lot : probable", () => { + const p: RecallProduct[] = [{ kind: "produit", id: "1", name: "Ravioles", barcode: "3250391631513", lot: "999999" }]; + expect(matchRecall(r, p)?.strength).toBe("probable"); + }); + it("même marque et un mot du nom sur une étiquette : à vérifier", () => { + const p: RecallProduct[] = [{ kind: "etiquette", id: "2", name: "Pizza montagnarde", brand: "Traiteur Leclerc" }]; + const m = matchRecall(r, p)!; + expect(m.strength).toBe("a_verifier"); + expect(m.reasons[0]).toMatch(/même marque/); + }); + it("rien en commun : aucune alerte", () => { + expect(matchRecall(r, [{ kind: "etiquette", id: "3", name: "Pizza montagnarde", brand: "Autre marque" }])).toBeNull(); + expect(matchRecall(r, [{ kind: "produit", id: "4", name: "Beurre", barcode: "3017620422003" }])).toBeNull(); + }); +}); From 7c21aae94874e3e68362e97488a5122a98ef4448 Mon Sep 17 00:00:00 2001 From: aburubiehjonas-design <245721399+aburubiehjonas-design@users.noreply.github.com> Date: Tue, 1 Dec 2026 16:37:44 +0000 Subject: [PATCH 2/6] =?UTF-8?q?Matrice=20des=20allerg=C3=A8nes=20imprimabl?= =?UTF-8?q?e=20et=20page=20publique=20avec=20QR=20et=20filtre=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(app)/menus/allergenes/actions.ts | 19 ++++ src/app/(app)/menus/allergenes/page.tsx | 100 +++++++++++++++++++ src/app/(app)/menus/layout.tsx | 3 +- src/app/allergenes/[jeton]/filter.tsx | 53 ++++++++++ src/app/allergenes/[jeton]/page.tsx | 33 +++++++ src/lib/services/allergen-matrix.ts | 113 ++++++++++++++++++++++ tests/integration/allergen-matrix.test.ts | 52 ++++++++++ 7 files changed, 372 insertions(+), 1 deletion(-) create mode 100644 src/app/(app)/menus/allergenes/actions.ts create mode 100644 src/app/(app)/menus/allergenes/page.tsx create mode 100644 src/app/allergenes/[jeton]/filter.tsx create mode 100644 src/app/allergenes/[jeton]/page.tsx create mode 100644 src/lib/services/allergen-matrix.ts create mode 100644 tests/integration/allergen-matrix.test.ts diff --git a/src/app/(app)/menus/allergenes/actions.ts b/src/app/(app)/menus/allergenes/actions.ts new file mode 100644 index 00000000..273a2f8a --- /dev/null +++ b/src/app/(app)/menus/allergenes/actions.ts @@ -0,0 +1,19 @@ +"use server"; +import { revalidatePath } from "next/cache"; +import { requirePage } from "@/lib/auth/session"; +import { PermissionDeniedError } from "@/lib/auth/permissions"; +import { setAllergenPage } from "@/lib/services/allergen-matrix"; +import type { FormState } from "@/components/ui/action-form"; + +export async function setAllergenPageAction(_p: FormState, f: FormData): Promise { + const s = await requirePage("recipes.manage"); + const a = String(f.get("do") ?? ""); + const action = a === "desactiver" || a === "nouvelle_adresse" ? a : "activer"; + try { await setAllergenPage(s.ctx, String(f.get("establishmentId") ?? ""), action); } catch (e) { + if (e instanceof PermissionDeniedError) return { status: "error", message: e.message }; + console.error("[allergènes]", e); + return { status: "error", message: "Erreur technique : rien n'a été changé." }; + } + revalidatePath("/menus/allergenes"); + return { status: "success", message: action === "desactiver" ? "Page désactivée : le QR n'affiche plus la carte." : action === "nouvelle_adresse" ? "Nouvelle adresse créée : réimprimez le QR, l'ancien ne marche plus." : "Page publique activée." }; +} diff --git a/src/app/(app)/menus/allergenes/page.tsx b/src/app/(app)/menus/allergenes/page.tsx new file mode 100644 index 00000000..cfb60a41 --- /dev/null +++ b/src/app/(app)/menus/allergenes/page.tsx @@ -0,0 +1,100 @@ +import type { Metadata } from "next"; +import { headers } from "next/headers"; +import QRCode from "qrcode"; +import { requirePage } from "@/lib/auth/session"; +import { hasPermission } from "@/lib/auth/permissions"; +import { allergenMatrix, getAllergenPage } from "@/lib/services/allergen-matrix"; +import { ALLERGENS } from "@/lib/recipes/allergens"; +import { ActionForm } from "@/components/ui/action-form"; +import { Alert, Card, CardTitle, EmptyState, PageHeader } from "@/components/ui/primitives"; +import { PrintButton } from "@/components/ui/print-button"; +import { loadScope } from "../../scope-data"; +import { EstablishmentPicker } from "../../haccp/ui"; +import { setAllergenPageAction } from "./actions"; + +export const metadata: Metadata = { title: "Matrice des allergènes" }; + +const fmt = (d: Date) => d.toLocaleDateString("fr-FR", { timeZone: "Europe/Paris", day: "numeric", month: "long", year: "numeric" }); + +export default async function AllergenMatrixPage({ searchParams }: { searchParams: Promise> }) { + const s = await requirePage("recipes.view"); + const sp = await searchParams; + const scope = await loadScope(s.ctx, sp, { allowAll: false }); + const est = scope.establishments.find((e) => e.id === scope.selection) ?? scope.establishments[0]; + const { dishes, updatedAt } = await allergenMatrix(s.ctx); + const page = est ? await getAllergenPage(s.ctx, est.id) : null; + const canManage = hasPermission(s.ctx, "recipes.manage"); + const h = await headers(); + const origin = process.env.APP_URL?.replace(/\/$/, "") ?? `${h.get("x-forwarded-proto") ?? "https"}://${h.get("x-forwarded-host") ?? h.get("host")}`; + const url = page?.enabled ? `${origin}/allergenes/${page.token}` : null; + const qr = url ? await QRCode.toString(url, { type: "svg", margin: 1 }) : null; + const toCheck = dishes.filter((d) => d.undeclared.length); + const today = fmt(new Date()); + return ( + <> + {est && }} /> + + {!dishes.length ? Ajoutez un prix de vente à vos fiches techniques (hors préparations de base) pour qu'elles apparaissent ici. : ( +
+ {toCheck.length > 0 && ( +
+ + Vérifiez sur l'étiquette du fournisseur et cochez les allergènes de ces produits (ou rien s'ils n'en ont pas) : {[...new Set(toCheck.flatMap((d) => d.undeclared))].slice(0, 12).join(", ")}{new Set(toCheck.flatMap((d) => d.undeclared)).size > 12 ? "…" : ""}. + +
+ )} +
+

{est?.name ?? ""} · Allergènes à déclaration obligatoire (règlement UE 1169/2011) · Édité le {today}{updatedAt ? ` · fiches mises à jour le ${fmt(updatedAt)}` : ""}

+ + + + + {ALLERGENS.map((a) => )} + + + + {dishes.map((d, i) => ( + + + {ALLERGENS.map((a) => { + const c = d.contains.includes(a.code), t = d.traces.includes(a.code); + return ; + })} + + ))} + +
Plat{a.label}
+ {d.name} {d.courseLabel} + {d.undeclared.length > 0 && à vérifier} + {c ? ● : t ? ○ : ·}
+

● contient · ○ peut contenir (traces) · Édité le {today}{updatedAt ? ` · dernière modification des fiches le ${fmt(updatedAt)}` : ""}. Information à vérifier par l'exploitant ; en cas d'allergie, le client le signale au personnel.

+
+
+ )} + {est && ( + + Page allergènes pour les clients +

Une adresse publique, sans connexion, qui affiche la carte de {est.name} avec ses allergènes. Le client coche ce qu'il ne mange pas et voit les plats qui lui conviennent. Les produits « à vérifier » n'y sont jamais signalés : complétez-les d'abord.

+ {url && qr ? ( +
+
+
+ {url} +

Imprimez cette page ou faites une capture du QR pour le poser en salle.

+
+
+ ) :

Page désactivée.

} + {canManage && ( +
+ {!page?.enabled &&
+ )} + + )} + + ); +} diff --git a/src/app/(app)/menus/layout.tsx b/src/app/(app)/menus/layout.tsx index bc8b17a7..6ec31086 100644 --- a/src/app/(app)/menus/layout.tsx +++ b/src/app/(app)/menus/layout.tsx @@ -8,9 +8,10 @@ export default async function MenusLayout({ children }: { children: ReactNode }) return ( <> diff --git a/src/app/allergenes/[jeton]/filter.tsx b/src/app/allergenes/[jeton]/filter.tsx new file mode 100644 index 00000000..80c49dca --- /dev/null +++ b/src/app/allergenes/[jeton]/filter.tsx @@ -0,0 +1,53 @@ +"use client"; +import { useState } from "react"; +import { ALLERGENS, type AllergenCode } from "@/lib/recipes/allergens"; + +type Dish = { id: string; name: string; courseLabel: string; contains: AllergenCode[]; traces: AllergenCode[] }; +const label = (c: string) => ALLERGENS.find((a) => a.code === c)?.label ?? c; + +/** Le client coche ce qu'il ne mange pas : les plats qui en contiennent passent en bas, barrés ; ceux avec des traces sont signalés. */ +export function AllergenFilter({ dishes }: { dishes: Dish[] }) { + const [avoid, setAvoid] = useState>(new Set()); + const toggle = (c: string) => setAvoid((s) => { const n = new Set(s); if (n.has(c)) n.delete(c); else n.add(c); return n; }); + const status = (d: Dish) => d.contains.some((c) => avoid.has(c)) ? "non" : d.traces.some((c) => avoid.has(c)) ? "traces" : "ok"; + const courses = [...new Set(dishes.map((d) => d.courseLabel))]; + if (!dishes.length) return

La carte n'est pas encore renseignée : demandez au personnel.

; + return ( + <> +
+ Je ne mange pas : +
+ {ALLERGENS.map((a) => ( + + ))} +
+
+ {courses.map((c) => { + const list = dishes.filter((d) => d.courseLabel === c).sort((a, b) => ["ok", "traces", "non"].indexOf(status(a)) - ["ok", "traces", "non"].indexOf(status(b))); + return ( +
+

{c}

+
    + {list.map((d) => { + const st = avoid.size ? status(d) : null; + return ( +
  • +
    +

    {d.name}

    + {st === "ok" && Convient} + {st === "traces" && Traces possibles} + {st === "non" && Contient} +
    +

    {d.contains.length ? <>Contient : {d.contains.map(label).join(", ")} : "Aucun des 14 allergènes déclaré"}

    + {d.traces.length > 0 &&

    Traces : {d.traces.map(label).join(", ")}

    } +
  • + ); + })} +
+
+ ); + })} + + ); +} diff --git a/src/app/allergenes/[jeton]/page.tsx b/src/app/allergenes/[jeton]/page.tsx new file mode 100644 index 00000000..8dcc6447 --- /dev/null +++ b/src/app/allergenes/[jeton]/page.tsx @@ -0,0 +1,33 @@ +import type { Metadata } from "next"; +import { AltairMark } from "@/components/brand/logo"; +import { publicAllergenMenu } from "@/lib/services/allergen-matrix"; +import { AllergenFilter } from "./filter"; + +export const metadata: Metadata = { title: "Allergènes de la carte", robots: { index: false } }; +export const dynamic = "force-dynamic"; + +export default async function PublicAllergensPage({ params }: { params: Promise<{ jeton: string }> }) { + const { jeton } = await params; + const info = await publicAllergenMenu(jeton); + return ( +
+ {!info ? ( +
Cette page n'est plus disponible. Demandez la liste des allergènes au personnel.
+ ) : ( + <> +
+

Allergènes de la carte

+

{info.establishmentName}

+

+ Les 14 allergènes à déclaration obligatoire, plat par plat. + {info.updatedAt ? ` Mise à jour le ${info.updatedAt.toLocaleDateString("fr-FR", { timeZone: "Europe/Paris", day: "numeric", month: "long", year: "numeric" })}.` : ""} +

+
+ +

Une recette ou un fournisseur peut changer : en cas d'allergie, signalez-la toujours au personnel avant de commander. « Traces » = peut contenir.

+

Page tenue à jour par le restaurant avec ALTAIR.

+ + )} +
+ ); +} diff --git a/src/lib/services/allergen-matrix.ts b/src/lib/services/allergen-matrix.ts new file mode 100644 index 00000000..f6df282d --- /dev/null +++ b/src/lib/services/allergen-matrix.ts @@ -0,0 +1,113 @@ +/** + * Matrice des allergènes (v0.170) : plats vendus × 14 allergènes réglementaires (règlement UE 1169/2011, annexe II), + * calculés depuis les produits et les sous-recettes des fiches techniques. Imprimable et datée, plus une page publique + * par établissement (QR à poser en salle) où le client filtre les plats selon ce qu'il ne mange pas. + * L'information reste sous la responsabilité de l'exploitant : un produit sans allergène déclaré est montré « à vérifier » + * dans la vue interne (jamais sur la page publique, qui le dit en une phrase). + */ +import { randomBytes } from "node:crypto"; +import { and, eq, inArray } from "drizzle-orm"; +import { db as defaultDb, schema, type DB } from "@/lib/db/pool"; +import { assertPermission, type AccessContext } from "@/lib/auth/permissions"; +import { ALLERGEN_CODES, mergeAllergens, type AllergenCode } from "@/lib/recipes/allergens"; +import { COURSES, loadRecipeGraphUnchecked } from "./stock"; +import { writeAudit } from "./audit"; +import { requireEstablishment } from "./scope"; + +export type MatrixDish = { + id: string; name: string; course: string; courseLabel: string; + contains: AllergenCode[]; traces: AllergenCode[]; + /** Produits de la fiche (sous-recettes comprises) sans aucun allergène ni trace déclaré : à vérifier. */ + undeclared: string[]; +}; + +/** Calcul sans contrôle de droits (l'appelant le fait) : carte vendue, hors préparations de base et fiches archivées. */ +export async function allergenDishesUnchecked(organizationId: string, dbx: DB = defaultDb): Promise<{ dishes: MatrixDish[]; updatedAt: Date | null }> { + const ctx = { organizationId } as AccessContext; + const graph = await loadRecipeGraphUnchecked(ctx, dbx); + const itemIds = [...new Set(graph.flatMap((g) => g.lines.flatMap((l) => (l.itemId ? [l.itemId] : []))))]; + const I = schema.purchaseItems; + const items = itemIds.length ? await dbx.select({ id: I.id, name: I.name, allergens: I.allergens, traces: I.allergenTraces, updatedAt: I.updatedAt }) + .from(I).where(and(eq(I.organizationId, organizationId), inArray(I.id, itemIds))) : []; + const itemsById = new Map(items.map((i) => [i.id, i])); + const byId = new Map(graph.map((g) => [g.recipe.id, g])); + const memo = new Map }>(); + const walk = (rid: string, seen: Set = new Set()): { contains: AllergenCode[]; traces: AllergenCode[]; undeclared: Set } => { + const m = memo.get(rid); + if (m) return m; + const g = byId.get(rid); + if (!g || seen.has(rid)) return { contains: [], traces: [], undeclared: new Set() }; + const next = new Set(seen).add(rid); + const undeclared = new Set(); + const parts = g.lines.map((l) => { + if (l.itemId) { + const it = itemsById.get(l.itemId); + if (it && !it.allergens.length && !it.traces.length) undeclared.add(it.name); + return { contains: it?.allergens ?? [], traces: it?.traces ?? [] }; + } + if (!l.subRecipeId) return { contains: [], traces: [] }; + const sub = walk(l.subRecipeId, next); + sub.undeclared.forEach((n) => undeclared.add(n)); + return sub; + }); + const merged = mergeAllergens([{ contains: g.recipe.allergens, traces: g.recipe.allergenTraces }, ...parts]); + const out = { ...merged, undeclared }; + memo.set(rid, out); + return out; + }; + const order = new Map(COURSES.map((c, i) => [c.code, i])); + const live = graph.filter((g) => !g.recipe.archivedAt && g.recipe.sellingPriceTtc !== null && g.recipe.course !== "preparation"); + const dishes = live.map((g) => { + const a = walk(g.recipe.id); + return { id: g.recipe.id, name: g.recipe.name, course: g.recipe.course, courseLabel: COURSES.find((c) => c.code === g.recipe.course)?.label ?? g.recipe.course, + contains: a.contains, traces: a.traces, undeclared: [...a.undeclared].sort((x, y) => x.localeCompare(y, "fr")) }; + }).sort((a, b) => (order.get(a.course) ?? 99) - (order.get(b.course) ?? 99) || a.name.localeCompare(b.name, "fr")); + const stamps = [...graph.map((g) => g.recipe.updatedAt), ...items.map((i) => i.updatedAt)].filter((d): d is Date => !!d).map((d) => new Date(d).getTime()); + return { dishes, updatedAt: stamps.length ? new Date(Math.max(...stamps)) : null }; +} + +export async function allergenMatrix(ctx: AccessContext, dbx: DB = defaultDb) { + assertPermission(ctx, "recipes.view"); + return allergenDishesUnchecked(ctx.organizationId, dbx); +} + +const P = schema.allergenPages; + +export async function getAllergenPage(ctx: AccessContext, establishmentId: string, dbx: DB = defaultDb) { + assertPermission(ctx, "recipes.view"); + await requireEstablishment(ctx, establishmentId, dbx); + const [row] = await dbx.select().from(P).where(and(eq(P.organizationId, ctx.organizationId), eq(P.establishmentId, establishmentId))); + return row ?? null; +} + +/** Active la page publique (crée l'adresse au premier appel), la désactive, ou change d'adresse (l'ancien QR ne marche plus). */ +export async function setAllergenPage(ctx: AccessContext, establishmentId: string, action: "activer" | "desactiver" | "nouvelle_adresse", dbx: DB = defaultDb) { + assertPermission(ctx, "recipes.manage"); + await requireEstablishment(ctx, establishmentId, dbx); + return dbx.transaction(async (tx) => { + const [cur] = await tx.select().from(P).where(and(eq(P.organizationId, ctx.organizationId), eq(P.establishmentId, establishmentId))); + const token = randomBytes(15).toString("base64url"); + let after; + if (!cur) { + if (action === "desactiver") return null; + [after] = await tx.insert(P).values({ organizationId: ctx.organizationId, establishmentId, token, enabled: true, createdBy: ctx.userId }).returning(); + } else { + [after] = await tx.update(P).set({ enabled: action !== "desactiver", ...(action === "nouvelle_adresse" ? { token } : {}), updatedAt: new Date() }) + .where(eq(P.id, cur.id)).returning(); + } + await writeAudit(tx, { organizationId: ctx.organizationId, userId: ctx.userId, action: `allergen_page.${action}`, entityType: "allergen_page", entityId: after!.id, before: cur ?? null, after }); + return after!; + }); +} + +/** Page publique (sans connexion) : null si l'adresse est inconnue ou désactivée. */ +export async function publicAllergenMenu(token: string, dbx: DB = defaultDb) { + if (!/^[A-Za-z0-9_-]{16,40}$/.test(token)) return null; + const [row] = await dbx.select({ page: P, name: schema.establishments.name, city: schema.establishments.city }).from(P) + .innerJoin(schema.establishments, eq(schema.establishments.id, P.establishmentId)).where(and(eq(P.token, token), eq(P.enabled, true))); + if (!row) return null; + const { dishes, updatedAt } = await allergenDishesUnchecked(row.page.organizationId, dbx); + return { establishmentName: row.name, city: row.city, updatedAt, dishes: dishes.map(({ undeclared: _u, ...d }) => d) }; +} + +export const ALL_ALLERGENS: readonly AllergenCode[] = ALLERGEN_CODES; diff --git a/tests/integration/allergen-matrix.test.ts b/tests/integration/allergen-matrix.test.ts new file mode 100644 index 00000000..793e859c --- /dev/null +++ b/tests/integration/allergen-matrix.test.ts @@ -0,0 +1,52 @@ +import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { pool } from "@/lib/db/pool"; +import { createCompany, createEstablishment } from "@/lib/services/structure"; +import { createProduct } from "@/lib/services/products"; +import { saveRecipe } from "@/lib/services/stock"; +import { allergenMatrix, getAllergenPage, publicAllergenMenu, setAllergenPage } from "@/lib/services/allergen-matrix"; +import { PermissionDeniedError } from "@/lib/auth/permissions"; +import { makeTenant, resetTestDatabase } from "./helpers"; + +let A: Awaited>, B: Awaited>; +let est: string, estB: string; + +beforeAll(async () => { + await resetTestDatabase(); + A = await makeTenant("Allergenes"); + B = await makeTenant("Voisin"); + est = (await createEstablishment(A.ctx, { companyId: (await createCompany(A.ctx, { legalName: "All SAS" })).id, name: "Bistrot" })).id; + estB = (await createEstablishment(B.ctx, { companyId: (await createCompany(B.ctx, { legalName: "Voisin SAS" })).id, name: "Voisin" })).id; + const farine = await createProduct(A.ctx, { name: "Farine T55", unit: "kg", category: "food", allergens: ["gluten"] }); + const beurre = await createProduct(A.ctx, { name: "Beurre", unit: "kg", category: "food", allergens: ["lait"], allergenTraces: ["fruits_coque"] }); + const sel = await createProduct(A.ctx, { name: "Sel", unit: "kg", category: "food" }); + const pate = await saveRecipe(A.ctx, null, { name: "Pâte brisée", course: "preparation", portions: "1", lines: [{ itemId: farine.id, quantity: "0.2", unit: "kg" }, { itemId: beurre.id, quantity: "0.1", unit: "kg" }] }); + await saveRecipe(A.ctx, null, { name: "Tarte salée", course: "plat", portions: "6", sellingPriceTtc: "14", lines: [{ subRecipeId: pate.id, quantity: "1", unit: "portion" }, { itemId: sel.id, quantity: "0.01", unit: "kg" }] }); +}); +afterAll(async () => { await pool.end(); }); + +describe("matrice des allergènes", () => { + it("calcule les allergènes à travers les sous-recettes et signale les produits non renseignés", async () => { + const { dishes } = await allergenMatrix(A.ctx); + expect(dishes.map((d) => d.name)).toEqual(["Tarte salée"]); + expect(dishes[0]).toMatchObject({ contains: ["gluten", "lait"], traces: ["fruits_coque"], undeclared: ["Sel"] }); + }); + it("page publique : activée, lisible sans connexion, sans le détail interne ; désactivable et changeable", async () => { + expect(await getAllergenPage(A.ctx, est)).toBeNull(); + const p = await setAllergenPage(A.ctx, est, "activer"); + const pub = await publicAllergenMenu(p!.token); + expect(pub?.establishmentName).toBe("Bistrot"); + expect(pub?.dishes[0]).not.toHaveProperty("undeclared"); + const p2 = await setAllergenPage(A.ctx, est, "nouvelle_adresse"); + expect(p2!.token).not.toBe(p!.token); + expect(await publicAllergenMenu(p!.token)).toBeNull(); + await setAllergenPage(A.ctx, est, "desactiver"); + expect(await publicAllergenMenu(p2!.token)).toBeNull(); + expect(await publicAllergenMenu("../../etc")).toBeNull(); + }); + it("droits et isolation", async () => { + await expect(setAllergenPage({ ...A.ctx, role: "staff" }, est, "activer")).rejects.toBeInstanceOf(PermissionDeniedError); + await expect(setAllergenPage(B.ctx, est, "activer")).rejects.toThrow(); + expect((await allergenMatrix(B.ctx)).dishes).toHaveLength(0); + void estB; + }); +}); From 9cac96592261fcbcde66e5efb303ceb79cccd0c9 Mon Sep 17 00:00:00 2001 From: aburubiehjonas-design <245721399+aburubiehjonas-design@users.noreply.github.com> Date: Tue, 1 Dec 2026 16:42:50 +0000 Subject: [PATCH 3/6] =?UTF-8?q?Nuisibles=20:=20contrat=20(n=C2=B0=20Certib?= =?UTF-8?q?iocide,=20fr=C3=A9quence,=20plan=20des=20pi=C3=A8ges),=20passag?= =?UTF-8?q?es=20sign=C3=A9s=20par=20lien,=20rappels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LkF13N77NoRR5wohpS2Hye --- src/app/(app)/haccp/layout.tsx | 2 + src/app/(app)/haccp/nuisibles/actions.ts | 58 ++++ src/app/(app)/haccp/nuisibles/page.tsx | 136 +++++++++ .../(app)/haccp/nuisibles/plan/[id]/route.ts | 15 + .../haccp/nuisibles/signature/[id]/route.ts | 15 + src/app/nuisibles/[jeton]/actions.ts | 23 ++ src/app/nuisibles/[jeton]/form.tsx | 32 ++ src/app/nuisibles/[jeton]/page.tsx | 29 ++ src/lib/scheduler.ts | 6 + src/lib/services/pest-control.ts | 280 ++++++++++++++++++ tests/integration/pest-control.test.ts | 99 +++++++ 11 files changed, 695 insertions(+) create mode 100644 src/app/(app)/haccp/nuisibles/actions.ts create mode 100644 src/app/(app)/haccp/nuisibles/page.tsx create mode 100644 src/app/(app)/haccp/nuisibles/plan/[id]/route.ts create mode 100644 src/app/(app)/haccp/nuisibles/signature/[id]/route.ts create mode 100644 src/app/nuisibles/[jeton]/actions.ts create mode 100644 src/app/nuisibles/[jeton]/form.tsx create mode 100644 src/app/nuisibles/[jeton]/page.tsx create mode 100644 src/lib/services/pest-control.ts create mode 100644 tests/integration/pest-control.test.ts diff --git a/src/app/(app)/haccp/layout.tsx b/src/app/(app)/haccp/layout.tsx index 536c0df7..c5f8093b 100644 --- a/src/app/(app)/haccp/layout.tsx +++ b/src/app/(app)/haccp/layout.tsx @@ -22,6 +22,8 @@ export default async function HaccpLayout({ children }: { children: ReactNode }) { href: "/haccp/temperatures-produit", label: "T° produit" }, { href: "/haccp/tracabilite", label: "Traçabilité" }, { href: "/haccp/qualite", label: "Qualité des plats" }, + { href: "/haccp/rappels", label: "Rappels produits" }, + { href: "/haccp/nuisibles", label: "Nuisibles" }, { href: "/haccp/suivi", label: "Suivi par jour" }, { href: "/haccp/historique", label: "Historique" }, { href: "/haccp/dossier", label: "Dossier PDF" }, diff --git a/src/app/(app)/haccp/nuisibles/actions.ts b/src/app/(app)/haccp/nuisibles/actions.ts new file mode 100644 index 00000000..88cea404 --- /dev/null +++ b/src/app/(app)/haccp/nuisibles/actions.ts @@ -0,0 +1,58 @@ +"use server"; +import { revalidatePath } from "next/cache"; +import { headers } from "next/headers"; +import { requirePage } from "@/lib/auth/session"; +import { cancelVisit, recordVisit, renewSignLink, saveContract, setTrapPlan } from "@/lib/services/pest-control"; +import type { FormState } from "@/components/ui/action-form"; +import { toHygieneError } from "../hygiene-actions"; + +const str = (f: FormData, k: string) => String(f.get(k) ?? ""); +async function signUrl(token: string) { + const h = await headers(); + const origin = process.env.APP_URL?.replace(/\/$/, "") ?? `${h.get("x-forwarded-proto") ?? "https"}://${h.get("x-forwarded-host") ?? h.get("host")}`; + return `${origin}/nuisibles/${token}`; +} +const LINK_LABEL = "Lien à ouvrir par le technicien (valable 7 jours, une seule signature) : envoyez-le par SMS ou ouvrez-le sur la tablette."; + +export async function saveContractAction(_p: FormState, f: FormData): Promise { + const s = await requirePage("haccp.manage"); + try { + const c = await saveContract(s.ctx, str(f, "id") || null, { + establishmentId: str(f, "establishmentId"), providerName: str(f, "providerName"), certibiocideNumber: str(f, "certibiocideNumber"), contactPhone: str(f, "contactPhone"), + contactEmail: str(f, "contactEmail"), startsOn: str(f, "startsOn"), endsOn: str(f, "endsOn"), visitsPerYear: str(f, "visitsPerYear"), notes: str(f, "notes"), + }); + const file = f.get("trapPlan"); + if (file instanceof File && file.size > 0) await setTrapPlan(s.ctx, c.id, { bytes: new Uint8Array(await file.arrayBuffer()), mime: file.type }); + } catch (e) { return toHygieneError(e); } + revalidatePath("/haccp/nuisibles"); + return { status: "success", message: "Contrat enregistré." }; +} + +export async function recordVisitAction(_p: FormState, f: FormData): Promise { + const s = await requirePage("haccp.record"); + const withSignLink = f.get("signLink") === "1"; + let token: string | null; + try { + ({ token } = await recordVisit(s.ctx, { + establishmentId: str(f, "establishmentId"), visitOn: str(f, "visitOn"), kind: str(f, "kind") === "curatif" ? "curatif" : "contrat", technicianName: str(f, "technicianName"), + activity: str(f, "activity"), pests: f.getAll("pests").map(String), findings: str(f, "findings"), actions: str(f, "actions"), recommendations: str(f, "recommendations"), products: str(f, "products"), + }, { withSignLink })); + } catch (e) { return toHygieneError(e); } + revalidatePath("/haccp", "layout"); + return token ? { status: "success", message: "Passage enregistré.", link: await signUrl(token), linkLabel: LINK_LABEL } : { status: "success", message: "Passage enregistré." }; +} + +export async function renewSignLinkAction(_p: FormState, f: FormData): Promise { + const s = await requirePage("haccp.record"); + let token: string; + try { token = await renewSignLink(s.ctx, str(f, "id")); } catch (e) { return toHygieneError(e); } + revalidatePath("/haccp/nuisibles"); + return { status: "success", message: "Nouveau lien créé : l'ancien ne marche plus.", link: await signUrl(token), linkLabel: LINK_LABEL }; +} + +export async function cancelVisitAction(_p: FormState, f: FormData): Promise { + const s = await requirePage("haccp.manage"); + try { await cancelVisit(s.ctx, str(f, "id"), str(f, "reason")); } catch (e) { return toHygieneError(e); } + revalidatePath("/haccp/nuisibles"); + return { status: "success", message: "Passage annulé (conservé au registre avec le motif)." }; +} diff --git a/src/app/(app)/haccp/nuisibles/page.tsx b/src/app/(app)/haccp/nuisibles/page.tsx new file mode 100644 index 00000000..c7fc4e6e --- /dev/null +++ b/src/app/(app)/haccp/nuisibles/page.tsx @@ -0,0 +1,136 @@ +import type { Metadata } from "next"; +import { requirePage } from "@/lib/auth/session"; +import { hasPermission } from "@/lib/auth/permissions"; +import { ACTIVITIES, PESTS, activityLabel, pestLabel, pestOverview } from "@/lib/services/pest-control"; +import { todayParis } from "@/lib/web/scope"; +import { ActionForm } from "@/components/ui/action-form"; +import { Alert, Badge, Card, CardTitle, EmptyState, Input, Label, PageHeader, Select } from "@/components/ui/primitives"; +import { loadScope } from "../../scope-data"; +import { CancelForm } from "../cancel-form"; +import { EstablishmentPicker, fmtDateTime } from "../ui"; +import { cancelVisitAction, recordVisitAction, renewSignLinkAction, saveContractAction } from "./actions"; + +export const metadata: Metadata = { title: "Nuisibles" }; +const fr = (d: string | null) => (d ? d.split("-").reverse().join("/") : "—"); +const area = "w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm"; + +export default async function PestPage({ searchParams }: { searchParams: Promise> }) { + const s = await requirePage("haccp.view"); + const sp = await searchParams; + const scope = await loadScope(s.ctx, sp, { allowAll: false }); + const est = scope.establishments.find((e) => e.id === scope.selection) ?? scope.establishments[0]; + const canRecord = hasPermission(s.ctx, "haccp.record"), canManage = hasPermission(s.ctx, "haccp.manage"); + const o = est ? await pestOverview(s.ctx, est.id) : null; + const c = o?.contract ?? null; + return ( + <> + } /> + {!est || !o ? : ( +
+
+ {!c && Ajoutez le contrat de votre prestataire (à droite) pour suivre les passages prévus.} + {o.late && Appelez le prestataire, puis notez le passage ci-dessous.} + {o.contractExpired && Renouvelez-le ou enregistrez le nouveau contrat.} +
+

Passages sur 12 mois

{o.last12}{c?.visitsPerYear ? / {c.visitsPerYear} prévus : null}

+

Avec activité

{o.withActivity}

+

Prochain passage

{o.nextDue ? fr(o.nextDue) : "Donnée manquante"}

+
+

Registre des passages (24 mois)

+ {!o.visits.length ? Notez le prochain passage du technicien avec le formulaire. : o.visits.map((v) => ( + +
+
+

{fr(v.visitOn)} · {v.kind === "curatif" ? "Intervention ponctuelle" : "Passage du contrat"}

+

{v.technicianName ? `Technicien : ${v.technicianName} · ` : ""}noté par {v.recordedByName}

+
+
+ {v.cancelledAt ? annulé : {activityLabel(v.activity)}} + {!v.cancelledAt && (v.hasSignature ? signé : non signé)} +
+
+ {v.pests.length > 0 &&

Nuisibles : {v.pests.map(pestLabel).join(", ")}

} + {v.findings &&

Constat : {v.findings}

} + {v.actions &&

Mesures prises : {v.actions}

} + {v.recommendations &&

Recommandations : {v.recommendations}

} + {v.products &&

Produits utilisés : {v.products}

} + {v.hasSignature && ( +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {`Signature +

Signé par {v.signerName} le {fmtDateTime(new Date(v.signedAt!))}

+
+ )} + {v.cancelledAt &&

Annulé : {v.cancelReason}

} + {!v.cancelledAt && ( +
+ {!v.hasSignature && canRecord &&
+ )} +
+ ))} +
+
+ {canRecord && ( + + Noter un passage +