Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(dataset-versioning): add version cols to dataset items model (#10817)

marliessophiefa904ae2bb9b
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.ts
index 36c8897037..e9c2c8ac34 100644
--- a/packages/shared/prisma/generated/types.ts
+++ b/packages/shared/prisma/generated/types.ts
@@ -420,7 +420,7 @@ export type Dataset = {
export type DatasetItem = {
id: string;
project_id: string;
- status: Generated<DatasetStatus>;
+ status: Generated<DatasetStatus | null>;
input: unknown | null;
expected_output: unknown | null;
metadata: unknown | null;
@@ -429,6 +429,9 @@ export type DatasetItem = {
dataset_id: string;
created_at: Generated<Timestamp>;
updated_at: Generated<Timestamp>;
+ sys_id: Generated<string | null>;
+ valid_from: Generated<Timestamp>;
+ is_deleted: Generated<boolean>;
};
export type DatasetItemEvent = {
id: string;
diff --git a/packages/shared/prisma/migrations/20251201095227_dataset_items_add_version_cols/migration.sql b/packages/shared/prisma/migrations/20251201095227_dataset_items_add_version_cols/migration.sql
new file mode 100644
index 0000000000..e6919077bd
--- /dev/null
+++ b/packages/shared/prisma/migrations/20251201095227_dataset_items_add_version_cols/migration.sql
@@ -0,0 +1,14 @@
+BEGIN;
+
+-- 1. Add columns
+ALTER TABLE "dataset_items"
+ ADD COLUMN "is_deleted" BOOLEAN NOT NULL DEFAULT false,
+ ADD COLUMN "sys_id" TEXT,
+ ADD COLUMN "valid_from" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ ALTER COLUMN "status" DROP NOT NULL;
+
+-- 2. Set default for NEW rows
+ALTER TABLE "dataset_items"
+ ALTER COLUMN "sys_id" SET DEFAULT md5(random()::text || clock_timestamp()::text)::uuid::text;
+
+COMMIT;
\ No newline at end of file
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index e27d3df53e..6b70360f48 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -617,7 +617,7 @@ model Dataset {
model DatasetItem {
id String @default(cuid())
projectId String @map("project_id")
- status DatasetStatus @default(ACTIVE)
+ status DatasetStatus? @default(ACTIVE)
input Json?
expectedOutput Json? @map("expected_output")
metadata Json?
@@ -627,6 +627,10 @@ model DatasetItem {
dataset Dataset @relation(fields: [datasetId, projectId], references: [id, projectId], onDelete: Cascade)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
+ // dataset version cols
+ sysId String? @default(dbgenerated()) @map("sys_id")
+ validFrom DateTime @default(now()) @map("valid_from")
+ isDeleted Boolean @default(false) @map("is_deleted")
datasetRunItems DatasetRunItems[]
@@id([id, projectId])
@@ -840,15 +844,15 @@ model Model {
projectId String? @map("project_id")
project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
- modelName String @map("model_name")
- matchPattern String @map("match_pattern")
- startDate DateTime? @map("start_date")
- inputPrice Decimal? @map("input_price")
- outputPrice Decimal? @map("output_price")
- totalPrice Decimal? @map("total_price")
+ modelName String @map("model_name")
+ matchPattern String @map("match_pattern")
+ startDate DateTime? @map("start_date")
+ inputPrice Decimal? @map("input_price")
+ outputPrice Decimal? @map("output_price")
+ totalPrice Decimal? @map("total_price")
unit String? // TOKENS, CHARACTERS, MILLISECONDS, SECONDS, REQUESTS, or IMAGES
- tokenizerId String? @map("tokenizer_id")
- tokenizerConfig Json? @map("tokenizer_config")
+ tokenizerId String? @map("tokenizer_id")
+ tokenizerConfig Json? @map("tokenizer_config")
Price Price[]
pricingTiers PricingTier[]
@@ -858,17 +862,17 @@ model Model {
}
model Price {
- id String @id @default(cuid())
- createdAt DateTime @default(now()) @map("created_at")
- updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
- modelId String @map("model_id") // Model is already linked to project (or default), so we don't need projectId here
- Model Model @relation(fields: [modelId], references: [id], onDelete: Cascade)
- projectId String? @map("project_id")
- project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
- pricingTierId String @map("pricing_tier_id")
+ id String @id @default(cuid())
+ createdAt DateTime @default(now()) @map("created_at")
+ updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
+ modelId String @map("model_id") // Model is already linked to project (or default), so we don't need projectId here
+ Model Model @relation(fields: [modelId], references: [id], onDelete: Cascade)
+ projectId String? @map("project_id")
+ project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ pricingTierId String @map("pricing_tier_id")
pricingTier PricingTier @relation(fields: [pricingTierId], references: [id], onDelete: Cascade)
- usageType String @map("usage_type")
- price Decimal
+ usageType String @map("usage_type")
+ price Decimal
@@unique([modelId, usageType, pricingTierId])
@@index(pricingTierId)
@@ -880,13 +884,13 @@ model PricingTier {
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
- modelId String @map("model_id")
- model Model @relation(fields: [modelId], references: [id], onDelete: Cascade)
+ modelId String @map("model_id")
+ model Model @relation(fields: [modelId], references: [id], onDelete: Cascade)
- name String @map("name")
- isDefault Boolean @default(false) @map("is_default")
- priority Int @map("priority")
- conditions Json @map("conditions") @db.JsonB
+ name String @map("name")
+ isDefault Boolean @default(false) @map("is_default")
+ priority Int @map("priority")
+ conditions Json @map("conditions") @db.JsonB
prices Price[]
diff --git a/worker/src/__tests__/evalService.test.ts b/worker/src/__tests__/evalService.test.ts
index 26e2a8c94b..2ca6acff15 100644
--- a/worker/src/__tests__/evalService.test.ts
+++ b/worker/src/__tests__/evalService.test.ts
@@ -667,6 +667,7 @@ Respond with JSON: {"score": <number>, "reasoning": "<explanation>"}`;
.insertInto("dataset_items")
.values({
id: datasetItemId,
+ sys_id: randomUUID(),
project_id: projectId,
dataset_id: datasetId,
source_trace_id: traceId,
@@ -743,6 +744,7 @@ Respond with JSON: {"score": <number>, "reasoning": "<explanation>"}`;
.insertInto("dataset_items")
.values({
id: datasetItemId,
+ sys_id: randomUUID(),
project_id: projectId,
dataset_id: datasetId,
source_trace_id: traceId,
@@ -820,6 +822,7 @@ Respond with JSON: {"score": <number>, "reasoning": "<explanation>"}`;
.insertInto("dataset_items")
.values({
id: datasetItemId,
+ sys_id: randomUUID(),
project_id: projectId,
dataset_id: datasetId,
})
@@ -980,6 +983,7 @@ Respond with JSON: {"score": <number>, "reasoning": "<explanation>"}`;
.insertInto("dataset_items")
.values({
id: datasetItemId,
+ sys_id: randomUUID(),
project_id: projectId,
dataset_id: datasetId,
source_trace_id: traceId,
@@ -1594,6 +1598,7 @@ Respond with JSON: {"score": <number>, "reasoning": "<explanation>"}`;
id: datasetItemId,
project_id: projectId,
dataset_id: datasetId2,
+ sys_id: randomUUID(),
source_trace_id: traceId,
})
.execute();
@@ -1749,6 +1754,7 @@ Respond with JSON: {"score": <number>, "reasoning": "<explanation>"}`;
.values({
id: datasetItemId,
project_id: projectId,
+ sys_id: randomUUID(),
dataset_id: datasetId1,
source_trace_id: traceId,
})
@@ -2441,6 +2447,7 @@ Respond with JSON: {"score": <number>, "reasoning": "<explanation>"}`;
expected_output: { expected_output: "This is a great response" },
project_id: projectId,
dataset_id: datasetId,
+ sys_id: randomUUID(),
})
.execute();
@@ -3114,6 +3121,7 @@ Respond with JSON: {"score": <number>, "reasoning": "<explanation>"}`;
.values({
id: datasetItemId,
project_id: projectId,
+ sys_id: randomUUID(),
dataset_id: datasetId,
})
.execute();