From cbafffdf1bf06541dc628044f0fa2b2706f4d223 Mon Sep 17 00:00:00 2001 From: Timo Knuth Date: Fri, 23 Jan 2026 16:22:07 +0100 Subject: [PATCH] Add Prisma migrations to version control - fixes deployment sync issue --- .gitignore | 2 +- .../20251013172642_init/migration.sql | 146 ++++++++++++++++++ .../20251014195005_init/migration.sql | 22 +++ .../migration.sql | 67 ++++++++ .../migration.sql | 31 ++++ 5 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/20251013172642_init/migration.sql create mode 100644 prisma/migrations/20251014195005_init/migration.sql create mode 100644 prisma/migrations/20260116161126_add_lead_model/migration.sql create mode 100644 prisma/migrations/20260123082730_add_app_coupon_feedback_contenttypes/migration.sql diff --git a/.gitignore b/.gitignore index bef31a7..e1dbe03 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ yarn-error.log* next-env.d.ts # prisma -/prisma/migrations/ +# /prisma/migrations/ # Now tracked in Git for deployment # docker docker-compose.override.yml diff --git a/prisma/migrations/20251013172642_init/migration.sql b/prisma/migrations/20251013172642_init/migration.sql new file mode 100644 index 0000000..f491598 --- /dev/null +++ b/prisma/migrations/20251013172642_init/migration.sql @@ -0,0 +1,146 @@ +-- CreateEnum +CREATE TYPE "QRType" AS ENUM ('STATIC', 'DYNAMIC'); + +-- CreateEnum +CREATE TYPE "ContentType" AS ENUM ('URL', 'WIFI', 'VCARD', 'PHONE', 'EMAIL', 'SMS', 'TEXT', 'WHATSAPP'); + +-- CreateEnum +CREATE TYPE "QRStatus" AS ENUM ('ACTIVE', 'PAUSED'); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL, + "email" TEXT NOT NULL, + "name" TEXT, + "password" TEXT, + "image" TEXT, + "emailVerified" TIMESTAMP(3), + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Account" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "type" TEXT NOT NULL, + "provider" TEXT NOT NULL, + "providerAccountId" TEXT NOT NULL, + "refresh_token" TEXT, + "access_token" TEXT, + "expires_at" INTEGER, + "token_type" TEXT, + "scope" TEXT, + "id_token" TEXT, + "session_state" TEXT, + + CONSTRAINT "Account_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Session" ( + "id" TEXT NOT NULL, + "sessionToken" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "expires" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Session_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "VerificationToken" ( + "identifier" TEXT NOT NULL, + "token" TEXT NOT NULL, + "expires" TIMESTAMP(3) NOT NULL +); + +-- CreateTable +CREATE TABLE "QRCode" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "title" TEXT NOT NULL, + "type" "QRType" NOT NULL DEFAULT 'DYNAMIC', + "contentType" "ContentType" NOT NULL DEFAULT 'URL', + "content" JSONB NOT NULL, + "tags" TEXT[], + "status" "QRStatus" NOT NULL DEFAULT 'ACTIVE', + "style" JSONB NOT NULL, + "slug" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "QRCode_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "QRScan" ( + "id" TEXT NOT NULL, + "qrId" TEXT NOT NULL, + "ts" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "ipHash" TEXT NOT NULL, + "userAgent" TEXT, + "device" TEXT, + "os" TEXT, + "country" TEXT, + "referrer" TEXT, + "utmSource" TEXT, + "utmMedium" TEXT, + "utmCampaign" TEXT, + "isUnique" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "QRScan_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Integration" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "provider" TEXT NOT NULL, + "status" TEXT NOT NULL DEFAULT 'inactive', + "config" JSONB NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Integration_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); + +-- CreateIndex +CREATE UNIQUE INDEX "QRCode_slug_key" ON "QRCode"("slug"); + +-- CreateIndex +CREATE INDEX "QRCode_userId_createdAt_idx" ON "QRCode"("userId", "createdAt"); + +-- CreateIndex +CREATE INDEX "QRScan_qrId_ts_idx" ON "QRScan"("qrId", "ts"); + +-- AddForeignKey +ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "QRCode" ADD CONSTRAINT "QRCode_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "QRScan" ADD CONSTRAINT "QRScan_qrId_fkey" FOREIGN KEY ("qrId") REFERENCES "QRCode"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Integration" ADD CONSTRAINT "Integration_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20251014195005_init/migration.sql b/prisma/migrations/20251014195005_init/migration.sql new file mode 100644 index 0000000..6c25fc5 --- /dev/null +++ b/prisma/migrations/20251014195005_init/migration.sql @@ -0,0 +1,22 @@ +/* + Warnings: + + - A unique constraint covering the columns `[stripeCustomerId]` on the table `User` will be added. If there are existing duplicate values, this will fail. + - A unique constraint covering the columns `[stripeSubscriptionId]` on the table `User` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateEnum +CREATE TYPE "Plan" AS ENUM ('FREE', 'PRO', 'BUSINESS'); + +-- AlterTable +ALTER TABLE "User" ADD COLUMN "plan" "Plan" NOT NULL DEFAULT 'FREE', +ADD COLUMN "stripeCurrentPeriodEnd" TIMESTAMP(3), +ADD COLUMN "stripeCustomerId" TEXT, +ADD COLUMN "stripePriceId" TEXT, +ADD COLUMN "stripeSubscriptionId" TEXT; + +-- CreateIndex +CREATE UNIQUE INDEX "User_stripeCustomerId_key" ON "User"("stripeCustomerId"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_stripeSubscriptionId_key" ON "User"("stripeSubscriptionId"); diff --git a/prisma/migrations/20260116161126_add_lead_model/migration.sql b/prisma/migrations/20260116161126_add_lead_model/migration.sql new file mode 100644 index 0000000..9e81366 --- /dev/null +++ b/prisma/migrations/20260116161126_add_lead_model/migration.sql @@ -0,0 +1,67 @@ +/* + Warnings: + + - The values [WIFI,EMAIL] on the enum `ContentType` will be removed. If these variants are still used in the database, this will fail. + - A unique constraint covering the columns `[resetPasswordToken]` on the table `User` will be added. If there are existing duplicate values, this will fail. + +*/ +-- AlterEnum +BEGIN; +CREATE TYPE "ContentType_new" AS ENUM ('URL', 'VCARD', 'GEO', 'PHONE', 'SMS', 'TEXT', 'WHATSAPP'); +ALTER TABLE "QRCode" ALTER COLUMN "contentType" DROP DEFAULT; +ALTER TABLE "QRCode" ALTER COLUMN "contentType" TYPE "ContentType_new" USING ("contentType"::text::"ContentType_new"); +ALTER TYPE "ContentType" RENAME TO "ContentType_old"; +ALTER TYPE "ContentType_new" RENAME TO "ContentType"; +DROP TYPE "ContentType_old"; +ALTER TABLE "QRCode" ALTER COLUMN "contentType" SET DEFAULT 'URL'; +COMMIT; + +-- AlterTable +ALTER TABLE "User" ADD COLUMN "resetPasswordExpires" TIMESTAMP(3), +ADD COLUMN "resetPasswordToken" TEXT; + +-- CreateTable +CREATE TABLE "NewsletterSubscription" ( + "id" TEXT NOT NULL, + "email" TEXT NOT NULL, + "source" TEXT NOT NULL DEFAULT 'ai-coming-soon', + "status" TEXT NOT NULL DEFAULT 'subscribed', + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "NewsletterSubscription_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Lead" ( + "id" TEXT NOT NULL, + "email" TEXT NOT NULL, + "source" TEXT NOT NULL DEFAULT 'reprint-calculator', + "reprintCost" DOUBLE PRECISION, + "updatesPerYear" INTEGER, + "annualSavings" DOUBLE PRECISION, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Lead_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "NewsletterSubscription_email_key" ON "NewsletterSubscription"("email"); + +-- CreateIndex +CREATE INDEX "NewsletterSubscription_email_idx" ON "NewsletterSubscription"("email"); + +-- CreateIndex +CREATE INDEX "NewsletterSubscription_createdAt_idx" ON "NewsletterSubscription"("createdAt"); + +-- CreateIndex +CREATE INDEX "Lead_email_idx" ON "Lead"("email"); + +-- CreateIndex +CREATE INDEX "Lead_createdAt_idx" ON "Lead"("createdAt"); + +-- CreateIndex +CREATE INDEX "Lead_source_idx" ON "Lead"("source"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_resetPasswordToken_key" ON "User"("resetPasswordToken"); diff --git a/prisma/migrations/20260123082730_add_app_coupon_feedback_contenttypes/migration.sql b/prisma/migrations/20260123082730_add_app_coupon_feedback_contenttypes/migration.sql new file mode 100644 index 0000000..d071c59 --- /dev/null +++ b/prisma/migrations/20260123082730_add_app_coupon_feedback_contenttypes/migration.sql @@ -0,0 +1,31 @@ +/* + Warnings: + + - Added the required column `updatedAt` to the `Lead` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterEnum +-- This migration adds more than one value to an enum. +-- With PostgreSQL versions 11 and earlier, this is not possible +-- in a single migration. This can be worked around by creating +-- multiple migrations, each migration adding only one value to +-- the enum. + + +ALTER TYPE "ContentType" ADD VALUE 'PDF'; +ALTER TYPE "ContentType" ADD VALUE 'APP'; +ALTER TYPE "ContentType" ADD VALUE 'COUPON'; +ALTER TYPE "ContentType" ADD VALUE 'FEEDBACK'; + +-- DropIndex +DROP INDEX "Lead_createdAt_idx"; + +-- DropIndex +DROP INDEX "Lead_email_idx"; + +-- DropIndex +DROP INDEX "Lead_source_idx"; + +-- AlterTable +ALTER TABLE "Lead" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL, +ALTER COLUMN "updatesPerYear" SET DATA TYPE DOUBLE PRECISION;