Paso 1: Creá tu cuenta gratuita en supabase.com → New Project.
Paso 2: Andá a Settings → API y copiá la Project URL y la anon public key. Pegálas en el banner amarillo de arriba.
Paso 3: Andá a SQL Editor y ejecutá este script para crear las tablas:
-- Roles
create table roles (
id uuid primary key default gen_random_uuid(),
nombre text unique not null
);
insert into roles (nombre) values ('admin'), ('operador'), ('ayudante');
-- Perfiles de usuario
create table profiles (
id uuid references auth.users primary key,
nombre text, email text,
rol_id uuid references roles(id),
cuadrilla_id uuid,
activo boolean default true,
pago_jornada numeric default 0,
anticipos numeric default 0,
created_at timestamptz default now()
);
-- Cuadrillas
create table cuadrillas (
id uuid primary key default gen_random_uuid(),
nombre text not null, especialidad text,
equipo text,
jefe_id uuid references profiles(id),
miembros_ids uuid[],
created_at timestamptz default now()
);
-- Proyectos
create table proyectos (
id uuid primary key default gen_random_uuid(),
nombre text not null, estado text default 'activo',
cuadrilla_id uuid references cuadrillas(id),
latitud numeric, longitud numeric,
fecha_inicio date, descripcion text,
created_at timestamptz default now()
);
-- Perforaciones
create table perforaciones (
id uuid primary key default gen_random_uuid(),
codigo text unique not null,
proyecto_id uuid references proyectos(id),
latitud numeric, longitud numeric,
profundidad_alcanzada numeric, profundidad_objetivo numeric,
diametro text, tipo_suelo text, descripcion_suelo text,
fecha_inicio date, fecha_fin date, dias_campo integer,
estado text default 'en_curso',
acuifero boolean default false, caudal_estimado numeric,
problema_descripcion text, problema_solucion text,
materiales text, observaciones text,
costo_mo numeric default 0, costo_materiales numeric default 0,
costo_transporte numeric default 0, costo_alojamiento numeric default 0,
costo_viaticos numeric default 0, costo_imprevistos numeric default 0,
created_by uuid references auth.users(id),
created_at timestamptz default now()
);
-- RLS (seguridad por filas)
alter table profiles enable row level security;
alter table cuadrillas enable row level security;
alter table proyectos enable row level security;
alter table perforaciones enable row level security;
create policy "Todos los autenticados leen" on cuadrillas for select using (auth.role() = 'authenticated');
create policy "Todos los autenticados leen" on proyectos for select using (auth.role() = 'authenticated');
create policy "Todos los autenticados leen" on perforaciones for select using (auth.role() = 'authenticated');
create policy "Solo admin escribe cuadrillas" on cuadrillas for all using (exists(select 1 from profiles where id=auth.uid() and rol='admin'));
create policy "Solo admin escribe proyectos" on proyectos for all using (exists(select 1 from profiles where id=auth.uid() and rol='admin'));
create policy "Solo admin escribe perforaciones" on perforaciones for all using (exists(select 1 from profiles where id=auth.uid() and rol='admin'));
create policy "Ver perfil propio" on profiles for select using (auth.uid() = id);
create policy "Actualizar perfil propio" on profiles for update using (auth.uid() = id);
Paso 4: Registrá tu usuario administrador desde esta app (botón "¿Primera vez?"). Luego ejecutá en SQL Editor:
update profiles set rol_id = (select id from roles where nombre = 'admin') where email = 'TU_CORREO_AQUI';
✓ Listo. Tu app está conectada a la nube. Los operarios que registres tendrán acceso de solo lectura.