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

@@ -51,7 +51,12 @@ jobs:
- name: Setup test database
run: |
apt-get update && apt-get install -y postgresql-client
sudo apt-get update -qq && sudo apt-get install -y -qq postgresql-client
for i in $(seq 1 30); do
PGPASSWORD=memento_test pg_isready -h postgres -U memento_test -d memento_test && break
[ "$i" -eq 30 ] && exit 1
sleep 2
done
PGPASSWORD=memento_test psql -h postgres -U memento_test -d memento_test -c "CREATE EXTENSION IF NOT EXISTS vector;"
npx prisma migrate deploy

View File

@@ -121,9 +121,8 @@ jobs:
git fetch origin main
git reset --hard origin/main
echo "=== Pull & recreate postgres with pgvector ==="
docker compose pull postgres
docker compose up -d --force-recreate postgres
echo "=== Ensure postgres is running (no recreate — prod data) ==="
docker compose up -d postgres
echo "=== Waiting for postgres healthy ==="
for i in $(seq 1 30); do
@@ -153,9 +152,6 @@ jobs:
fi
echo "Backup saved: $DUMP_FILE ($(( DUMP_SIZE / 1024 ))KB)"
echo "=== Resolve failed prisma migrations ==="
docker compose exec -T postgres psql -U "${POSTGRES_USER:-memento}" -d "${POSTGRES_DB:-memento}" -c "UPDATE \"_prisma_migrations\" SET \"finished_at\"=NOW(), \"rolled_back_at\"=NULL WHERE \"finished_at\" IS NULL AND \"rolled_back_at\" IS NULL;" || true
echo "=== Building app images ==="
docker compose build memento-note
docker compose build mcp-server

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 $$;