Skip to content

Commit

Permalink
feat: add rag schema (migration) (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
mantagen authored Nov 5, 2024
1 parent dbb81f9 commit 638f43f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Warnings:
- You are about to drop the column `data` on the `ingest_lesson_plan_part` table. All the data in the column will be lost.
- You are about to drop the column `valueText` on the `ingest_lesson_plan_part` table. All the data in the column will be lost.
- Added the required column `value_json` to the `ingest_lesson_plan_part` table without a default value. This is not possible if the table is not empty.
- Added the required column `value_text` to the `ingest_lesson_plan_part` table without a default value. This is not possible if the table is not empty.
*/
-- CreateSchema
CREATE SCHEMA IF NOT EXISTS "rag";

-- AlterTable -- updated this to be RENAME instead of DROP and ADD
ALTER TABLE "ingest"."ingest_lesson_plan_part"
RENAME COLUMN data TO value_json;

ALTER TABLE "ingest"."ingest_lesson_plan_part"
RENAME COLUMN "valueText" TO value_text;

-- CreateTable
CREATE TABLE "rag"."rag_lesson_plans" (
"id" TEXT NOT NULL,
"oak_lesson_id" INTEGER NOT NULL,
"ingest_lesson_id" TEXT,
"lesson_plan" JSONB NOT NULL,
"subject_slug" TEXT NOT NULL,
"key_stage_slug" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,

CONSTRAINT "rag_lesson_plans_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "rag"."rag_lesson_plan_parts" (
"id" TEXT NOT NULL,
"rag_lesson_plan_id" TEXT NOT NULL,
"key" TEXT NOT NULL,
"value_text" TEXT NOT NULL,
"value_json" JSONB NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"embedding" vector(256) NOT NULL,

CONSTRAINT "rag_lesson_plan_parts_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "rag"."rag_lesson_plan_parts" ADD CONSTRAINT "rag_lesson_plan_parts_rag_lesson_plan_id_fkey" FOREIGN KEY ("rag_lesson_plan_id") REFERENCES "rag"."rag_lesson_plans"("id") ON DELETE CASCADE ON UPDATE CASCADE;
39 changes: 35 additions & 4 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ datasource db {
url = env("PRISMA_ACCELERATE_DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
extensions = [vector, pg_trgm]
schemas = ["public", "ingest"]
schemas = ["public", "ingest", "rag"]
}

generator zod {
Expand Down Expand Up @@ -985,7 +985,7 @@ enum QuizAnswerStatus {

model Ingest {
id String @id @default(cuid())
config Json @default("{}") @map("config") @db.JsonB
config Json @map("config") @db.JsonB
status String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
Expand Down Expand Up @@ -1063,8 +1063,8 @@ model IngestLessonPlanPart {
ingestId String @map("ingest_id")
batchId String? @map("batch_id")
key String
valueJson Json @map("data") @db.JsonB
valueText String
valueJson Json @map("value_json") @db.JsonB
valueText String @map("value_text")
embedding Unsupported("vector(256)")?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
Expand Down Expand Up @@ -1110,3 +1110,34 @@ model IngestError {
@@map("ingest_error")
@@schema("ingest")
}

model RagLessonPlan {
id String @id @default(cuid())
oakLessonId Int @map("oak_lesson_id")
ingestLessonId String? @map("ingest_lesson_id")
lessonPlan Json @map("lesson_plan") @db.JsonB
subjectSlug String @map("subject_slug")
keyStageSlug String @map("key_stage_slug")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
ragLessonPlanPart RagLessonPlanPart[]
@@map("rag_lesson_plans")
@@schema("rag")
}

model RagLessonPlanPart {
id String @id @default(cuid())
ragLessonPlanId String @map("rag_lesson_plan_id")
key String
valueText String @map("value_text")
valueJson Json @map("value_json") @db.JsonB
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
ragLessonPlan RagLessonPlan @relation(fields: [ragLessonPlanId], references: [id], onDelete: Cascade)
embedding Unsupported("vector(256)")
@@map("rag_lesson_plan_parts")
@@schema("rag")
}

0 comments on commit 638f43f

Please sign in to comment.