Skip to content

Commit

Permalink
feat: migrate filesystem storage to sqlite db (promptfoo#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
typpo authored Mar 17, 2024
1 parent 5efb6fe commit d02e404
Show file tree
Hide file tree
Showing 36 changed files with 2,821 additions and 440 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ Here are some of the available scripts:
- `build:watch`: Continuously watch and transpile TypeScript files on changes
- `test`: Run test suite
- `test:watch`: Continuously run test suite on changes
- `db:generate`: Generate new db migrations (and create the db if it doesn't already exist)
- `db:migrate`: Run existing db migrations (and create the db if it doesn't already exist)

# [» View full documentation «](https://promptfoo.dev/docs/intro)

Expand Down
8 changes: 8 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'dotenv/config';
import type { Config } from 'drizzle-kit';

export default {
schema: './src/database.ts',
out: './drizzle',
driver: 'better-sqlite',
} satisfies Config;
36 changes: 36 additions & 0 deletions drizzle/0000_lush_hellion.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CREATE TABLE `datasets` (
`id` text PRIMARY KEY NOT NULL,
`test_case_id` text NOT NULL,
`created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL
);
--> statement-breakpoint
CREATE TABLE `evals` (
`id` text PRIMARY KEY NOT NULL,
`created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
`description` text,
`results` text NOT NULL,
`config` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `evals_to_datasets` (
`eval_id` text NOT NULL,
`dataset_id` text NOT NULL,
PRIMARY KEY(`dataset_id`, `eval_id`),
FOREIGN KEY (`eval_id`) REFERENCES `evals`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`dataset_id`) REFERENCES `datasets`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `evals_to_prompts` (
`eval_id` text NOT NULL,
`prompt_id` text NOT NULL,
PRIMARY KEY(`eval_id`, `prompt_id`),
FOREIGN KEY (`eval_id`) REFERENCES `evals`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`prompt_id`) REFERENCES `prompts`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `prompts` (
`id` text PRIMARY KEY NOT NULL,
`created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
`prompt` text NOT NULL,
`hash` text NOT NULL
);
244 changes: 244 additions & 0 deletions drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
{
"version": "5",
"dialect": "sqlite",
"id": "8b53403f-5b6f-436a-862e-9fd17a52204e",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"datasets": {
"name": "datasets",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"test_case_id": {
"name": "test_case_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"evals": {
"name": "evals",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"results": {
"name": "results",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"config": {
"name": "config",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"evals_to_datasets": {
"name": "evals_to_datasets",
"columns": {
"eval_id": {
"name": "eval_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"dataset_id": {
"name": "dataset_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"evals_to_datasets_eval_id_evals_id_fk": {
"name": "evals_to_datasets_eval_id_evals_id_fk",
"tableFrom": "evals_to_datasets",
"tableTo": "evals",
"columnsFrom": [
"eval_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"evals_to_datasets_dataset_id_datasets_id_fk": {
"name": "evals_to_datasets_dataset_id_datasets_id_fk",
"tableFrom": "evals_to_datasets",
"tableTo": "datasets",
"columnsFrom": [
"dataset_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"evals_to_datasets_eval_id_dataset_id_pk": {
"columns": [
"dataset_id",
"eval_id"
],
"name": "evals_to_datasets_eval_id_dataset_id_pk"
}
},
"uniqueConstraints": {}
},
"evals_to_prompts": {
"name": "evals_to_prompts",
"columns": {
"eval_id": {
"name": "eval_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"prompt_id": {
"name": "prompt_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"evals_to_prompts_eval_id_evals_id_fk": {
"name": "evals_to_prompts_eval_id_evals_id_fk",
"tableFrom": "evals_to_prompts",
"tableTo": "evals",
"columnsFrom": [
"eval_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"evals_to_prompts_prompt_id_prompts_id_fk": {
"name": "evals_to_prompts_prompt_id_prompts_id_fk",
"tableFrom": "evals_to_prompts",
"tableTo": "prompts",
"columnsFrom": [
"prompt_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"evals_to_prompts_eval_id_prompt_id_pk": {
"columns": [
"eval_id",
"prompt_id"
],
"name": "evals_to_prompts_eval_id_prompt_id_pk"
}
},
"uniqueConstraints": {}
},
"prompts": {
"name": "prompts",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"prompt": {
"name": "prompt",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"hash": {
"name": "hash",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
13 changes: 13 additions & 0 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1710348564252,
"tag": "0000_lush_hellion",
"breakpoints": true
}
]
}
Loading

0 comments on commit d02e404

Please sign in to comment.