Spaces:
Running on Zero
Running on Zero
Download supabase_schema.sql from lmcdjma/fellah: direct link, hf CLI and curl.
- Browser
- Download file 3.48 kB
-
https://huggingface.co/spaces/lmcdjma/fellah/resolve/main/supabase_schema.sql
- Command line
-
hf download hf://spaces/lmcdjma/fellah/supabase_schema.sql
-
curl -L -o supabase_schema.sql https://huggingface.co/spaces/lmcdjma/fellah/resolve/main/supabase_schema.sql
3.48 kB
| -- ============================================================================ | |
| -- Fellah — structure de la base Supabase | |
| -- À coller une seule fois dans Supabase : SQL Editor → New query → Run. | |
| -- Le script peut être relancé sans danger (il ne recrée pas ce qui existe). | |
| -- ============================================================================ | |
| -- Profil de chaque utilisateur : ses réglages (alertes email/SMS, changements) | |
| create table if not exists public.profils ( | |
| user_id text primary key, | |
| parametres jsonb, | |
| migre_le timestamptz, -- reprise des données de l'ancien stockage | |
| cree_le timestamptz not null default now(), | |
| maj_le timestamptz not null default now() | |
| ); | |
| -- Une étude : nom, suivi automatique, alertes, irrigation, aptitude des terres… | |
| create table if not exists public.etudes ( | |
| id text primary key, | |
| user_id text not null, | |
| nom text not null, | |
| cree_le text, | |
| donnees jsonb not null default '{}'::jsonb, | |
| maj_le timestamptz not null default now() | |
| ); | |
| create index if not exists etudes_user_idx on public.etudes (user_id); | |
| -- Le terrain d'une étude : contour, surface, centre | |
| create table if not exists public.terrains ( | |
| id text primary key, | |
| etude_id text not null references public.etudes (id) on delete cascade, | |
| user_id text not null, | |
| nom text, | |
| cree_le text, | |
| contour_wkt text, | |
| surface_ha double precision, | |
| centre jsonb, | |
| donnees jsonb not null default '{}'::jsonb, | |
| maj_le timestamptz not null default now() | |
| ); | |
| create index if not exists terrains_user_idx on public.terrains (user_id); | |
| create index if not exists terrains_etude_idx on public.terrains (etude_id); | |
| -- Une analyse : indices, zones, changements, qualité… (les fichiers sont dans le bucket) | |
| create table if not exists public.analyses ( | |
| id text primary key, | |
| terrain_id text not null references public.terrains (id) on delete cascade, | |
| user_id text not null, | |
| date_scene text not null, | |
| donnees jsonb not null, | |
| maj_le timestamptz not null default now() | |
| ); | |
| create index if not exists analyses_user_idx on public.analyses (user_id); | |
| create index if not exists analyses_terrain_idx on public.analyses (terrain_id, date_scene); | |
| -- Date de dernière modification, mise à jour automatiquement | |
| create or replace function public.fellah_maj_le() returns trigger | |
| language plpgsql set search_path = '' as $$ | |
| begin | |
| new.maj_le := now(); | |
| return new; | |
| end $$; | |
| do $$ | |
| declare t text; | |
| begin | |
| foreach t in array array['profils', 'etudes', 'terrains', 'analyses'] loop | |
| execute format('drop trigger if exists %I_maj_le on public.%I', t, t); | |
| execute format('create trigger %I_maj_le before update on public.%I | |
| for each row execute function public.fellah_maj_le()', t, t); | |
| end loop; | |
| end $$; | |
| -- Sécurité : protection ligne par ligne activée, aucun accès public. | |
| -- Seul le serveur de Fellah, avec la clé secrète, lit et écrit. | |
| alter table public.profils enable row level security; | |
| alter table public.etudes enable row level security; | |
| alter table public.terrains enable row level security; | |
| alter table public.analyses enable row level security; | |
| revoke all on public.profils, public.etudes, public.terrains, public.analyses from anon, authenticated; | |
| grant select, insert, update, delete on public.profils, public.etudes, public.terrains, public.analyses | |
| to service_role; | |