-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-blogs.sql
More file actions
30 lines (24 loc) · 1.02 KB
/
setup-blogs.sql
File metadata and controls
30 lines (24 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- Blogs table
create table if not exists public.blogs (
id uuid primary key default gen_random_uuid(),
title text not null,
excerpt text not null,
author text not null,
category text not null,
cover_image text not null,
content text not null,
status text not null default 'PUBLISHED',
published_at timestamptz not null default now(),
created_by uuid references auth.users(id) on delete set null,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
alter table public.blogs enable row level security;
create policy "blogs_public_read_published" on public.blogs
for select to public using (status = 'PUBLISHED');
create policy "blogs_auth_read_all" on public.blogs
for select to authenticated using (true);
create policy "blogs_auth_insert" on public.blogs
for insert to authenticated with check (auth.uid() = created_by);
create policy "blogs_auth_update" on public.blogs
for update to authenticated using (auth.uid() = created_by) with check (auth.uid() = created_by);