initializing database models, migrations and ORM with Prisma

This commit is contained in:
Eng. Elias
2024-02-19 13:53:04 +04:00
parent 4d011ff080
commit e6f08d85fc
6 changed files with 212 additions and 7 deletions

1
.gitignore vendored
View File

@@ -27,6 +27,7 @@ yarn-error.log*
# local env files
.env*.local
.env
# vercel
.vercel

91
package-lock.json generated
View File

@@ -8,6 +8,7 @@
"name": "crew-ai-visualizer",
"version": "0.1.0",
"dependencies": {
"@prisma/client": "^5.9.1",
"next": "14.1.0",
"react": "^18",
"react-dom": "^18",
@@ -17,7 +18,7 @@
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "^4.1.0",
"@iconify/react": "^4.1.1",
"@types/node": "^20",
"@types/node": "^20.11.19",
"@types/react": "^18",
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^6.7.3",
@@ -26,8 +27,10 @@
"eslint": "^8",
"eslint-config-next": "14.1.0",
"postcss": "^8",
"prisma": "^5.9.1",
"tailwindcss": "^3.3.0",
"typescript": "^5"
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
},
"node_modules/@aashutoshrathi/word-wrap": {
@@ -996,6 +999,68 @@
"url": "https://opencollective.com/popperjs"
}
},
"node_modules/@prisma/client": {
"version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.9.1.tgz",
"integrity": "sha512-caSOnG4kxcSkhqC/2ShV7rEoWwd3XrftokxJqOCMVvia4NYV/TPtJlS9C2os3Igxw/Qyxumj9GBQzcStzECvtQ==",
"hasInstallScript": true,
"engines": {
"node": ">=16.13"
},
"peerDependencies": {
"prisma": "*"
},
"peerDependenciesMeta": {
"prisma": {
"optional": true
}
}
},
"node_modules/@prisma/debug": {
"version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.9.1.tgz",
"integrity": "sha512-yAHFSFCg8KVoL0oRUno3m60GAjsUKYUDkQ+9BA2X2JfVR3kRVSJFc/GpQ2fSORi4pSHZR9orfM4UC9OVXIFFTA==",
"devOptional": true
},
"node_modules/@prisma/engines": {
"version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.9.1.tgz",
"integrity": "sha512-gkdXmjxQ5jktxWNdDA5aZZ6R8rH74JkoKq6LD5mACSvxd2vbqWeWIOV0Py5wFC8vofOYShbt6XUeCIUmrOzOnQ==",
"devOptional": true,
"hasInstallScript": true,
"dependencies": {
"@prisma/debug": "5.9.1",
"@prisma/engines-version": "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64",
"@prisma/fetch-engine": "5.9.1",
"@prisma/get-platform": "5.9.1"
}
},
"node_modules/@prisma/engines-version": {
"version": "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64",
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64.tgz",
"integrity": "sha512-HFl7275yF0FWbdcNvcSRbbu9JCBSLMcurYwvWc8WGDnpu7APxQo2ONtZrUggU3WxLxUJ2uBX+0GOFIcJeVeOOQ==",
"devOptional": true
},
"node_modules/@prisma/fetch-engine": {
"version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.9.1.tgz",
"integrity": "sha512-l0goQOMcNVOJs1kAcwqpKq3ylvkD9F04Ioe1oJoCqmz05mw22bNAKKGWuDd3zTUoUZr97va0c/UfLNru+PDmNA==",
"devOptional": true,
"dependencies": {
"@prisma/debug": "5.9.1",
"@prisma/engines-version": "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64",
"@prisma/get-platform": "5.9.1"
}
},
"node_modules/@prisma/get-platform": {
"version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.9.1.tgz",
"integrity": "sha512-6OQsNxTyhvG+T2Ksr8FPFpuPeL4r9u0JF0OZHUBI/Uy9SS43sPyAIutt4ZEAyqWQt104ERh70EZedkHZKsnNbg==",
"devOptional": true,
"dependencies": {
"@prisma/debug": "5.9.1"
}
},
"node_modules/@remix-run/router": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.15.0.tgz",
@@ -1051,9 +1116,9 @@
"dev": true
},
"node_modules/@types/node": {
"version": "20.11.17",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.17.tgz",
"integrity": "sha512-QmgQZGWu1Yw9TDyAP9ZzpFJKynYNeOvwMJmaxABfieQoVoiVOS6MN1WSpqpRcbeA5+RW82kraAVxCCJg+780Qw==",
"version": "20.11.19",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz",
"integrity": "sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==",
"dependencies": {
"undici-types": "~5.26.4"
}
@@ -4369,6 +4434,22 @@
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/prisma": {
"version": "5.9.1",
"resolved": "https://registry.npmjs.org/prisma/-/prisma-5.9.1.tgz",
"integrity": "sha512-Hy/8KJZz0ELtkw4FnG9MS9rNWlXcJhf98Z2QMqi0QiVMoS8PzsBkpla0/Y5hTlob8F3HeECYphBjqmBxrluUrQ==",
"devOptional": true,
"hasInstallScript": true,
"dependencies": {
"@prisma/engines": "5.9.1"
},
"bin": {
"prisma": "build/index.js"
},
"engines": {
"node": ">=16.13"
}
},
"node_modules/prop-types": {
"version": "15.8.1",
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz",

View File

@@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@prisma/client": "^5.9.1",
"next": "14.1.0",
"react": "^18",
"react-dom": "^18",
@@ -18,7 +19,7 @@
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "^4.1.0",
"@iconify/react": "^4.1.1",
"@types/node": "^20",
"@types/node": "^20.11.19",
"@types/react": "^18",
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^6.7.3",
@@ -27,7 +28,9 @@
"eslint": "^8",
"eslint-config-next": "14.1.0",
"postcss": "^8",
"prisma": "^5.9.1",
"tailwindcss": "^3.3.0",
"typescript": "^5"
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}

View File

@@ -0,0 +1,50 @@
-- CreateEnum
CREATE TYPE "AgentTool" AS ENUM ('DUCK_DUCK_GO_SEARCH', 'PUBMED', 'PYTHON_REPL', 'SEMANTIC_SCHOLER', 'STACK_EXCHANGE', 'WIKIDATA', 'WIKIPEDIA', 'YAHOO_FINANCE', 'YUOUTUBE_SEARCH');
-- CreateEnum
CREATE TYPE "MissionProcess" AS ENUM ('SEQUENTIAL', 'HIERARCHICAL');
-- CreateTable
CREATE TABLE "Agent" (
"id" SERIAL NOT NULL,
"role" TEXT NOT NULL,
"goal" TEXT NOT NULL,
"backstory" TEXT,
"tools" "AgentTool"[] DEFAULT ARRAY[]::"AgentTool"[],
"allowDelegation" BOOLEAN NOT NULL DEFAULT false,
"verbose" BOOLEAN NOT NULL DEFAULT false,
"image" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Agent_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Mission" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"tasks" JSONB NOT NULL,
"verbose" BOOLEAN NOT NULL,
"process" "MissionProcess" NOT NULL,
"result" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Mission_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "AgentInMission" (
"agentId" INTEGER NOT NULL,
"missionId" INTEGER NOT NULL,
"assignedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "AgentInMission_pkey" PRIMARY KEY ("agentId","missionId")
);
-- AddForeignKey
ALTER TABLE "AgentInMission" ADD CONSTRAINT "AgentInMission_agentId_fkey" FOREIGN KEY ("agentId") REFERENCES "Agent"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "AgentInMission" ADD CONSTRAINT "AgentInMission_missionId_fkey" FOREIGN KEY ("missionId") REFERENCES "Mission"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"

67
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,67 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum AgentTool {
DUCK_DUCK_GO_SEARCH
PUBMED
PYTHON_REPL
SEMANTIC_SCHOLER
STACK_EXCHANGE
WIKIDATA
WIKIPEDIA
YAHOO_FINANCE
YUOUTUBE_SEARCH
}
model Agent {
id Int @id @default(autoincrement())
role String
goal String
backstory String?
tools AgentTool[] @default([])
allowDelegation Boolean @default(false)
verbose Boolean @default(false)
image String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
missions AgentInMission[]
}
enum MissionProcess {
SEQUENTIAL
HIERARCHICAL
}
model Mission {
id Int @id @default(autoincrement())
name String
crew AgentInMission[]
tasks Json
verbose Boolean
process MissionProcess
result String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model AgentInMission {
agent Agent @relation(fields: [agentId], references: [id])
agentId Int // relation scalar field (used in the `@relation` attribute above)
mission Mission @relation(fields: [missionId], references: [id])
missionId Int // relation scalar field (used in the `@relation` attribute above)
assignedAt DateTime @default(now())
@@id([agentId, missionId])
}