fix(ci): migrations idempotentes et deploy prod sans toucher Postgres
Some checks failed
CI / Lint, Test & Build (push) Failing after 5m48s
Deploy to Production / Build and Deploy (push) Has been cancelled

Les migrations échouaient sur une base vide (contraintes/index déjà créés par init).
Le workflow deploy ne recrée plus Postgres ni ne force les entrées _prisma_migrations.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Antigravity
2026-05-17 08:53:29 +00:00
parent bd214f010e
commit b5fb439592
4 changed files with 42 additions and 22 deletions

View File

@@ -41,15 +41,20 @@ CREATE INDEX IF NOT EXISTS "NoteShare_status_idx" ON "NoteShare"("status");
CREATE INDEX IF NOT EXISTS "NoteShare_sharedBy_idx" ON "NoteShare"("sharedBy");
-- Add unique constraint for MemoryEchoInsight (idempotent)
-- init migration may already have created these as UNIQUE INDEXes (same relation name)
DO $$ BEGIN
ALTER TABLE "MemoryEchoInsight" ADD CONSTRAINT "MemoryEchoInsight_userId_insightDate_key" UNIQUE ("userId", "insightDate");
EXCEPTION WHEN duplicate_object THEN NULL;
EXCEPTION
WHEN duplicate_object THEN NULL;
WHEN duplicate_table THEN NULL;
END $$;
-- Add unique constraint for NoteShare (idempotent)
DO $$ BEGIN
ALTER TABLE "NoteShare" ADD CONSTRAINT "NoteShare_noteId_userId_key" UNIQUE ("noteId", "userId");
EXCEPTION WHEN duplicate_object THEN NULL;
EXCEPTION
WHEN duplicate_object THEN NULL;
WHEN duplicate_table THEN NULL;
END $$;
-- Fix Note.notebookId foreign key to use ON DELETE SET NULL (idempotent)

View File

@@ -1,18 +1,32 @@
-- AlterTable
ALTER TABLE "Label" ADD COLUMN "type" TEXT NOT NULL DEFAULT 'user';
-- AlterTable Label (may already exist from 20260509160000_add_missing_columns)
DO $$ BEGIN
ALTER TABLE "Label" ADD COLUMN "type" TEXT NOT NULL DEFAULT 'user';
EXCEPTION WHEN duplicate_column THEN NULL;
END $$;
-- AlterTable
ALTER TABLE "UserAISettings" ADD COLUMN "autoSave" BOOLEAN NOT NULL DEFAULT true;
-- AlterTable UserAISettings
DO $$ BEGIN
ALTER TABLE "UserAISettings" ADD COLUMN "autoSave" BOOLEAN NOT NULL DEFAULT true;
EXCEPTION WHEN duplicate_column THEN NULL;
END $$;
-- AlterTable
ALTER TABLE "Notebook" ADD COLUMN "parentId" TEXT,
ADD COLUMN "trashedAt" TIMESTAMP(3);
-- AlterTable Notebook
DO $$ BEGIN
ALTER TABLE "Notebook" ADD COLUMN "parentId" TEXT;
EXCEPTION WHEN duplicate_column THEN NULL;
END $$;
-- CreateIndex
CREATE INDEX "Notebook_parentId_idx" ON "Notebook"("parentId");
DO $$ BEGIN
ALTER TABLE "Notebook" ADD COLUMN "trashedAt" TIMESTAMP(3);
EXCEPTION WHEN duplicate_column THEN NULL;
END $$;
-- CreateIndex
CREATE INDEX "Notebook_trashedAt_idx" ON "Notebook"("trashedAt");
CREATE INDEX IF NOT EXISTS "Notebook_parentId_idx" ON "Notebook"("parentId");
CREATE INDEX IF NOT EXISTS "Notebook_trashedAt_idx" ON "Notebook"("trashedAt");
-- AddForeignKey
ALTER TABLE "Notebook" ADD CONSTRAINT "Notebook_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Notebook"("id") ON DELETE CASCADE ON UPDATE CASCADE;
DO $$ BEGIN
ALTER TABLE "Notebook" ADD CONSTRAINT "Notebook_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Notebook"("id") ON DELETE CASCADE ON UPDATE CASCADE;
EXCEPTION
WHEN duplicate_object THEN NULL;
WHEN duplicate_table THEN NULL;
END $$;