From 52fe6492cd20b2d86eca6d2feab11e0e91ac7fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Lorne?= Date: Wed, 11 Oct 2023 11:42:39 +0100 Subject: [PATCH 1/5] feat(prisma): add project to prisma schema --- .../migration.sql | 22 +++++++++++++++++++ prisma/schema.prisma | 8 +++++++ 2 files changed, 30 insertions(+) create mode 100644 prisma/migrations/20231011104145_add_project_column/migration.sql diff --git a/prisma/migrations/20231011104145_add_project_column/migration.sql b/prisma/migrations/20231011104145_add_project_column/migration.sql new file mode 100644 index 00000000..47c7ddfb --- /dev/null +++ b/prisma/migrations/20231011104145_add_project_column/migration.sql @@ -0,0 +1,22 @@ +/* + Warnings: + + - Added the required column `projectId` to the `llmLogs` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "llmLogs" ADD COLUMN "projectId" TEXT NOT NULL; + +-- CreateTable +CREATE TABLE "Project" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + + CONSTRAINT "Project_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Project_name_key" ON "Project"("name"); + +-- AddForeignKey +ALTER TABLE "llmLogs" ADD CONSTRAINT "llmLogs_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f1efbfc0..d58fdbfc 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -25,6 +25,8 @@ model llmLogs { total_tokens Int cost Float? tags Tag[] + project Project @relation(fields: [projectId], references: [id]) + projectId String } model Tag { @@ -33,6 +35,12 @@ model Tag { logs llmLogs[] } +model Project { + id String @id @default(uuid()) + name String @unique + llmLogs llmLogs[] +} + model omnilogUser { id String @id @default(uuid()) email String @unique From a05f7014afbe4e53619b408928df4827e3d6cffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Lorne?= Date: Wed, 11 Oct 2023 11:47:34 +0100 Subject: [PATCH 2/5] feat(prisma): add default project to seed --- front/prisma/seed.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/front/prisma/seed.ts b/front/prisma/seed.ts index c4ede981..4116caf6 100644 --- a/front/prisma/seed.ts +++ b/front/prisma/seed.ts @@ -25,6 +25,11 @@ async function main() { password: hashed, }, }); + const project = await prisma.project.create({ + data: { + name: "Default Project", + }, + }); const tagSeeded = await prisma.tag.create({ data: { name: "Seeded", @@ -47,6 +52,11 @@ async function main() { id: tagSeeded.id, }, }, + project: { + connect: { + id: project.id, + }, + }, }, }); await prisma.llmLogs.create({ @@ -66,6 +76,11 @@ async function main() { }, ], }, + project: { + connect: { + id: project.id, + }, + }, }, }); } From 1e4c4ae2104144ceef8d359f0edec361e499ec2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Lorne?= Date: Wed, 11 Oct 2023 12:28:04 +0100 Subject: [PATCH 3/5] fix(prisma): add migration to store projectName in logs --- front/prisma/seed.ts | 4 ++-- .../migration.sql | 16 ++++++++++++++++ prisma/schema.prisma | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 prisma/migrations/20231011111357_modify_project_ref_in_logs/migration.sql diff --git a/front/prisma/seed.ts b/front/prisma/seed.ts index 4116caf6..855e7543 100644 --- a/front/prisma/seed.ts +++ b/front/prisma/seed.ts @@ -54,7 +54,7 @@ async function main() { }, project: { connect: { - id: project.id, + name: project.name, }, }, }, @@ -78,7 +78,7 @@ async function main() { }, project: { connect: { - id: project.id, + name: project.name, }, }, }, diff --git a/prisma/migrations/20231011111357_modify_project_ref_in_logs/migration.sql b/prisma/migrations/20231011111357_modify_project_ref_in_logs/migration.sql new file mode 100644 index 00000000..c0f99d88 --- /dev/null +++ b/prisma/migrations/20231011111357_modify_project_ref_in_logs/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - You are about to drop the column `projectId` on the `llmLogs` table. All the data in the column will be lost. + - Added the required column `projectName` to the `llmLogs` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropForeignKey +ALTER TABLE "llmLogs" DROP CONSTRAINT "llmLogs_projectId_fkey"; + +-- AlterTable +ALTER TABLE "llmLogs" DROP COLUMN "projectId", +ADD COLUMN "projectName" TEXT NOT NULL; + +-- AddForeignKey +ALTER TABLE "llmLogs" ADD CONSTRAINT "llmLogs_projectName_fkey" FOREIGN KEY ("projectName") REFERENCES "Project"("name") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index d58fdbfc..8597b6d7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -25,8 +25,8 @@ model llmLogs { total_tokens Int cost Float? tags Tag[] - project Project @relation(fields: [projectId], references: [id]) - projectId String + project Project @relation(fields: [projectName], references: [name]) + projectName String } model Tag { From 16d86e170dde696c0e5d8e510282f7223f7dbf04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Lorne?= Date: Wed, 11 Oct 2023 12:42:31 +0100 Subject: [PATCH 4/5] feat(front): add projectName to LogDetails --- front/src/features/tables/views/LogDetailsTable.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/front/src/features/tables/views/LogDetailsTable.tsx b/front/src/features/tables/views/LogDetailsTable.tsx index 77c15e64..d3a19f7f 100644 --- a/front/src/features/tables/views/LogDetailsTable.tsx +++ b/front/src/features/tables/views/LogDetailsTable.tsx @@ -60,6 +60,10 @@ export const LogDetailsTable = ({ logDetails }: { logDetails: LogData }) => { logId={logDetails.id} /> + + Project + {logDetails.projectName} + From f83caef1d8e9b17464bdd0f567da6692140ccfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Lorne?= Date: Wed, 11 Oct 2023 17:06:01 +0100 Subject: [PATCH 5/5] refactor(front): use projectId in llmLogs schema --- .../features/tables/views/LogDetailsTable.tsx | 2 +- front/src/services/prisma/LogsData.ts | 2 ++ front/src/types/logDisplayOptions.ts | 4 ++-- .../migration.sql | 16 ---------------- .../migration.sql | 0 prisma/schema.prisma | 4 ++-- 6 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 prisma/migrations/20231011111357_modify_project_ref_in_logs/migration.sql rename prisma/migrations/{20231011104145_add_project_column => 20231011160412_add_project_property}/migration.sql (100%) diff --git a/front/src/features/tables/views/LogDetailsTable.tsx b/front/src/features/tables/views/LogDetailsTable.tsx index d3a19f7f..7c6d6ecd 100644 --- a/front/src/features/tables/views/LogDetailsTable.tsx +++ b/front/src/features/tables/views/LogDetailsTable.tsx @@ -62,7 +62,7 @@ export const LogDetailsTable = ({ logDetails }: { logDetails: LogData }) => { Project - {logDetails.projectName} + {logDetails.project.name} diff --git a/front/src/services/prisma/LogsData.ts b/front/src/services/prisma/LogsData.ts index a4321658..3b07e25f 100644 --- a/front/src/services/prisma/LogsData.ts +++ b/front/src/services/prisma/LogsData.ts @@ -19,6 +19,7 @@ export const LogsData = { }, take: 5, }, + project: true, }, }); }, @@ -33,6 +34,7 @@ export const LogsData = { name: "asc", }, }, + project: true, }, }); diff --git a/front/src/types/logDisplayOptions.ts b/front/src/types/logDisplayOptions.ts index fed65b5e..2850d053 100644 --- a/front/src/types/logDisplayOptions.ts +++ b/front/src/types/logDisplayOptions.ts @@ -1,4 +1,4 @@ -import { Tag, llmLogs } from "@prisma/client"; +import { Project, Tag, llmLogs } from "@prisma/client"; export type LogDisplayOptions = { sortBy?: SortOptions; @@ -14,5 +14,5 @@ export type TimeOption = "last-hour" | "last-day" | "last-week"; export type Order = "asc" | "desc"; export type SortOptions = "datetime_utc" | "total_tokens" | "id" | "cost"; -export type LogData = llmLogs & { tags: Tag[] }; +export type LogData = llmLogs & { tags: Tag[] } & { project: Project }; export type LogDataArray = LogData[]; diff --git a/prisma/migrations/20231011111357_modify_project_ref_in_logs/migration.sql b/prisma/migrations/20231011111357_modify_project_ref_in_logs/migration.sql deleted file mode 100644 index c0f99d88..00000000 --- a/prisma/migrations/20231011111357_modify_project_ref_in_logs/migration.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `projectId` on the `llmLogs` table. All the data in the column will be lost. - - Added the required column `projectName` to the `llmLogs` table without a default value. This is not possible if the table is not empty. - -*/ --- DropForeignKey -ALTER TABLE "llmLogs" DROP CONSTRAINT "llmLogs_projectId_fkey"; - --- AlterTable -ALTER TABLE "llmLogs" DROP COLUMN "projectId", -ADD COLUMN "projectName" TEXT NOT NULL; - --- AddForeignKey -ALTER TABLE "llmLogs" ADD CONSTRAINT "llmLogs_projectName_fkey" FOREIGN KEY ("projectName") REFERENCES "Project"("name") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20231011104145_add_project_column/migration.sql b/prisma/migrations/20231011160412_add_project_property/migration.sql similarity index 100% rename from prisma/migrations/20231011104145_add_project_column/migration.sql rename to prisma/migrations/20231011160412_add_project_property/migration.sql diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8597b6d7..d58fdbfc 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -25,8 +25,8 @@ model llmLogs { total_tokens Int cost Float? tags Tag[] - project Project @relation(fields: [projectName], references: [name]) - projectName String + project Project @relation(fields: [projectId], references: [id]) + projectId String } model Tag {