fix(ci): migrations idempotentes et deploy prod sans toucher Postgres
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:
@@ -51,7 +51,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Setup test database
|
- name: Setup test database
|
||||||
run: |
|
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;"
|
PGPASSWORD=memento_test psql -h postgres -U memento_test -d memento_test -c "CREATE EXTENSION IF NOT EXISTS vector;"
|
||||||
npx prisma migrate deploy
|
npx prisma migrate deploy
|
||||||
|
|
||||||
|
|||||||
@@ -121,9 +121,8 @@ jobs:
|
|||||||
git fetch origin main
|
git fetch origin main
|
||||||
git reset --hard origin/main
|
git reset --hard origin/main
|
||||||
|
|
||||||
echo "=== Pull & recreate postgres with pgvector ==="
|
echo "=== Ensure postgres is running (no recreate — prod data) ==="
|
||||||
docker compose pull postgres
|
docker compose up -d postgres
|
||||||
docker compose up -d --force-recreate postgres
|
|
||||||
|
|
||||||
echo "=== Waiting for postgres healthy ==="
|
echo "=== Waiting for postgres healthy ==="
|
||||||
for i in $(seq 1 30); do
|
for i in $(seq 1 30); do
|
||||||
@@ -153,9 +152,6 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
echo "Backup saved: $DUMP_FILE ($(( DUMP_SIZE / 1024 ))KB)"
|
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 ==="
|
echo "=== Building app images ==="
|
||||||
docker compose build memento-note
|
docker compose build memento-note
|
||||||
docker compose build mcp-server
|
docker compose build mcp-server
|
||||||
|
|||||||
@@ -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");
|
CREATE INDEX IF NOT EXISTS "NoteShare_sharedBy_idx" ON "NoteShare"("sharedBy");
|
||||||
|
|
||||||
-- Add unique constraint for MemoryEchoInsight (idempotent)
|
-- Add unique constraint for MemoryEchoInsight (idempotent)
|
||||||
|
-- init migration may already have created these as UNIQUE INDEXes (same relation name)
|
||||||
DO $$ BEGIN
|
DO $$ BEGIN
|
||||||
ALTER TABLE "MemoryEchoInsight" ADD CONSTRAINT "MemoryEchoInsight_userId_insightDate_key" UNIQUE ("userId", "insightDate");
|
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 $$;
|
END $$;
|
||||||
|
|
||||||
-- Add unique constraint for NoteShare (idempotent)
|
-- Add unique constraint for NoteShare (idempotent)
|
||||||
DO $$ BEGIN
|
DO $$ BEGIN
|
||||||
ALTER TABLE "NoteShare" ADD CONSTRAINT "NoteShare_noteId_userId_key" UNIQUE ("noteId", "userId");
|
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 $$;
|
END $$;
|
||||||
|
|
||||||
-- Fix Note.notebookId foreign key to use ON DELETE SET NULL (idempotent)
|
-- Fix Note.notebookId foreign key to use ON DELETE SET NULL (idempotent)
|
||||||
|
|||||||
@@ -1,18 +1,32 @@
|
|||||||
-- AlterTable
|
-- AlterTable Label (may already exist from 20260509160000_add_missing_columns)
|
||||||
ALTER TABLE "Label" ADD COLUMN "type" TEXT NOT NULL DEFAULT 'user';
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "Label" ADD COLUMN "type" TEXT NOT NULL DEFAULT 'user';
|
||||||
|
EXCEPTION WHEN duplicate_column THEN NULL;
|
||||||
|
END $$;
|
||||||
|
|
||||||
-- AlterTable
|
-- AlterTable UserAISettings
|
||||||
ALTER TABLE "UserAISettings" ADD COLUMN "autoSave" BOOLEAN NOT NULL DEFAULT true;
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "UserAISettings" ADD COLUMN "autoSave" BOOLEAN NOT NULL DEFAULT true;
|
||||||
|
EXCEPTION WHEN duplicate_column THEN NULL;
|
||||||
|
END $$;
|
||||||
|
|
||||||
-- AlterTable
|
-- AlterTable Notebook
|
||||||
ALTER TABLE "Notebook" ADD COLUMN "parentId" TEXT,
|
DO $$ BEGIN
|
||||||
ADD COLUMN "trashedAt" TIMESTAMP(3);
|
ALTER TABLE "Notebook" ADD COLUMN "parentId" TEXT;
|
||||||
|
EXCEPTION WHEN duplicate_column THEN NULL;
|
||||||
|
END $$;
|
||||||
|
|
||||||
-- CreateIndex
|
DO $$ BEGIN
|
||||||
CREATE INDEX "Notebook_parentId_idx" ON "Notebook"("parentId");
|
ALTER TABLE "Notebook" ADD COLUMN "trashedAt" TIMESTAMP(3);
|
||||||
|
EXCEPTION WHEN duplicate_column THEN NULL;
|
||||||
|
END $$;
|
||||||
|
|
||||||
-- CreateIndex
|
CREATE INDEX IF NOT EXISTS "Notebook_parentId_idx" ON "Notebook"("parentId");
|
||||||
CREATE INDEX "Notebook_trashedAt_idx" ON "Notebook"("trashedAt");
|
CREATE INDEX IF NOT EXISTS "Notebook_trashedAt_idx" ON "Notebook"("trashedAt");
|
||||||
|
|
||||||
-- AddForeignKey
|
DO $$ BEGIN
|
||||||
ALTER TABLE "Notebook" ADD CONSTRAINT "Notebook_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Notebook"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
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 $$;
|
||||||
|
|||||||
Reference in New Issue
Block a user