-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_schema.sql
More file actions
75 lines (65 loc) · 3.06 KB
/
supabase_schema.sql
File metadata and controls
75 lines (65 loc) · 3.06 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- Enable UUID extension
create extension if not exists "uuid-ossp";
-- 1. CHURCHES TABLE
create table public.churches (
id uuid default uuid_generate_v4() primary key,
name text not null,
deep_research_profile jsonb not null default '{}'::jsonb,
branding_assets jsonb not null default '{}'::jsonb,
subscription_status text default 'inactive', -- 'active', 'inactive', 'past_due'
stripe_customer_id text,
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- 2. SERMONS TABLE
create table public.sermons (
id uuid default uuid_generate_v4() primary key,
church_id uuid references public.churches(id) not null,
transcript text not null,
title text, -- Optional but helpful
series_title text, -- Optional but helpful for "Current Series" context
status text default 'pending_processing',
audio_url text,
processing_error text,
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- 3. ASSETS TABLE
create table public.assets (
id uuid default uuid_generate_v4() primary key,
sermon_id uuid references public.sermons(id) not null,
type text not null, -- e.g., 'email_recap', 'devotional'
content_markdown text,
pdf_url text,
status text default 'pending', -- 'processing', 'completed', 'failed'
error text,
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- 4. STORAGE BUCKET (You must run this in the Storage UI or via Policy, but for SQL Editor:)
insert into storage.buckets (id, name, public)
values ('sermon-assets', 'sermon-assets', true)
on conflict (id) do nothing;
-- 5. RLS POLICIES (Simple Public Access for this Demo - Harden for prod!)
alter table public.churches enable row level security;
alter table public.sermons enable row level security;
alter table public.assets enable row level security;
create policy "Enable read access for all users" on public.churches for select using (true);
create policy "Enable read access for all users" on public.sermons for select using (true);
create policy "Enable read access for all users" on public.assets for select using (true);
create policy "Enable insert for all users" on public.assets for insert with check (true);
create policy "Enable update for all users" on public.assets for update using (true);
-- 6. ONBOARDING REQUESTS TABLE
create table public.onboarding_requests (
id uuid default uuid_generate_v4() primary key,
user_id uuid references auth.users not null,
church_name text,
website text,
denomination text,
social_links jsonb default '{}'::jsonb,
status text default 'pending_research',
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- RLS
alter table public.onboarding_requests enable row level security;
create policy "Enable insert for authenticated users" on public.onboarding_requests
for insert with check (auth.uid() = user_id);
create policy "Enable read for users based on user_id" on public.onboarding_requests
for select using (auth.uid() = user_id);