-- Blog posts for slymn.me — run in Supabase SQL editor or via CLI. -- RLS: public read for published posts; inserts/updates/deletes go through service role (Next.js API).
create table if not exists public.blog_posts ( id uuid primary key default gen_random_uuid(), slug text not null unique, title text not null, excerpt text not null default '', cover_image text, content jsonb not null default '{"blocks":[]}'::jsonb, original_language text not null default 'az', english_translation jsonb, status text not null default 'draft' check (status in ('draft', 'published')), published_at timestamptz, tags text[] not null default '{}', seo_title text, seo_description text, og_image text, created_at timestamptz not null default now(), updated_at timestamptz not null default now() );
create index if not exists blog_posts_status_published_at_idx on public.blog_posts (status, published_at desc nulls last);
create index if not exists blog_posts_slug_idx on public.blog_posts (slug);
alter table public.blog_posts enable row level security;
-- Anonymous users can read published posts only drop policy if exists "blog_posts_select_published" on public.blog_posts; create policy "blog_posts_select_published" on public.blog_posts for select using (status = 'published');
-- Optional: allow authenticated dashboard users direct access (not required if you only use service role from API) -- create policy "blog_posts_service_all" on public.blog_posts for all using (auth.role() = 'service_role');
comment on table public.blog_posts is 'Portfolio blog; english_translation caches OpenAI EN variant (title, excerpt, blocks).';
