1
+ DO $$
2
+ DECLARE
3
+ anon_role text = COALESCE(current_setting(' storage.anon_role' , true), ' anon' );
4
+ authenticated_role text = COALESCE(current_setting(' storage.authenticated_role' , true), ' authenticated' );
5
+ service_role text = COALESCE(current_setting(' storage.service_role' , true), ' service_role' );
6
+ BEGIN
7
+ CREATE TABLE IF NOT EXISTS storage .buckets_vectors (
8
+ id text not null primary key ,
9
+ type storage .BucketType NOT NULL default ' VECTOR' ,
10
+ created_at timestamptz NOT NULL default now(),
11
+ updated_at timestamptz NOT NULL default now()
12
+ );
13
+
14
+ CREATE TABLE IF NOT EXISTS storage .vector_indexes
15
+ (
16
+ id text primary key default gen_random_uuid(),
17
+ name text COLLATE " C" NOT NULL ,
18
+ bucket_id text NOT NULL references storage .buckets_vectors (id),
19
+ data_type text NOT NULL ,
20
+ dimension integer NOT NULL ,
21
+ distance_metric text NOT NULL ,
22
+ metadata_configuration jsonb NULL ,
23
+ created_at timestamptz NOT NULL default now(),
24
+ updated_at timestamptz NOT NULL default now()
25
+ );
26
+
27
+ ALTER TABLE storage .buckets_vectors ENABLE ROW LEVEL SECURITY;
28
+ ALTER TABLE storage .vector_indexes ENABLE ROW LEVEL SECURITY;
29
+
30
+ EXECUTE ' GRANT SELECT ON TABLE storage.buckets_vectors TO ' || service_role || ' , ' || authenticated_role || ' , ' || anon_role;
31
+ EXECUTE ' GRANT SELECT ON TABLE storage.vector_indexes TO ' || service_role || ' , ' || authenticated_role || ' , ' || anon_role;
32
+
33
+ CREATE UNIQUE INDEX IF NOT EXISTS vector_indexes_name_bucket_id_idx ON storage .vector_indexes (name, bucket_id);
34
+ END$$;
0 commit comments