Configuração do Supabase:
Crie estas tabelas no SQL Editor do seu Supabase:
create table profiles (
id uuid primary key references auth.users(id) on delete cascade,
full_name text,
role text check (role in ('nutricionista','aluno')),
nutricionista_id uuid references profiles(id),
age int, height numeric, gender text, goal text,
created_at timestamp default now()
);
create table plans (
id uuid primary key default gen_random_uuid(),
student_id uuid references profiles(id),
nutricionista_id uuid references profiles(id),
title text, content text, plan_type text,
created_at timestamp default now()
);
create table weight_logs (
id uuid primary key default gen_random_uuid(),
student_id uuid references profiles(id),
weight numeric, notes text,
logged_at timestamp default now()
);
alter table profiles enable row level security;
alter table plans enable row level security;
alter table weight_logs enable row level security;
create policy "users read own" on profiles for select using (true);
create policy "users update own" on profiles for update using (auth.uid() = id);
create policy "users insert own" on profiles for insert with check (auth.uid() = id);
create policy "plans read" on plans for select using (true);
create policy "plans insert" on plans for insert with check (true);
create policy "weight read" on weight_logs for select using (true);
create policy "weight insert" on weight_logs for insert with check (true);
-- Tabela de fotos de evolução (necessária para "Gerar Meu Plano"):
create table fotos_evolucao (
id uuid primary key default gen_random_uuid(),
student_id uuid references profiles(id) on delete cascade,
photo_url text not null,
label text,
peso numeric,
registered_at timestamp default now()
);
alter table fotos_evolucao enable row level security;
create policy "fotos read" on fotos_evolucao for select using (true);
create policy "fotos insert" on fotos_evolucao for insert with check (true);
create table plan_attachments (
id uuid primary key default gen_random_uuid(),
plan_id uuid references plans(id) on delete cascade,
file_name text,
file_type text,
file_url text,
created_at timestamp default now()
);
alter table plan_attachments enable row level security;
create policy "attachments read" on plan_attachments for select using (true);
create policy "attachments insert" on plan_attachments for insert with check (true);
-- Bucket de armazenamento de fotos (criar no Supabase Storage):
-- Nome: fotos-alunos | Tipo: privado
-- Migração para bancos existentes (execute se as tabelas já existirem):
alter table profiles add column if not exists email text;
alter table plans add column if not exists plan_attachments_saved boolean default false;