sanamare/prisma/migrations/20261111040000_creators/migration.sql
Claude d218ec5b8c Creator-Programm Phase 1: persönliche Codes, Link /c/CODE, Provisionen, Admin und Creator-Bereich
- Creator-Code = Gutschein mit Creator; Stufen mit Rabatt (Prozent/Festbetrag, Deckel, Mindestwert) und Provision, Werte je Creator überschreibbar
- Ausschlüsse: global je Kategorie, je Stufe (Produkte/Kategorien), Schalter am Produkt; Artikel im Sale ausgenommen
- Link /c/CODE[/pfad] merkt den Code (Cookie, 30 Tage), zählt Klicks ohne IP, Hinweis oben im Shop
- Bestellung friert Creator, Stufe, Satz und Netto-Basis ein; Rabattanteil je Position (auch für Rechnungs-Steuern)
- Provision: vorgemerkt, Freigabe nach Haltefrist ab Versand (Kurse: ab Zahlung), Storno vor/nach Auszahlung, Auszahlung verbuchen
- Admin /admin/creator (Liste, Detail, Stufen, Einstellungen), Rechte creators.*, Badge in Bestellungen
- Kundenkonto /konto/creator: Bedingungen bestätigen, Code/Link, Zahlen je Monat, Provisionen, IBAN und Steuerstatus
- Kein Rabatt auf eigene Bestellungen, Willkommens-Mail, Datenschutz-/AGB-Vorlagen ergänzt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HsJ4RG9iGFNcNnG8YcScYE
2026-11-11 04:37:48 +01:00

146 lines
5.6 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- AlterTable
ALTER TABLE "Coupon" ADD COLUMN "creatorId" TEXT;
-- AlterTable
ALTER TABLE "Order" ADD COLUMN "commissionBase" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "commissionRate" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "creatorId" TEXT,
ADD COLUMN "creatorTier" TEXT NOT NULL DEFAULT '';
-- AlterTable
ALTER TABLE "OrderItem" ADD COLUMN "discount" INTEGER NOT NULL DEFAULT 0;
-- AlterTable
ALTER TABLE "Product" ADD COLUMN "noCreatorDiscount" BOOLEAN NOT NULL DEFAULT false;
-- CreateTable
CREATE TABLE "CreatorTier" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"sort" INTEGER NOT NULL DEFAULT 0,
"discountType" TEXT NOT NULL DEFAULT 'percent',
"discountValue" INTEGER NOT NULL DEFAULT 5,
"discountCap" INTEGER NOT NULL DEFAULT 0,
"commissionRate" INTEGER NOT NULL DEFAULT 700,
"minOrder" INTEGER NOT NULL DEFAULT 0,
"upgradeFrom" INTEGER NOT NULL DEFAULT 0,
"extras" TEXT NOT NULL DEFAULT '',
"excludedProductIds" TEXT[],
"excludedCategoryIds" TEXT[],
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "CreatorTier_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Creator" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"status" TEXT NOT NULL DEFAULT 'active',
"tierId" TEXT NOT NULL,
"discountType" TEXT,
"discountValue" INTEGER,
"discountCap" INTEGER,
"commissionRate" INTEGER,
"channels" TEXT NOT NULL DEFAULT '',
"focus" TEXT NOT NULL DEFAULT '',
"taxStatus" TEXT NOT NULL DEFAULT '',
"vatId" TEXT NOT NULL DEFAULT '',
"accountHolder" TEXT NOT NULL DEFAULT '',
"iban" TEXT NOT NULL DEFAULT '',
"payoutMethod" TEXT NOT NULL DEFAULT 'transfer',
"termsAcceptedAt" TIMESTAMP(3),
"termsVersion" TEXT NOT NULL DEFAULT '',
"note" TEXT NOT NULL DEFAULT '',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Creator_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "CreatorClick" (
"creatorId" TEXT NOT NULL,
"day" TEXT NOT NULL,
"count" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "CreatorClick_pkey" PRIMARY KEY ("creatorId","day")
);
-- CreateTable
CREATE TABLE "Commission" (
"id" TEXT NOT NULL,
"creatorId" TEXT NOT NULL,
"orderId" TEXT NOT NULL,
"amount" INTEGER NOT NULL,
"base" INTEGER NOT NULL,
"rate" INTEGER NOT NULL,
"status" TEXT NOT NULL DEFAULT 'pending',
"releaseAt" TIMESTAMP(3),
"payoutId" TEXT,
"offsetPayoutId" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Commission_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "CreatorPayout" (
"id" TEXT NOT NULL,
"creatorId" TEXT NOT NULL,
"amount" INTEGER NOT NULL,
"method" TEXT NOT NULL DEFAULT 'transfer',
"note" TEXT NOT NULL DEFAULT '',
"author" TEXT NOT NULL DEFAULT '',
"paidAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "CreatorPayout_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Creator_userId_key" ON "Creator"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "Commission_orderId_key" ON "Commission"("orderId");
-- CreateIndex
CREATE INDEX "Commission_creatorId_status_idx" ON "Commission"("creatorId", "status");
-- CreateIndex
CREATE INDEX "Coupon_creatorId_idx" ON "Coupon"("creatorId");
-- AddForeignKey
ALTER TABLE "Order" ADD CONSTRAINT "Order_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "Creator"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Coupon" ADD CONSTRAINT "Coupon_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "Creator"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Creator" ADD CONSTRAINT "Creator_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Creator" ADD CONSTRAINT "Creator_tierId_fkey" FOREIGN KEY ("tierId") REFERENCES "CreatorTier"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "CreatorClick" ADD CONSTRAINT "CreatorClick_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "Creator"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Commission" ADD CONSTRAINT "Commission_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "Creator"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Commission" ADD CONSTRAINT "Commission_orderId_fkey" FOREIGN KEY ("orderId") REFERENCES "Order"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Commission" ADD CONSTRAINT "Commission_payoutId_fkey" FOREIGN KEY ("payoutId") REFERENCES "CreatorPayout"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "CreatorPayout" ADD CONSTRAINT "CreatorPayout_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "Creator"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- Startvorlage der Stufen (frei änderbar unter Creator › Stufen)
INSERT INTO "CreatorTier" ("id", "name", "sort", "discountType", "discountValue", "discountCap", "commissionRate", "minOrder", "upgradeFrom", "extras", "excludedProductIds", "excludedCategoryIds", "updatedAt") VALUES
('tier_starter', 'Starter', 0, 'percent', 5, 0, 700, 0, 0, 'Creator-Bereich mit Statistik', '{}', '{}', NOW()),
('tier_partner', 'Partner', 1, 'percent', 5, 0, 1000, 0, 300000, 'Produkte zum Vorzugspreis, eigene Landingpage', '{}', '{}', NOW()),
('tier_botschafter', 'Botschafterin', 2, 'percent', 5, 0, 1000, 0, 0, 'Wenige Ausgewählte per Vertrag: Werte je Creator individuell, Gratis-Produkte, Fixbetrag pro Video möglich', '{}', '{}', NOW());