Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions migrations/tenant/0044-vector-bucket-type.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DO $$
DECLARE
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_enum
JOIN pg_type ON pg_enum.enumtypid = pg_type.oid
WHERE pg_type.typname = 'buckettype'
AND enumlabel = 'VECTOR'
) THEN
ALTER TYPE storage.BucketType ADD VALUE 'VECTOR';
END IF;
END$$;
34 changes: 34 additions & 0 deletions migrations/tenant/0045-vector-buckets.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
DO $$
DECLARE
anon_role text = COALESCE(current_setting('storage.anon_role', true), 'anon');
authenticated_role text = COALESCE(current_setting('storage.authenticated_role', true), 'authenticated');
service_role text = COALESCE(current_setting('storage.service_role', true), 'service_role');
BEGIN
CREATE TABLE IF NOT EXISTS storage.buckets_vectors (
id text not null primary key,
type storage.BucketType NOT NULL default 'VECTOR',
created_at timestamptz NOT NULL default now(),
updated_at timestamptz NOT NULL default now()
);

CREATE TABLE IF NOT EXISTS storage.vector_indexes
(
id text primary key default gen_random_uuid(),
name text COLLATE "C" NOT NULL,
bucket_id text NOT NULL references storage.buckets_vectors (id),
data_type text NOT NULL,
dimension integer NOT NULL,
distance_metric text NOT NULL,
metadata_configuration jsonb NULL,
created_at timestamptz NOT NULL default now(),
updated_at timestamptz NOT NULL default now()
);

ALTER TABLE storage.buckets_vectors ENABLE ROW LEVEL SECURITY;
ALTER TABLE storage.vector_indexes ENABLE ROW LEVEL SECURITY;

EXECUTE 'GRANT SELECT ON TABLE storage.buckets_vectors TO ' || service_role || ', ' || authenticated_role || ', ' || anon_role;
EXECUTE 'GRANT SELECT ON TABLE storage.vector_indexes TO ' || service_role || ', ' || authenticated_role || ', ' || anon_role;

CREATE UNIQUE INDEX IF NOT EXISTS vector_indexes_name_bucket_id_idx ON storage.vector_indexes (name, bucket_id);
END$$;
Loading
Loading