Merge pull request #624 from AppFlowy-IO/embedding-migration-optional

chore: make vector extension optional for migrations
This commit is contained in:
Zack 2024-06-15 01:50:43 +08:00 committed by GitHub
commit 7b593c599b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 17 deletions

View File

@ -1,17 +0,0 @@
-- 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 INDEX IF NOT EXISTS af_collab_embeddings_similarity_idx ON af_collab_embeddings USING hnsw (embedding vector_cosine_ops);

View File

@ -0,0 +1,24 @@
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 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;