Pending course, rest ready for launch

This commit is contained in:
Marcelo
2026-03-15 13:52:11 +00:00
parent be4ca2ed78
commit 62b3cfe467
77 changed files with 6450 additions and 868 deletions

View File

@@ -0,0 +1,100 @@
/*
Warnings:
- A unique constraint covering the columns `[certificateNumber]` on the table `Certificate` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[userId,courseId]` on the table `Certificate` will be added. If there are existing duplicate values, this will fail.
- Added the required column `certificateNumber` to the `Certificate` table without a default value. This is not possible if the table is not empty.
*/
-- CreateEnum
CREATE TYPE "MiniGameDifficulty" AS ENUM ('BEGINNER', 'INTERMEDIATE', 'ADVANCED');
-- AlterTable
ALTER TABLE "Certificate" ADD COLUMN "certificateNumber" TEXT NOT NULL,
ADD COLUMN "pdfVersion" INTEGER NOT NULL DEFAULT 1;
-- CreateTable
CREATE TABLE "MiniGame" (
"id" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT NOT NULL,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"difficulty" "MiniGameDifficulty" NOT NULL DEFAULT 'INTERMEDIATE',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "MiniGame_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "MiniGameQuestion" (
"id" TEXT NOT NULL,
"miniGameId" TEXT NOT NULL,
"prompt" TEXT NOT NULL,
"choices" TEXT[],
"answerIndex" INTEGER NOT NULL,
"orderIndex" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "MiniGameQuestion_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "MiniGameAttempt" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"miniGameId" TEXT NOT NULL,
"scorePercent" INTEGER NOT NULL,
"correctCount" INTEGER NOT NULL,
"totalQuestions" INTEGER NOT NULL,
"startedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"completedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "MiniGameAttempt_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "StudyRecommendation" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"courseId" TEXT NOT NULL,
"reason" TEXT NOT NULL,
"priority" INTEGER NOT NULL DEFAULT 0,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "StudyRecommendation_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "MiniGame_slug_key" ON "MiniGame"("slug");
-- CreateIndex
CREATE INDEX "MiniGameQuestion_miniGameId_orderIndex_idx" ON "MiniGameQuestion"("miniGameId", "orderIndex");
-- CreateIndex
CREATE INDEX "MiniGameAttempt_userId_miniGameId_completedAt_idx" ON "MiniGameAttempt"("userId", "miniGameId", "completedAt");
-- CreateIndex
CREATE INDEX "StudyRecommendation_userId_isActive_priority_idx" ON "StudyRecommendation"("userId", "isActive", "priority");
-- CreateIndex
CREATE UNIQUE INDEX "Certificate_certificateNumber_key" ON "Certificate"("certificateNumber");
-- CreateIndex
CREATE UNIQUE INDEX "Certificate_userId_courseId_key" ON "Certificate"("userId", "courseId");
-- AddForeignKey
ALTER TABLE "MiniGameQuestion" ADD CONSTRAINT "MiniGameQuestion_miniGameId_fkey" FOREIGN KEY ("miniGameId") REFERENCES "MiniGame"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "MiniGameAttempt" ADD CONSTRAINT "MiniGameAttempt_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "MiniGameAttempt" ADD CONSTRAINT "MiniGameAttempt_miniGameId_fkey" FOREIGN KEY ("miniGameId") REFERENCES "MiniGame"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "StudyRecommendation" ADD CONSTRAINT "StudyRecommendation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "StudyRecommendation" ADD CONSTRAINT "StudyRecommendation_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,225 @@
-- CreateSchema
CREATE SCHEMA IF NOT EXISTS "public";
-- CreateEnum
CREATE TYPE "public"."ContentStatus" AS ENUM ('DRAFT', 'PUBLISHED', 'ARCHIVED');
-- CreateEnum
CREATE TYPE "public"."ExerciseType" AS ENUM ('MULTIPLE_CHOICE', 'FILL_IN_BLANK', 'TRANSLATION', 'MATCHING');
-- CreateEnum
CREATE TYPE "public"."ProficiencyLevel" AS ENUM ('BEGINNER', 'INTERMEDIATE', 'ADVANCED', 'EXPERT');
-- CreateEnum
CREATE TYPE "public"."UserRole" AS ENUM ('SUPER_ADMIN', 'ORG_ADMIN', 'TEACHER', 'LEARNER');
-- CreateTable
CREATE TABLE "public"."Certificate" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"courseId" TEXT NOT NULL,
"companyId" TEXT,
"issuedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"metadataSnapshot" JSONB NOT NULL,
CONSTRAINT "Certificate_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Company" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"logoUrl" TEXT,
"billingEmail" TEXT,
"maxSeats" INTEGER NOT NULL DEFAULT 5,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Company_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Course" (
"id" TEXT NOT NULL,
"title" JSONB NOT NULL,
"slug" TEXT NOT NULL,
"description" JSONB NOT NULL,
"level" "public"."ProficiencyLevel" NOT NULL DEFAULT 'INTERMEDIATE',
"tags" TEXT[],
"status" "public"."ContentStatus" NOT NULL DEFAULT 'DRAFT',
"price" DECIMAL(65,30) NOT NULL DEFAULT 0.00,
"authorId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"prerequisiteId" TEXT,
CONSTRAINT "Course_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Enrollment" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"courseId" TEXT NOT NULL,
"amountPaid" DECIMAL(65,30) NOT NULL,
"currency" TEXT NOT NULL DEFAULT 'MXN',
"paymentMethod" TEXT NOT NULL DEFAULT 'MERCADO_PAGO',
"externalId" TEXT,
"purchasedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Enrollment_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Exercise" (
"id" TEXT NOT NULL,
"lessonId" TEXT NOT NULL,
"type" "public"."ExerciseType" NOT NULL,
"content" JSONB NOT NULL,
"orderIndex" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "Exercise_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Lesson" (
"id" TEXT NOT NULL,
"moduleId" TEXT NOT NULL,
"title" JSONB NOT NULL,
"slug" TEXT,
"orderIndex" INTEGER NOT NULL,
"estimatedDuration" INTEGER NOT NULL,
"version" INTEGER NOT NULL DEFAULT 1,
"isFreePreview" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"videoUrl" TEXT,
"description" JSONB,
"youtubeUrl" TEXT,
CONSTRAINT "Lesson_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Membership" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"companyId" TEXT NOT NULL,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"role" TEXT NOT NULL DEFAULT 'MEMBER',
"joinedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Membership_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Module" (
"id" TEXT NOT NULL,
"courseId" TEXT NOT NULL,
"title" JSONB NOT NULL,
"orderIndex" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Module_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Profile" (
"id" TEXT NOT NULL,
"email" TEXT NOT NULL,
"fullName" TEXT,
"avatarUrl" TEXT,
"role" "public"."UserRole" NOT NULL DEFAULT 'LEARNER',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Profile_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."Resource" (
"id" TEXT NOT NULL,
"lessonId" TEXT NOT NULL,
"fileUrl" TEXT NOT NULL,
"displayName" JSONB NOT NULL,
"fileType" TEXT NOT NULL,
CONSTRAINT "Resource_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."UserProgress" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"lessonId" TEXT NOT NULL,
"isCompleted" BOOLEAN NOT NULL DEFAULT false,
"score" INTEGER,
"startedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"finishedAt" TIMESTAMP(3),
"lastPlayedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "UserProgress_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Course_slug_key" ON "public"."Course"("slug" ASC);
-- CreateIndex
CREATE UNIQUE INDEX "Enrollment_userId_courseId_key" ON "public"."Enrollment"("userId" ASC, "courseId" ASC);
-- CreateIndex
CREATE UNIQUE INDEX "Membership_userId_companyId_key" ON "public"."Membership"("userId" ASC, "companyId" ASC);
-- CreateIndex
CREATE UNIQUE INDEX "Profile_email_key" ON "public"."Profile"("email" ASC);
-- CreateIndex
CREATE UNIQUE INDEX "UserProgress_userId_lessonId_key" ON "public"."UserProgress"("userId" ASC, "lessonId" ASC);
-- AddForeignKey
ALTER TABLE "public"."Certificate" ADD CONSTRAINT "Certificate_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "public"."Company"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Certificate" ADD CONSTRAINT "Certificate_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "public"."Course"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Certificate" ADD CONSTRAINT "Certificate_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."Profile"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Course" ADD CONSTRAINT "Course_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "public"."Profile"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Course" ADD CONSTRAINT "Course_prerequisiteId_fkey" FOREIGN KEY ("prerequisiteId") REFERENCES "public"."Course"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Enrollment" ADD CONSTRAINT "Enrollment_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "public"."Course"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Enrollment" ADD CONSTRAINT "Enrollment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Exercise" ADD CONSTRAINT "Exercise_lessonId_fkey" FOREIGN KEY ("lessonId") REFERENCES "public"."Lesson"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Lesson" ADD CONSTRAINT "Lesson_moduleId_fkey" FOREIGN KEY ("moduleId") REFERENCES "public"."Module"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Membership" ADD CONSTRAINT "Membership_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "public"."Company"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Membership" ADD CONSTRAINT "Membership_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Module" ADD CONSTRAINT "Module_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "public"."Course"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."Resource" ADD CONSTRAINT "Resource_lessonId_fkey" FOREIGN KEY ("lessonId") REFERENCES "public"."Lesson"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."UserProgress" ADD CONSTRAINT "UserProgress_lessonId_fkey" FOREIGN KEY ("lessonId") REFERENCES "public"."Lesson"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "public"."UserProgress" ADD CONSTRAINT "UserProgress_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"

View File

@@ -37,6 +37,12 @@ enum ExerciseType {
MATCHING
}
enum MiniGameDifficulty {
BEGINNER
INTERMEDIATE
ADVANCED
}
// --- MODELS ---
model Profile {
@@ -55,6 +61,8 @@ model Profile {
progress UserProgress[]
certificates Certificate[]
authoredCourses Course[] @relation("CourseAuthor") // Teachers own courses
miniGameAttempts MiniGameAttempt[]
recommendations StudyRecommendation[]
}
model Company {
@@ -94,7 +102,8 @@ model Course {
description Json // { "en": "...", "es": "..." }
level ProficiencyLevel @default(INTERMEDIATE)
tags String[]
learningOutcomes Json? // "What you will learn"; array of strings now, i18n object later
status ContentStatus @default(DRAFT)
price Decimal @default(0.00) // Price in MXN
@@ -111,6 +120,7 @@ model Course {
modules Module[]
certificates Certificate[]
enrollments Enrollment[]
recommendations StudyRecommendation[]
}
model Enrollment {
@@ -152,6 +162,7 @@ model Lesson {
slug String? // Optional for direct linking
orderIndex Int
videoUrl String?
youtubeUrl String?
estimatedDuration Int // Seconds
version Int @default(1)
isFreePreview Boolean @default(false) // Marketing hook
@@ -206,10 +217,72 @@ model Certificate {
userId String
courseId String
companyId String? // Captured for co-branding (Nullable for B2C)
certificateNumber String @unique
pdfVersion Int @default(1)
issuedAt DateTime @default(now())
metadataSnapshot Json // Burn the course name/version here
user Profile @relation(fields: [userId], references: [id])
course Course @relation(fields: [courseId], references: [id])
company Company? @relation(fields: [companyId], references: [id])
}
@@unique([userId, courseId])
}
model MiniGame {
id String @id @default(uuid())
slug String @unique
title String
description String
isActive Boolean @default(true)
difficulty MiniGameDifficulty @default(INTERMEDIATE)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
questions MiniGameQuestion[]
attempts MiniGameAttempt[]
}
model MiniGameQuestion {
id String @id @default(uuid())
miniGameId String
prompt String
choices String[]
answerIndex Int
orderIndex Int @default(0)
miniGame MiniGame @relation(fields: [miniGameId], references: [id], onDelete: Cascade)
@@index([miniGameId, orderIndex])
}
model MiniGameAttempt {
id String @id @default(uuid())
userId String
miniGameId String
scorePercent Int
correctCount Int
totalQuestions Int
startedAt DateTime @default(now())
completedAt DateTime @default(now())
user Profile @relation(fields: [userId], references: [id], onDelete: Cascade)
miniGame MiniGame @relation(fields: [miniGameId], references: [id], onDelete: Cascade)
@@index([userId, miniGameId, completedAt])
}
model StudyRecommendation {
id String @id @default(uuid())
userId String
courseId String
reason String
priority Int @default(0)
isActive Boolean @default(true)
createdAt DateTime @default(now())
user Profile @relation(fields: [userId], references: [id], onDelete: Cascade)
course Course @relation(fields: [courseId], references: [id], onDelete: Cascade)
@@index([userId, isActive, priority])
}

View File

@@ -93,6 +93,126 @@ async function main() {
},
})
console.log(`📚 Created Course: ${course.slug}`)
const miniGames = [
{
slug: "translation",
title: "Legal Translation Challenge",
description: "Translate legal terms accurately in context.",
difficulty: "BEGINNER",
questions: [
{
prompt: "Spanish term: incumplimiento contractual",
choices: ["Contractual compliance", "Breach of contract", "Contract interpretation", "Mutual assent"],
answerIndex: 1,
},
{
prompt: "Spanish term: medida cautelar",
choices: ["Class action", "Summary judgment", "Injunctive relief", "Arbitration clause"],
answerIndex: 2,
},
],
},
{
slug: "term-matching",
title: "Term Matching Game",
description: "Match legal terms with accurate definitions.",
difficulty: "INTERMEDIATE",
questions: [
{
prompt: "Match: consideration",
choices: [
"A legally binding command from the court",
"A bargained-for exchange of value between parties",
"A prior case that has no legal effect",
"A statement made outside of court",
],
answerIndex: 1,
},
{
prompt: "Match: injunction",
choices: [
"A court order requiring a party to do or stop doing something",
"A clause that sets venue for disputes",
"A witness statement under oath",
"A mandatory arbitration waiver",
],
answerIndex: 0,
},
],
},
{
slug: "contract-clauses",
title: "Contract Clause Practice",
description: "Pick the best clause drafting option for each scenario.",
difficulty: "ADVANCED",
questions: [
{
prompt: "Choose the strongest force majeure clause element:",
choices: [
"No definition of triggering events",
"Broad reference without notice obligations",
"Defined events, notice timeline, and mitigation duty",
"Automatic termination without limits",
],
answerIndex: 2,
},
{
prompt: "Best limitation of liability drafting choice:",
choices: [
"Exclude all damages including willful misconduct",
"Cap liability with carve-outs for fraud and gross negligence",
"No cap and no exclusions",
"Cap liability only for one party",
],
answerIndex: 1,
},
],
},
]
const prismaAny = prisma as unknown as {
miniGame: {
upsert: (args: object) => Promise<{ id: string }>
}
miniGameQuestion: {
deleteMany: (args: object) => Promise<unknown>
createMany: (args: object) => Promise<unknown>
}
}
for (const game of miniGames) {
const saved = await prismaAny.miniGame.upsert({
where: { slug: game.slug },
update: {
title: game.title,
description: game.description,
difficulty: game.difficulty,
isActive: true,
},
create: {
slug: game.slug,
title: game.title,
description: game.description,
difficulty: game.difficulty,
isActive: true,
},
})
await prismaAny.miniGameQuestion.deleteMany({
where: { miniGameId: saved.id },
})
await prismaAny.miniGameQuestion.createMany({
data: game.questions.map((q, index) => ({
miniGameId: saved.id,
prompt: q.prompt,
choices: q.choices,
answerIndex: q.answerIndex,
orderIndex: index,
})),
})
}
console.log(`🧩 Seeded ${miniGames.length} mini-games`)
console.log('✅ Seed complete!')
@@ -104,4 +224,4 @@ async function main() {
}
}
main()
main()