This repository has been archived by the owner on Feb 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: consolidate 0.8.0 database migrations
- Loading branch information
Showing
10 changed files
with
185 additions
and
180 deletions.
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
packages/api/supabase/migrations/20240419164109_assistant.sql
This file was deleted.
Oops, something went wrong.
134 changes: 134 additions & 0 deletions
134
packages/api/supabase/migrations/20240419164109_v0.8.0_openai_types.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
-- Create a table to store OpenAI Assistant Objects | ||
create table | ||
assistant_objects ( | ||
id uuid primary key DEFAULT uuid_generate_v4(), | ||
created_at bigint default extract(epoch from now()) not null, | ||
description varchar(512), | ||
instructions text, | ||
metadata jsonb, | ||
model varchar(255) not null, | ||
name varchar(255), | ||
object text check (object in ('assistant')), | ||
tools jsonb, | ||
response_format jsonb, | ||
temperature float, | ||
tool_resources jsonb, | ||
top_p float | ||
); | ||
|
||
-- Create a table to store the OpenAI Thread Objects | ||
create table | ||
thread_objects ( | ||
id uuid primary key DEFAULT uuid_generate_v4(), | ||
user_id uuid references auth.users not null, | ||
object text check (object in ('thread')), | ||
created_at bigint default extract(epoch FROM NOW()) NOT NULL, | ||
tool_resources jsonb, | ||
metadata jsonb | ||
); | ||
|
||
-- Create a table to store the OpenAI Message Objects | ||
create table | ||
message_objects ( | ||
id uuid primary key DEFAULT uuid_generate_v4(), | ||
user_id uuid references auth.users not null, | ||
object text check (object in ('thread.message')), | ||
created_at bigint default extract(epoch FROM NOW()) not null, | ||
thread_id uuid references thread_objects (id) on delete cascade not null, | ||
status text, | ||
incomplete_details jsonb, | ||
completed_at bigint, | ||
incomplete_at bigint, | ||
role text, | ||
content jsonb, | ||
assistant_id uuid, -- No foreign key constraint, can be null and doesn't have to refer to an assistant that exists | ||
run_id uuid, -- No foreign key constraint, can be null and doesn't have to refer to a thread that exists | ||
attachments jsonb, | ||
metadata jsonb | ||
); | ||
|
||
-- RLS policies | ||
alter table thread_objects enable row level security; | ||
alter table message_objects enable row level security; | ||
|
||
-- Policies for thread_objects | ||
create policy "Individuals can view their own thread_objects." on thread_objects for | ||
select using (auth.uid() = user_id); | ||
create policy "Individuals can create thread_objects." on thread_objects for | ||
insert with check (auth.uid() = user_id); | ||
create policy "Individuals can update their own thread_objects." on thread_objects for | ||
update using (auth.uid() = user_id); | ||
create policy "Individuals can delete their own thread_objects." on thread_objects for | ||
delete using (auth.uid() = user_id); | ||
|
||
-- Policies for message_objects | ||
create policy "Individuals can view their own message_objects." on message_objects for | ||
select using (auth.uid() = user_id); | ||
create policy "Individuals can create message_objects." on message_objects for | ||
insert with check (auth.uid() = user_id); | ||
create policy "Individuals can update their own message_objects." on message_objects for | ||
update using (auth.uid() = user_id); | ||
create policy "Individuals can delete their own message_objects." on message_objects for | ||
delete using (auth.uid() = user_id); | ||
|
||
-- Indexes for foreign keys for message_objects | ||
CREATE INDEX message_objects_user_id ON message_objects (user_id); | ||
CREATE INDEX message_objects_thread_id ON message_objects (thread_id); | ||
CREATE INDEX message_objects_created_at ON thread_objects (created_at); | ||
|
||
-- Indexes for common filtering and sorting for thread_objects | ||
CREATE INDEX thread_objects_id ON thread_objects (id); | ||
CREATE INDEX thread_objects_user_id ON thread_objects (user_id); | ||
CREATE INDEX thread_objects_created_at ON thread_objects (created_at); | ||
|
||
-- Add user_id column to assistant_objects and file_objects tables | ||
alter table assistant_objects | ||
add column user_id uuid references auth.users not null; | ||
alter table file_objects | ||
add column user_id uuid references auth.users not null; | ||
-- Set buckets to private | ||
update storage.buckets | ||
set public = false | ||
where id = 'file_bucket'; | ||
|
||
-- RLS policies | ||
alter table assistant_objects enable row level security; | ||
alter table file_objects enable row level security; | ||
|
||
-- Policies for assistant_objects | ||
create policy "Individuals can view their own assistant_objects. " on assistant_objects for | ||
select using (auth.uid() = user_id); | ||
create policy "Individuals can create assistant_objects." on assistant_objects for | ||
insert with check (auth.uid() = user_id); | ||
create policy "Individuals can update their own assistant_objects." on assistant_objects for | ||
update using (auth.uid() = user_id); | ||
create policy "Individuals can delete their own assistant_objects." on assistant_objects for | ||
delete using (auth.uid() = user_id); | ||
|
||
-- Policies for file_objects | ||
create policy "Individuals can view their own file_objects." on file_objectsfor | ||
select using (auth.uid() = user_id); | ||
create policy "Individuals can create file_objects." on file_objects for | ||
insert with check (auth.uid() = user_id); | ||
create policy "Individuals can update their own file_objects." on file_objects for | ||
update using (auth.uid() = user_id); | ||
create policy "Individuals can delete their own file_objects." on file_objects for | ||
delete using (auth.uid() = user_id); | ||
|
||
-- Policies for file_bucket | ||
create policy "Any authenticated individual can add files to file_bucket." | ||
on storage.objects for | ||
insert to authenticated with check (bucket_id = 'file_bucket'); | ||
create policy "Individuals can view their own files in the file_bucket." | ||
on storage.objects for | ||
select using (bucket_id = 'file_bucket' AND auth.uid() = owner); | ||
create policy "Individuals can delete their own files." | ||
on storage.objects for | ||
delete using (bucket_id = 'file_bucket' AND auth.uid() = owner); | ||
create policy "Individuals can update their own files in file_bucket." | ||
on storage.objects for | ||
update using (auth.uid() = owner) with check (bucket_id = 'file_bucket'); | ||
|
||
ALTER TABLE file_objects ALTER COLUMN created_at SET DEFAULT extract(epoch from now()); | ||
ALTER TABLE file_objects ALTER COLUMN created_at SET NOT NULL; | ||
ALTER TABLE file_objects ADD CHECK (object in ('file')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
packages/api/supabase/migrations/20240516152530_enable_rls.sql
This file was deleted.
Oops, something went wrong.
64 changes: 0 additions & 64 deletions
64
packages/api/supabase/migrations/20240522141100_threads_runs_messages_steps.sql
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
packages/api/supabase/migrations/20240603183253_vector-store-rls.sql
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
packages/api/supabase/migrations/20240610185420_file_objects.sql
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
src/leapfrogai_ui/supabase/migrations/20240523233951_0.8_ui_migration.sql
This file was deleted.
Oops, something went wrong.