From dabe6b6268ba2f0398e668584ced40d0e56193f8 Mon Sep 17 00:00:00 2001 From: Tero Halla-aho Date: Sat, 20 Dec 2025 22:35:30 +0200 Subject: [PATCH 1/2] Restore agent billing migration --- PROGRESS.md | 4 ++++ .../20251212_agent_billing/migration.sql | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 prisma/migrations/20251212_agent_billing/migration.sql diff --git a/PROGRESS.md b/PROGRESS.md index a08f79f..d36caed 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -97,3 +97,7 @@ - Navbar: combined admin actions (approvals/users/monitoring) under a single “Admin” dropdown menu. - Pricing copy: treat listing prices as indicative “starting from” values and show starting-from line on browse cards + home latest carousel. - Site settings page added with a toggle to require login for listing contact details; contact info is now hidden from logged-out visitors. + +## 2025-12-20 — Migration history repair +- Restored missing migration `20251212_agent_billing` (agent billing columns + listing billing settings table) so Prisma history matches the DB. +- Reconciled test DB migration history: aligned checksum for `20251212_agent_billing` and marked `20260310_site_settings` and `20260311_billing_preferences` as applied to stop Prisma errors and surface listings again. diff --git a/prisma/migrations/20251212_agent_billing/migration.sql b/prisma/migrations/20251212_agent_billing/migration.sql new file mode 100644 index 0000000..685f115 --- /dev/null +++ b/prisma/migrations/20251212_agent_billing/migration.sql @@ -0,0 +1,19 @@ +-- Agent billing preferences and per-listing overrides (legacy) + +ALTER TABLE "User" +ADD COLUMN "agentBillingEnabled" BOOLEAN NOT NULL DEFAULT FALSE, +ADD COLUMN "agentBankAccount" TEXT, +ADD COLUMN "agentVatBreakdownRequired" BOOLEAN NOT NULL DEFAULT FALSE, +ADD COLUMN "agentUseListingOverrides" BOOLEAN NOT NULL DEFAULT FALSE; + +CREATE TABLE "ListingBillingSettings" ( + "id" TEXT NOT NULL, + "listingId" TEXT NOT NULL, + "bankAccount" TEXT, + "vatBreakdownRequired" BOOLEAN NOT NULL DEFAULT FALSE, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT "ListingBillingSettings_pkey" PRIMARY KEY ("id"), + CONSTRAINT "ListingBillingSettings_listingId_key" UNIQUE ("listingId"), + CONSTRAINT "ListingBillingSettings_listingId_fkey" FOREIGN KEY ("listingId") REFERENCES "Listing"("id") ON DELETE CASCADE ON UPDATE CASCADE +); From ed67f4305a4a39a33bd0993ab03e348b8ff7cf64 Mon Sep 17 00:00:00 2001 From: Tero Halla-aho Date: Sat, 20 Dec 2025 22:59:48 +0200 Subject: [PATCH 2/2] Add migration preflight and sync prod DB --- PROGRESS.md | 2 ++ deploy/deploy.sh | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/PROGRESS.md b/PROGRESS.md index d36caed..8bb1564 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -101,3 +101,5 @@ ## 2025-12-20 — Migration history repair - Restored missing migration `20251212_agent_billing` (agent billing columns + listing billing settings table) so Prisma history matches the DB. - Reconciled test DB migration history: aligned checksum for `20251212_agent_billing` and marked `20260310_site_settings` and `20260311_billing_preferences` as applied to stop Prisma errors and surface listings again. +- Applied the same agent billing schema to staging/prod DB (`lomavuokraus`) and marked the migration as applied; Prisma status now clean there too. +- Deploy script now runs a Prisma migration status preflight using DATABASE_URL from env or in-cluster secret and fails fast on drift before applying manifests. diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 4b19c27..4d1320d 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -71,7 +71,7 @@ APP_VERSION="${APP_VERSION:-$(echo \"$IMAGE\" | awk -F: '{print $NF}')}" export K8S_NAMESPACE APP_HOST API_HOST NEXT_PUBLIC_SITE_URL NEXT_PUBLIC_API_BASE APP_ENV CLUSTER_ISSUER INGRESS_CLASS APP_REPLICAS K8S_IMAGE APP_VERSION -maybe_run_prisma_migrations() { +resolve_database_url() { local db_url="${DATABASE_URL:-}" if [[ -z "$db_url" ]]; then # If DATABASE_URL isn't available locally, try to reuse the in-cluster secret. @@ -87,6 +87,25 @@ maybe_run_prisma_migrations() { fi fi + echo "$db_url" +} + +prisma_preflight() { + local db_url="$1" + if [[ -z "$db_url" ]]; then + echo "DATABASE_URL unavailable; skipping Prisma status preflight" >&2 + return 0 + fi + + echo "Prisma preflight: checking migration status for APP_ENV=$APP_ENV (namespace=$K8S_NAMESPACE)" + if ! DATABASE_URL="$db_url" npx prisma migrate status >/dev/null; then + echo "Prisma migrate status failed. Fix migration history before deploying." >&2 + exit 1 + fi +} + +maybe_run_prisma_migrations() { + local db_url="$1" if [[ -n "$db_url" ]]; then echo "Running Prisma migrations for APP_ENV=$APP_ENV (namespace=$K8S_NAMESPACE)" DATABASE_URL="$db_url" npx prisma migrate deploy @@ -95,7 +114,9 @@ maybe_run_prisma_migrations() { fi } -maybe_run_prisma_migrations +DB_URL_FOR_DEPLOY="$(resolve_database_url)" +prisma_preflight "$DB_URL_FOR_DEPLOY" +maybe_run_prisma_migrations "$DB_URL_FOR_DEPLOY" TMP_MANIFEST=$(mktemp) envsubst < k8s/app.yaml > "$TMP_MANIFEST"