En auto-hébergeant votre base Supabase, vous êtes l'unique propriétaire de vos données.
Copiez ce script et collez-le dans le SQL Editor de votre tableau de bord Supabase, puis cliquez sur RUN.
-- 1. Profiles
CREATE TABLE IF NOT EXISTS public.profiles (
id UUID REFERENCES auth.users NOT NULL PRIMARY KEY,
tier TEXT DEFAULT 'free',
dashboard_config JSONB DEFAULT '[]'::jsonb,
ha_url TEXT,
ha_token_enc TEXT,
ha_entity_energy TEXT,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now())
);
-- 2. Rooms
CREATE TABLE IF NOT EXISTS public.rooms (
id TEXT NOT NULL,
user_id UUID REFERENCES auth.users NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (id, user_id)
);
-- 3. Entities
CREATE TABLE IF NOT EXISTS public.entities (
haId TEXT NOT NULL,
user_id UUID REFERENCES auth.users NOT NULL,
name TEXT NOT NULL,
type TEXT NOT NULL,
roomId TEXT,
PRIMARY KEY (haId, user_id)
);
-- RLS
ALTER TABLE public.profiles ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.rooms ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.entities ENABLE ROW LEVEL SECURITY;
-- Policies
CREATE POLICY "Users can see their own profile" ON public.profiles FOR SELECT USING (auth.uid() = id);
CREATE POLICY "Users can update their own profile" ON public.profiles FOR UPDATE USING (auth.uid() = id);
CREATE POLICY "Users can insert their own profile" ON public.profiles FOR INSERT WITH CHECK (auth.uid() = id);
CREATE POLICY "Users can manage their rooms" ON public.rooms FOR ALL USING (auth.uid() = user_id);
CREATE POLICY "Users can manage their entities" ON public.entities FOR ALL USING (auth.uid() = user_id);