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 @@
|
|||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'ai_workspace_files') THEN
|
||||||
-- AlterTable
|
-- AlterTable
|
||||||
ALTER TABLE "ai_workspace_files" ADD COLUMN "blob_id" VARCHAR NOT NULL DEFAULT '';
|
ALTER TABLE "ai_workspace_files"
|
||||||
|
ADD COLUMN "blob_id" VARCHAR NOT NULL DEFAULT '';
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
@@ -5,6 +5,10 @@
|
|||||||
- 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.
|
- 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.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
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
|
-- DropIndex
|
||||||
DROP INDEX "ai_workspace_embeddings_workspace_id_doc_id_chunk_key";
|
DROP INDEX "ai_workspace_embeddings_workspace_id_doc_id_chunk_key";
|
||||||
|
|
||||||
@@ -12,9 +16,14 @@ DROP INDEX "ai_workspace_embeddings_workspace_id_doc_id_chunk_key";
|
|||||||
DROP INDEX "ai_workspace_file_embeddings_workspace_id_file_id_chunk_key";
|
DROP INDEX "ai_workspace_file_embeddings_workspace_id_file_id_chunk_key";
|
||||||
|
|
||||||
-- AlterTable
|
-- AlterTable
|
||||||
ALTER TABLE "ai_workspace_embeddings" DROP CONSTRAINT "ai_workspace_embeddings_pkey",
|
ALTER TABLE "ai_workspace_embeddings"
|
||||||
|
DROP CONSTRAINT "ai_workspace_embeddings_pkey",
|
||||||
ADD CONSTRAINT "ai_workspace_embeddings_pkey" PRIMARY KEY ("workspace_id", "doc_id", "chunk");
|
ADD CONSTRAINT "ai_workspace_embeddings_pkey" PRIMARY KEY ("workspace_id", "doc_id", "chunk");
|
||||||
|
|
||||||
-- AlterTable
|
-- AlterTable
|
||||||
ALTER TABLE "ai_workspace_file_embeddings" DROP CONSTRAINT "ai_workspace_file_embeddings_pkey",
|
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");
|
ADD CONSTRAINT "ai_workspace_file_embeddings_pkey" PRIMARY KEY ("workspace_id", "file_id", "chunk");
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
|||||||
Reference in New Issue
Block a user