mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 06:47:02 +08:00
fix: migration compatible for postgres (#12659)
fix AI-162 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Improved database migration scripts to prevent errors by ensuring changes are only applied if relevant tables exist. No visible changes to user features or functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,2 +1,9 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "ai_workspace_files" ADD COLUMN "blob_id" VARCHAR NOT NULL DEFAULT '';
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'ai_workspace_files') THEN
|
||||
-- AlterTable
|
||||
ALTER TABLE "ai_workspace_files"
|
||||
ADD COLUMN "blob_id" VARCHAR NOT NULL DEFAULT '';
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
@@ -5,16 +5,25 @@
|
||||
- The primary key for the `ai_workspace_file_embeddings` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||
|
||||
*/
|
||||
-- DropIndex
|
||||
DROP INDEX "ai_workspace_embeddings_workspace_id_doc_id_chunk_key";
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'ai_workspace_embeddings') AND
|
||||
EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'ai_workspace_file_embeddings') THEN
|
||||
-- DropIndex
|
||||
DROP INDEX "ai_workspace_embeddings_workspace_id_doc_id_chunk_key";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "ai_workspace_file_embeddings_workspace_id_file_id_chunk_key";
|
||||
-- DropIndex
|
||||
DROP INDEX "ai_workspace_file_embeddings_workspace_id_file_id_chunk_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "ai_workspace_embeddings" DROP CONSTRAINT "ai_workspace_embeddings_pkey",
|
||||
ADD CONSTRAINT "ai_workspace_embeddings_pkey" PRIMARY KEY ("workspace_id", "doc_id", "chunk");
|
||||
-- AlterTable
|
||||
ALTER TABLE "ai_workspace_embeddings"
|
||||
DROP CONSTRAINT "ai_workspace_embeddings_pkey",
|
||||
ADD CONSTRAINT "ai_workspace_embeddings_pkey" PRIMARY KEY ("workspace_id", "doc_id", "chunk");
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "ai_workspace_file_embeddings" DROP CONSTRAINT "ai_workspace_file_embeddings_pkey",
|
||||
ADD CONSTRAINT "ai_workspace_file_embeddings_pkey" PRIMARY KEY ("workspace_id", "file_id", "chunk");
|
||||
-- AlterTable
|
||||
ALTER TABLE "ai_workspace_file_embeddings"
|
||||
DROP CONSTRAINT "ai_workspace_file_embeddings_pkey",
|
||||
ADD CONSTRAINT "ai_workspace_file_embeddings_pkey" PRIMARY KEY ("workspace_id", "file_id", "chunk");
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
|
||||
Reference in New Issue
Block a user