-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(EditSurveyName): prevent infinite API calls and add seed configur…
…ation
- Loading branch information
Showing
30 changed files
with
830 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
-- CreateTable | ||
CREATE TABLE "Survey" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"userId" TEXT NOT NULL, | ||
"updatedAt" TIMESTAMP(3), | ||
"status" TEXT NOT NULL DEFAULT 'draft', | ||
"responseCount" INTEGER NOT NULL DEFAULT 0, | ||
|
||
CONSTRAINT "Survey_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Question" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"min" TEXT NOT NULL, | ||
"steps" INTEGER NOT NULL, | ||
"max" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
"responseCount" INTEGER NOT NULL DEFAULT 0, | ||
"averageValue" DOUBLE PRECISION NOT NULL DEFAULT 0, | ||
"surveyId" TEXT NOT NULL, | ||
"scaleType" TEXT NOT NULL DEFAULT 'numeric', | ||
"scaleOptions" TEXT[] DEFAULT ARRAY[]::TEXT[], | ||
|
||
CONSTRAINT "Question_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Answer" ( | ||
"id" TEXT NOT NULL, | ||
"questionId" TEXT NOT NULL, | ||
"surveyId" TEXT, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"value" INTEGER NOT NULL, | ||
"updatedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "Answer_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT, | ||
"email" TEXT, | ||
"emailVerified" TIMESTAMP(3), | ||
"image" TEXT, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"lastLogin" TIMESTAMP(3), | ||
"role" TEXT NOT NULL DEFAULT 'RESEARCHER', | ||
"updatedAt" TIMESTAMP(3), | ||
"planId" TEXT, | ||
"planActiveUntil" TIMESTAMP(3), | ||
|
||
CONSTRAINT "User_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, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "Session_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, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "Account_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "VerificationToken" ( | ||
"identifier" TEXT NOT NULL, | ||
"token" TEXT NOT NULL, | ||
"expires" TIMESTAMP(3) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Plan" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"price" DOUBLE PRECISION NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"features" TEXT[], | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "Plan_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Survey" ADD CONSTRAINT "Survey_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Question" ADD CONSTRAINT "Question_surveyId_fkey" FOREIGN KEY ("surveyId") REFERENCES "Survey"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Answer" ADD CONSTRAINT "Answer_questionId_fkey" FOREIGN KEY ("questionId") REFERENCES "Question"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Answer" ADD CONSTRAINT "Answer_surveyId_fkey" FOREIGN KEY ("surveyId") REFERENCES "Survey"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "User" ADD CONSTRAINT "User_planId_fkey" FOREIGN KEY ("planId") REFERENCES "Plan"("id") ON DELETE SET NULL 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 "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
15 changes: 15 additions & 0 deletions
15
prisma/migrations/20241212173834_add_question_position/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- AlterTable | ||
ALTER TABLE "Question" ADD COLUMN IF NOT EXISTS "position" INTEGER NOT NULL DEFAULT 0; | ||
|
||
-- Add index on surveyId | ||
CREATE INDEX IF NOT EXISTS "Question_surveyId_idx" ON "Question"("surveyId"); | ||
|
||
-- UpdateData: Set position based on creation date within each survey | ||
WITH numbered_questions AS ( | ||
SELECT id, ROW_NUMBER() OVER (PARTITION BY "surveyId" ORDER BY "createdAt") - 1 as new_position | ||
FROM "Question" | ||
) | ||
UPDATE "Question" q | ||
SET position = nq.new_position | ||
FROM numbered_questions nq | ||
WHERE q.id = nq.id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ import { PrismaClient } from '@prisma/client'; | |
const prisma = new PrismaClient(); | ||
|
||
async function main() { | ||
// Lösche existierende Pläne | ||
// Lösche existierende Daten in der richtigen Reihenfolge | ||
await prisma.survey.deleteMany(); | ||
await prisma.user.deleteMany(); | ||
await prisma.plan.deleteMany(); | ||
|
||
// Erstelle Standard-Pläne | ||
|
@@ -48,10 +50,35 @@ async function main() { | |
}, | ||
]; | ||
|
||
// Erstelle Pläne und speichere die IDs | ||
const createdPlans: Record<string, string> = {}; | ||
for (const plan of plans) { | ||
await prisma.plan.create({ | ||
const createdPlan = await prisma.plan.create({ | ||
data: plan, | ||
}); | ||
createdPlans[createdPlan.name] = createdPlan.id; | ||
} | ||
|
||
// Erstelle Pro-User | ||
const proUsers = [ | ||
{ | ||
email: '[email protected]', | ||
name: 'Georgi Semov', | ||
}, | ||
{ | ||
email: '[email protected]', | ||
name: 'Thomas Bartoschek', | ||
}, | ||
]; | ||
|
||
for (const user of proUsers) { | ||
await prisma.user.create({ | ||
data: { | ||
...user, | ||
planId: createdPlans['Professional'], | ||
planActiveUntil: new Date('2025-12-31'), // Plan gültig bis Ende 2025 | ||
}, | ||
}); | ||
} | ||
|
||
console.log('Seed erfolgreich ausgeführt'); | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.