-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_schema.sql
More file actions
54 lines (45 loc) · 1.89 KB
/
Copy pathsupabase_schema.sql
File metadata and controls
54 lines (45 loc) · 1.89 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
-- Run this in your Supabase SQL Editor (Dashboard → SQL Editor → New Query)
-- Search Agents table
create table if not exists search_agents (
id uuid default gen_random_uuid() primary key,
user_id uuid references auth.users(id) on delete cascade not null,
name text not null,
description text,
llm_provider text not null,
model_id text not null,
api_key text not null,
system_prompt text not null,
output_columns jsonb not null default '[]',
slug text unique not null,
is_active boolean default true,
created_at timestamptz default now(),
updated_at timestamptz default now()
);
-- Row Level Security: users can only access their own agents
alter table search_agents enable row level security;
create policy "Users can view own agents"
on search_agents for select
using (auth.uid() = user_id);
create policy "Users can insert own agents"
on search_agents for insert
with check (auth.uid() = user_id);
create policy "Users can update own agents"
on search_agents for update
using (auth.uid() = user_id);
create policy "Users can delete own agents"
on search_agents for delete
using (auth.uid() = user_id);
-- Search Logs table (usage tracking)
create table if not exists search_logs (
id uuid default gen_random_uuid() primary key,
agent_id uuid references search_agents(id) on delete cascade not null,
query text not null,
created_at timestamptz default now()
);
-- Migrations: run these if table already exists
alter table search_agents add column if not exists final_prompt text;
alter table search_agents add column if not exists result_count integer default 10;
alter table search_agents add column if not exists result_count_max integer default null;
-- Index for faster slug lookups on the public search endpoint
create index if not exists search_agents_slug_idx on search_agents(slug);
create index if not exists search_agents_user_id_idx on search_agents(user_id);