Prisma Init
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "Profile" (
|
||||
"id" UUID NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"description" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "Profile_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Link" (
|
||||
"id" UUID NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"url" TEXT NOT NULL,
|
||||
"profileId" UUID NOT NULL,
|
||||
|
||||
CONSTRAINT "Link_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Skill" (
|
||||
"id" UUID NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"profileId" UUID NOT NULL,
|
||||
|
||||
CONSTRAINT "Skill_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Experience" (
|
||||
"id" UUID NOT NULL,
|
||||
"company" TEXT NOT NULL,
|
||||
"position" TEXT NOT NULL,
|
||||
"startDate" TIMESTAMP(3) NOT NULL,
|
||||
"endDate" TIMESTAMP(3),
|
||||
"achievements" TEXT[],
|
||||
"profileId" UUID NOT NULL,
|
||||
|
||||
CONSTRAINT "Experience_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Project" (
|
||||
"id" UUID NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"url" TEXT,
|
||||
"description" TEXT,
|
||||
"profileId" UUID NOT NULL,
|
||||
|
||||
CONSTRAINT "Project_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Link" ADD CONSTRAINT "Link_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Skill" ADD CONSTRAINT "Skill_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Experience" ADD CONSTRAINT "Experience_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Project" ADD CONSTRAINT "Project_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (e.g., Git)
|
||||
provider = "postgresql"
|
||||
@@ -0,0 +1,58 @@
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
output = "../src/generated/prisma"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
}
|
||||
|
||||
model Profile {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
name String
|
||||
description String
|
||||
|
||||
links Link[]
|
||||
skills Skill[]
|
||||
experience Experience[]
|
||||
projects Project[]
|
||||
}
|
||||
|
||||
model Link {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
name String
|
||||
url String
|
||||
|
||||
profileId String @db.Uuid
|
||||
profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model Skill {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
name String
|
||||
|
||||
profileId String @db.Uuid
|
||||
profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model Experience {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
company String
|
||||
position String
|
||||
startDate DateTime
|
||||
endDate DateTime?
|
||||
achievements String[]
|
||||
|
||||
profileId String @db.Uuid
|
||||
profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model Project {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
name String
|
||||
url String?
|
||||
description String?
|
||||
|
||||
profileId String @db.Uuid
|
||||
profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { PrismaPg } from "@prisma/adapter-pg";
|
||||
import { PrismaClient } from "../src/generated/prisma/client.js";
|
||||
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
if (!connectionString) {
|
||||
throw new Error("DATABASE_URL is not set");
|
||||
}
|
||||
|
||||
const prisma = new PrismaClient({
|
||||
adapter: new PrismaPg({ connectionString }),
|
||||
});
|
||||
|
||||
const PROFILE_ID = "00000000-0000-4000-8000-000000000001";
|
||||
|
||||
const profile = {
|
||||
name: "Whoami",
|
||||
description: "Seeded profile",
|
||||
};
|
||||
|
||||
async function main() {
|
||||
await prisma.profile.upsert({
|
||||
where: { id: PROFILE_ID },
|
||||
create: {
|
||||
id: PROFILE_ID,
|
||||
...profile,
|
||||
},
|
||||
update: profile,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await main();
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
Reference in New Issue
Block a user