Veritabanı Tablolarını Oluştur
SQL Editor'a git ve şu kodu çalıştır:
-- Bakıcı profilleri
CREATE TABLE caregivers (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
user_id uuid REFERENCES auth.users,
name text, surname text, phone text,
city text, district text, gender text,
birth_year int, categories text[],
experience text, price_range text,
live_in text, bio text, tc_no text,
verified boolean DEFAULT false,
featured boolean DEFAULT false,
rating numeric DEFAULT 0,
review_count int DEFAULT 0,
tags text[],
created_at timestamptz DEFAULT now()
);
-- Mesajlar
CREATE TABLE messages (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
from_user uuid REFERENCES auth.users,
to_user uuid REFERENCES auth.users,
caregiver_id uuid REFERENCES caregivers,
content text NOT NULL,
read boolean DEFAULT false,
created_at timestamptz DEFAULT now()
);
-- Aile profilleri (bakıcı arayanlar)
CREATE TABLE families (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
user_id uuid REFERENCES auth.users UNIQUE,
name text, phone text, email text,
plan text DEFAULT 'free',
plan_expires_at timestamptz,
created_at timestamptz DEFAULT now()
);
ALTER TABLE families ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Kullanıcı kendi aile profilini yönetir" ON families FOR ALL USING (auth.uid() = user_id);
CREATE POLICY "Aileler bakıcılara açık" ON families FOR SELECT USING (true);
-- Değerlendirmeler
CREATE TABLE reviews (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
caregiver_id uuid REFERENCES caregivers,
reviewer_id uuid REFERENCES auth.users,
rating int CHECK (rating BETWEEN 1 AND 5),
text text,
created_at timestamptz DEFAULT now()
);
-- RLS Politikaları
ALTER TABLE caregivers ENABLE ROW LEVEL SECURITY;
ALTER TABLE messages ENABLE ROW LEVEL SECURITY;
ALTER TABLE reviews ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Bakıcılar herkese açık" ON caregivers FOR SELECT USING (true);
CREATE POLICY "Kullanıcı kendi profilini yönetir" ON caregivers FOR ALL USING (auth.uid() = user_id);
CREATE POLICY "Mesajlar kullanıcıya özel" ON messages FOR ALL USING (auth.uid() = from_user OR auth.uid() = to_user);
CREATE POLICY "Yorumlar herkese açık" ON reviews FOR SELECT USING (true);
CREATE POLICY "Giriş yapan yorum yapabilir" ON reviews FOR INSERT WITH CHECK (auth.uid() = reviewer_id);