From 709f8c3cdfb62315be27af1d970b1e4fd30beac1 Mon Sep 17 00:00:00 2001 From: Bartosz Sypytkowski Date: Fri, 14 Jun 2024 19:03:03 +0200 Subject: [PATCH 1/2] chore: make vector extension optional for migrations --- .../20240521092310_collab_embeddings.sql | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/migrations/20240521092310_collab_embeddings.sql b/migrations/20240521092310_collab_embeddings.sql index 74836a3f..7377990f 100644 --- a/migrations/20240521092310_collab_embeddings.sql +++ b/migrations/20240521092310_collab_embeddings.sql @@ -1,17 +1,24 @@ --- Add migration script here -CREATE EXTENSION IF NOT EXISTS vector; +DO $$ +BEGIN + -- Add migration script here + CREATE EXTENSION IF NOT EXISTS vector; --- create table to store collab embeddings -CREATE TABLE IF NOT EXISTS af_collab_embeddings -( - fragment_id TEXT NOT NULL PRIMARY KEY, - oid TEXT NOT NULL, - partition_key INTEGER NOT NULL, - content_type INTEGER NOT NULL, - indexed_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT (NOW()), - content TEXT, - embedding VECTOR(1536), - FOREIGN KEY (oid, partition_key) REFERENCES af_collab (oid, partition_key) ON DELETE CASCADE -); + -- create table to store collab embeddings + CREATE TABLE IF NOT EXISTS af_collab_embeddings + ( + fragment_id TEXT NOT NULL PRIMARY KEY, + oid TEXT NOT NULL, + partition_key INTEGER NOT NULL, + content_type INTEGER NOT NULL, + indexed_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT (NOW()), + content TEXT, + embedding VECTOR(1536), + FOREIGN KEY (oid, partition_key) REFERENCES af_collab (oid, partition_key) ON DELETE CASCADE + ); -CREATE INDEX IF NOT EXISTS af_collab_embeddings_similarity_idx ON af_collab_embeddings USING hnsw (embedding vector_cosine_ops); \ No newline at end of file + CREATE INDEX IF NOT EXISTS af_collab_embeddings_similarity_idx ON af_collab_embeddings USING hnsw (embedding vector_cosine_ops); + +EXCEPTION WHEN OTHERS THEN + RAISE NOTICE 'could not create "vector" extension, ignoring this migration'; +END; +$$ LANGUAGE plpgsql; \ No newline at end of file From 01aae523a97dd40177e81357bb4fa3b546472a58 Mon Sep 17 00:00:00 2001 From: Bartosz Sypytkowski Date: Fri, 14 Jun 2024 19:24:55 +0200 Subject: [PATCH 2/2] chore: moved migration to new file --- ...collab_embeddings.sql => 20240614171931_collab_embeddings.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename migrations/{20240521092310_collab_embeddings.sql => 20240614171931_collab_embeddings.sql} (100%) diff --git a/migrations/20240521092310_collab_embeddings.sql b/migrations/20240614171931_collab_embeddings.sql similarity index 100% rename from migrations/20240521092310_collab_embeddings.sql rename to migrations/20240614171931_collab_embeddings.sql