ci: attempt to fix Deployment
This commit is contained in:
@@ -6,8 +6,9 @@ metadata:
|
||||
labels:
|
||||
app: prisma-migrate
|
||||
spec:
|
||||
backoffLimit: 3
|
||||
ttlSecondsAfterFinished: 300
|
||||
backoffLimit: 1
|
||||
ttlSecondsAfterFinished: 86400
|
||||
activeDeadlineSeconds: 180
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
|
||||
@@ -2,22 +2,31 @@
|
||||
set -e
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 1. Resolve any previously failed migrations so deploy can proceed.
|
||||
# Only migrations explicitly marked as "Failed" in the status output are
|
||||
# resolved. We grep for lines containing "Failed" and extract the name.
|
||||
# 1. Print current migration status for debugging.
|
||||
# ---------------------------------------------------------------------------
|
||||
echo "[migrate] Checking for failed migrations..."
|
||||
echo "[migrate] Checking database migration status..."
|
||||
STATUS_OUTPUT=$(bunx prisma migrate status 2>&1 || true)
|
||||
echo "$STATUS_OUTPUT"
|
||||
|
||||
# Only resolve migrations whose status line explicitly says "Failed"
|
||||
echo "$STATUS_OUTPUT" | grep -i "failed" | grep -oE '[0-9]{14}_[a-zA-Z_]+' | while read -r MIGRATION; do
|
||||
# ---------------------------------------------------------------------------
|
||||
# 2. Resolve any "Failed" migrations as rolled-back so deploy can re-apply.
|
||||
# All migration SQL in this repo is written to be idempotent (using
|
||||
# IF NOT EXISTS / DO $$ ... $$ guards), so a re-run after resolving will
|
||||
# succeed even when schema drift has occurred from a prior db push.
|
||||
#
|
||||
# Regex matches both named (20260307010000_add_foo) and unnamed (20260125205653)
|
||||
# migration timestamps so the initial baseline migration is also covered.
|
||||
# ---------------------------------------------------------------------------
|
||||
FAILED=$(printf '%s\n' "$STATUS_OUTPUT" | grep -i "failed" | grep -oE '[0-9]{14}(_[a-zA-Z_]+)?' || true)
|
||||
|
||||
for MIGRATION in $FAILED; do
|
||||
echo "[migrate] Resolving failed migration: $MIGRATION"
|
||||
bunx prisma migrate resolve --rolled-back "$MIGRATION" || true
|
||||
bunx prisma migrate resolve --rolled-back "$MIGRATION"
|
||||
done
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 2. Deploy all pending migrations from the migrations directory.
|
||||
# 3. Deploy all pending migrations from the migrations directory.
|
||||
# ---------------------------------------------------------------------------
|
||||
echo "[migrate] Running prisma migrate deploy..."
|
||||
bunx prisma migrate deploy
|
||||
echo "[migrate] All migrations applied successfully."
|
||||
|
||||
+12
-3
@@ -1,10 +1,19 @@
|
||||
-- AlterTable: GeneratedQuotes — add columns missing from prior db push
|
||||
-- AlterTable: GeneratedQuotes — add columns missing from prior db push (idempotent)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'GeneratedQuotes' AND column_name = 'quoteRegenParams') THEN
|
||||
ALTER TABLE "GeneratedQuotes" ADD COLUMN "quoteRegenParams" JSONB NOT NULL DEFAULT '{}';
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'GeneratedQuotes' AND column_name = 'quoteRegenHash') THEN
|
||||
ALTER TABLE "GeneratedQuotes" ADD COLUMN "quoteRegenHash" TEXT NOT NULL DEFAULT '';
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'GeneratedQuotes' AND column_name = 'downloads') THEN
|
||||
ALTER TABLE "GeneratedQuotes" ADD COLUMN "downloads" JSONB NOT NULL DEFAULT '[]';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- AlterTable: GeneratedQuotes — set default on existing quoteRegenData column
|
||||
ALTER TABLE "GeneratedQuotes" ALTER COLUMN "quoteRegenData" SET DEFAULT '{}';
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "GeneratedQuotes_quoteRegenHash_key" ON "GeneratedQuotes"("quoteRegenHash");
|
||||
-- CreateIndex (idempotent)
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "GeneratedQuotes_quoteRegenHash_key" ON "GeneratedQuotes"("quoteRegenHash");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "CwMember" (
|
||||
-- CreateTable (idempotent)
|
||||
CREATE TABLE IF NOT EXISTS "CwMember" (
|
||||
"id" TEXT NOT NULL,
|
||||
"cwMemberId" INTEGER NOT NULL,
|
||||
"identifier" TEXT NOT NULL,
|
||||
@@ -15,8 +15,8 @@ CREATE TABLE "CwMember" (
|
||||
CONSTRAINT "CwMember_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "CwMember_cwMemberId_key" ON "CwMember"("cwMemberId");
|
||||
-- CreateIndex (idempotent)
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "CwMember_cwMemberId_key" ON "CwMember"("cwMemberId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "CwMember_identifier_key" ON "CwMember"("identifier");
|
||||
-- CreateIndex (idempotent)
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "CwMember_identifier_key" ON "CwMember"("identifier");
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
-- AlterTable
|
||||
-- AlterTable (idempotent)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'Opportunity' AND column_name = 'cwDateEntered') THEN
|
||||
ALTER TABLE "Opportunity" ADD COLUMN "cwDateEntered" TIMESTAMP(3);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
-- Rename the misspelled column serverityId -> severityId on ServiceTicket
|
||||
-- Rename the misspelled column serverityId -> severityId on ServiceTicket (idempotent)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'ServiceTicket' AND column_name = 'serverityId') THEN
|
||||
ALTER TABLE "ServiceTicket" RENAME COLUMN "serverityId" TO "severityId";
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
-- CreateEnum
|
||||
-- CreateEnum (idempotent)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'SyncJobType') THEN
|
||||
CREATE TYPE "SyncJobType" AS ENUM ('FULL_SYNC', 'INCREMENTAL_SYNC');
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- CreateEnum
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'SyncJobStatus') THEN
|
||||
CREATE TYPE "SyncJobStatus" AS ENUM ('QUEUED', 'RUNNING', 'COMPLETED', 'FAILED', 'TIMED_OUT');
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "SyncJobRun" (
|
||||
-- CreateTable (idempotent)
|
||||
CREATE TABLE IF NOT EXISTS "SyncJobRun" (
|
||||
"id" TEXT NOT NULL,
|
||||
"jobType" "SyncJobType" NOT NULL,
|
||||
"status" "SyncJobStatus" NOT NULL DEFAULT 'QUEUED',
|
||||
@@ -19,8 +28,7 @@ CREATE TABLE "SyncJobRun" (
|
||||
CONSTRAINT "SyncJobRun_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "SyncStepLog" (
|
||||
CREATE TABLE IF NOT EXISTS "SyncStepLog" (
|
||||
"id" TEXT NOT NULL,
|
||||
"syncJobRunId" TEXT NOT NULL,
|
||||
"tableName" TEXT NOT NULL,
|
||||
@@ -37,5 +45,14 @@ CREATE TABLE "SyncStepLog" (
|
||||
CONSTRAINT "SyncStepLog_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "SyncStepLog" ADD CONSTRAINT "SyncStepLog_syncJobRunId_fkey" FOREIGN KEY ("syncJobRunId") REFERENCES "SyncJobRun"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- AddForeignKey (idempotent)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_name = 'SyncStepLog_syncJobRunId_fkey'
|
||||
) THEN
|
||||
ALTER TABLE "SyncStepLog" ADD CONSTRAINT "SyncStepLog_syncJobRunId_fkey"
|
||||
FOREIGN KEY ("syncJobRunId") REFERENCES "SyncJobRun"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
Reference in New Issue
Block a user