Schéma cible Supabase (Postgres)
companies, profiles, memberships, document_categories, documents, permissions, products, quote_requests, quote_lines, pages.
create type member_role as enum ('admin', 'acheteur', 'technicien');
create table public.companies (
id uuid primary key default gen_random_uuid(),
name text not null,
siret text not null,
city text not null,
capacity_certificate_number text not null,
capacity_certificate_valid_until date not null
);
create table public.profiles (
id uuid primary key references auth.users(id) on delete cascade,
full_name text not null,
email text not null,
is_staff boolean not null default false
);
create table public.memberships (
profile_id uuid not null references public.profiles(id) on delete cascade,
company_id uuid not null references public.companies(id) on delete cascade,
role member_role not null,
primary key (profile_id, company_id)
);
create table public.document_categories (
id text primary key,
label text not null,
is_public boolean not null default false,
sort_order int not null
);
create table public.documents (
id uuid primary key default gen_random_uuid(),
company_id uuid references public.companies(id),
category_id text not null references public.document_categories(id),
title text not null,
storage_path text not null,
created_at timestamptz not null default now()
);
create table public.permissions (
company_id uuid not null references public.companies(id) on delete cascade,
profile_id uuid not null references public.profiles(id) on delete cascade,
category_id text not null references public.document_categories(id),
granted_by uuid references public.profiles(id),
granted_at timestamptz not null default now(),
primary key (company_id, profile_id, category_id)
);
create table public.products (
id uuid primary key default gen_random_uuid(),
slug text not null unique,
name text not null,
kind text not null check (kind in ('retrofit', 'equipement', 'historique')),
replaces text[] not null default '{}',
gwp_ar4 int not null,
safety_class text not null check (safety_class in ('A1', 'A2L', 'A3')),
glide_k numeric(4, 1) not null,
oils text[] not null,
applications text[] not null,
packagings text[] not null,
composition text not null,
regulatory_note text not null
);
create table public.quote_requests (
id bigint generated always as identity primary key,
reference text not null unique,
company_id uuid not null references public.companies(id),
profile_id uuid not null references public.profiles(id),
company_siret text not null,
capacity_certificate_number text not null,
capacity_certificate_valid_until date not null,
capacity_certificate_expired boolean not null,
comment text not null default '',
status text not null default 'reçue',
created_at timestamptz not null default now()
);
create table public.quote_lines (
id bigint generated always as identity primary key,
quote_request_id bigint not null references public.quote_requests(id) on delete cascade,
product_id uuid not null references public.products(id),
product_name text not null,
packaging text not null,
quantity int not null check (quantity between 1 and 500)
);
create table public.pages (
slug text primary key,
published_data jsonb not null,
published_at timestamptz not null default now(),
published_by uuid references public.profiles(id)
);