انسخ هذا الكود والصقه في SQL Editor في Supabase Dashboard ثم اضغط Run
-- ════════════════════════════════════
-- SADA Growth Agency — Database Schema
-- ════════════════════════════════════
-- جدول العملاء
create table public.clients (
id uuid default gen_random_uuid() primary key,
user_id uuid references auth.users(id) on delete cascade,
name text not null,
email text not null,
plan text default 'basic',
is_active boolean default true,
status text default 'active',
created_at timestamptz default now()
);
-- إضافة الأعمدة إن كان الجدول موجوداً مسبقاً
alter table public.clients add column if not exists is_active boolean default true;
alter table public.clients add column if not exists status text default 'active';
-- جدول حسابات المنصات
create table public.client_accounts (
id uuid default gen_random_uuid() primary key,
client_id uuid references public.clients(id) on delete cascade,
platform text not null,
account_name text not null,
account_handle text,
account_url text,
platform_id text,
created_at timestamptz default now()
);
-- جدول الإحصائيات
create table public.account_stats (
id uuid default gen_random_uuid() primary key,
account_id uuid references public.client_accounts(id) on delete cascade,
views bigint default 0,
likes bigint default 0,
followers bigint default 0,
videos_count int default 0,
date_recorded date default current_date,
created_at timestamptz default now()
);
-- تفعيل RLS
alter table public.clients enable row level security;
alter table public.client_accounts enable row level security;
alter table public.account_stats enable row level security;
-- صلاحيات العميل (يرى بياناته فقط)
create policy "client_own" on public.clients
for select using (auth.uid() = user_id);
create policy "accounts_own" on public.client_accounts
for select using (
exists (select 1 from public.clients
where id = client_id and user_id = auth.uid())
);
create policy "stats_own" on public.account_stats
for select using (
exists (
select 1 from public.client_accounts ca
join public.clients c on c.id = ca.client_id
where ca.id = account_id and c.user_id = auth.uid()
)
);
-- صلاحيات الكتابة الكاملة للمدير (service_role)
-- تُضاف تلقائياً عبر الـ service role key في Supabase
-- ربط العميل تلقائياً عند التسجيل
create or replace function public.link_client_on_signup()
returns trigger as $$
begin
update public.clients
set user_id = new.id
where email = new.email and user_id is null;
return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
after insert on auth.users
for each row execute function public.link_client_on_signup();
بعد تشغيل الكود، أضف بريدك الإلكتروني في إعدادات Supabase → Authentication → Users كـ admin
➕ إضافة عميل جديد
بعد الإضافة، أرسل للعميل البريد وكلمة المرور ليدخل لوحته مباشرة — لا حاجة لتسجيل.
📱 إضافة حساب للعميل
ستجده في YouTube Studio → قناتك → About → مشاركة القناة