Fix production TypeScript builds and add DEPLOY.md so the app can be hosted from this repo. Co-authored-by: Cursor <cursoragent@cursor.com>
164 lines
6.9 KiB
SQL
164 lines
6.9 KiB
SQL
-- CreateTable
|
|
CREATE TABLE `learning_journeys` (
|
|
`userId` BIGINT UNSIGNED NOT NULL,
|
|
`currentStep` VARCHAR(32) NOT NULL DEFAULT 'registered',
|
|
`preTestCompletedAt` DATETIME(3) NULL,
|
|
`trainingStartedAt` DATETIME(3) NULL,
|
|
`trainingCompletedAt` DATETIME(3) NULL,
|
|
`postTestCompletedAt` DATETIME(3) NULL,
|
|
`lastActivityAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`updatedAt` DATETIME(3) NOT NULL,
|
|
|
|
PRIMARY KEY (`userId`)
|
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
-- CreateTable
|
|
CREATE TABLE `course_sessions` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`sessionKey` VARCHAR(64) NOT NULL,
|
|
`order` INTEGER NOT NULL,
|
|
`title` VARCHAR(191) NOT NULL,
|
|
`description` TEXT NOT NULL,
|
|
`estimatedDurationMinutes` INTEGER NOT NULL,
|
|
`blocks` JSON NOT NULL,
|
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`updatedAt` DATETIME(3) NOT NULL,
|
|
|
|
UNIQUE INDEX `course_sessions_sessionKey_key`(`sessionKey`),
|
|
UNIQUE INDEX `course_sessions_order_key`(`order`),
|
|
INDEX `idx_course_sessions_order`(`order`),
|
|
PRIMARY KEY (`id`)
|
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
-- CreateTable
|
|
CREATE TABLE `session_progress` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`userId` BIGINT UNSIGNED NOT NULL,
|
|
`sessionOrder` INTEGER NOT NULL,
|
|
`status` ENUM('not_started', 'in_progress', 'completed') NOT NULL DEFAULT 'not_started',
|
|
`startedAt` DATETIME(3) NULL,
|
|
`completedAt` DATETIME(3) NULL,
|
|
`completionMetadata` JSON NULL,
|
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`updatedAt` DATETIME(3) NOT NULL,
|
|
|
|
INDEX `idx_session_progress_user_status`(`userId`, `status`),
|
|
UNIQUE INDEX `uq_session_progress_user_order`(`userId`, `sessionOrder`),
|
|
PRIMARY KEY (`id`)
|
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
-- CreateTable
|
|
CREATE TABLE `assessment_attempts` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`userId` BIGINT UNSIGNED NOT NULL,
|
|
`phase` ENUM('pre', 'post') NOT NULL,
|
|
`status` ENUM('submitted', 'scored') NOT NULL DEFAULT 'scored',
|
|
`submittedAt` DATETIME(3) NOT NULL,
|
|
`scoredAt` DATETIME(3) NOT NULL,
|
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`updatedAt` DATETIME(3) NOT NULL,
|
|
|
|
INDEX `idx_assessment_attempts_user_phase_submitted`(`userId`, `phase`, `submittedAt`),
|
|
PRIMARY KEY (`id`)
|
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
-- CreateTable
|
|
CREATE TABLE `assessment_answers` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`attemptId` BIGINT UNSIGNED NOT NULL,
|
|
`questionId` VARCHAR(32) NOT NULL,
|
|
`rawValue` INTEGER NOT NULL,
|
|
`points` INTEGER NOT NULL,
|
|
`dimension` VARCHAR(32) NOT NULL,
|
|
`isReverseScored` BOOLEAN NOT NULL,
|
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
|
|
UNIQUE INDEX `uq_assessment_answers_attempt_question`(`attemptId`, `questionId`),
|
|
PRIMARY KEY (`id`)
|
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
-- CreateTable
|
|
CREATE TABLE `assessment_scores` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`attemptId` BIGINT UNSIGNED NOT NULL,
|
|
`metricKey` VARCHAR(32) NOT NULL,
|
|
`rawScore` INTEGER NOT NULL,
|
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
|
|
UNIQUE INDEX `uq_assessment_scores_attempt_metric`(`attemptId`, `metricKey`),
|
|
PRIMARY KEY (`id`)
|
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
-- CreateTable
|
|
CREATE TABLE `chat_sessions` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`userId` BIGINT UNSIGNED NOT NULL,
|
|
`sessionOrder` INTEGER NOT NULL,
|
|
`startedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`endedAt` DATETIME(3) NULL,
|
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`updatedAt` DATETIME(3) NOT NULL,
|
|
|
|
INDEX `idx_chat_sessions_user_order_started`(`userId`, `sessionOrder`, `startedAt`),
|
|
PRIMARY KEY (`id`)
|
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
-- CreateTable
|
|
CREATE TABLE `chat_messages` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`chatSessionId` BIGINT UNSIGNED NOT NULL,
|
|
`role` ENUM('system', 'user', 'assistant') NOT NULL,
|
|
`content` TEXT NOT NULL,
|
|
`metadata` JSON NULL,
|
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
|
|
INDEX `idx_chat_messages_session_created`(`chatSessionId`, `createdAt`),
|
|
PRIMARY KEY (`id`)
|
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
-- CreateTable
|
|
CREATE TABLE `ai_analysis_runs` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`userId` BIGINT UNSIGNED NOT NULL,
|
|
`chatSessionId` BIGINT UNSIGNED NULL,
|
|
`provider` VARCHAR(64) NOT NULL,
|
|
`model` VARCHAR(128) NOT NULL,
|
|
`status` ENUM('queued', 'running', 'succeeded', 'failed') NOT NULL DEFAULT 'queued',
|
|
`latencyMs` INTEGER NULL,
|
|
`totalTokens` INTEGER NULL,
|
|
`errorMessage` TEXT NULL,
|
|
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`updatedAt` DATETIME(3) NOT NULL,
|
|
|
|
INDEX `idx_ai_analysis_runs_user_created`(`userId`, `createdAt`),
|
|
PRIMARY KEY (`id`)
|
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE `learning_journeys` ADD CONSTRAINT `learning_journeys_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE `session_progress` ADD CONSTRAINT `session_progress_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE `assessment_attempts` ADD CONSTRAINT `assessment_attempts_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE `assessment_answers` ADD CONSTRAINT `assessment_answers_attemptId_fkey` FOREIGN KEY (`attemptId`) REFERENCES `assessment_attempts`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE `assessment_scores` ADD CONSTRAINT `assessment_scores_attemptId_fkey` FOREIGN KEY (`attemptId`) REFERENCES `assessment_attempts`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE `chat_sessions` ADD CONSTRAINT `chat_sessions_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE `chat_messages` ADD CONSTRAINT `chat_messages_chatSessionId_fkey` FOREIGN KEY (`chatSessionId`) REFERENCES `chat_sessions`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE `ai_analysis_runs` ADD CONSTRAINT `ai_analysis_runs_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE `ai_analysis_runs` ADD CONSTRAINT `ai_analysis_runs_chatSessionId_fkey` FOREIGN KEY (`chatSessionId`) REFERENCES `chat_sessions`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|