Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rag schema (migration) #343

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
Loading