Data Seeding
This commit is contained in:
+126
-10
@@ -2,6 +2,7 @@ import { PrismaPg } from "@prisma/adapter-pg";
|
|||||||
import { PrismaClient } from "../src/generated/prisma/client.js";
|
import { PrismaClient } from "../src/generated/prisma/client.js";
|
||||||
|
|
||||||
const connectionString = process.env.DATABASE_URL;
|
const connectionString = process.env.DATABASE_URL;
|
||||||
|
|
||||||
if (!connectionString) {
|
if (!connectionString) {
|
||||||
throw new Error("DATABASE_URL is not set");
|
throw new Error("DATABASE_URL is not set");
|
||||||
}
|
}
|
||||||
@@ -13,18 +14,133 @@ const prisma = new PrismaClient({
|
|||||||
const PROFILE_ID = "00000000-0000-4000-8000-000000000001";
|
const PROFILE_ID = "00000000-0000-4000-8000-000000000001";
|
||||||
|
|
||||||
const profile = {
|
const profile = {
|
||||||
name: "Whoami",
|
name: "Myle Ataraxia",
|
||||||
description: "Seeded profile",
|
description:
|
||||||
|
"A backend developer in love with creative challenges.",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const links = [
|
||||||
|
{
|
||||||
|
name: "inkstory.net",
|
||||||
|
url: "https://inkstory.net",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "GitHub",
|
||||||
|
url: "https://github.com/MyleAtaraxia"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const skills = [
|
||||||
|
"Go",
|
||||||
|
"TypeScript",
|
||||||
|
"Node.js",
|
||||||
|
"NestJS",
|
||||||
|
"GraphQL",
|
||||||
|
"Kotlin",
|
||||||
|
"Android",
|
||||||
|
"REST API",
|
||||||
|
"PostgreSQL",
|
||||||
|
"SQL",
|
||||||
|
"Docker",
|
||||||
|
"Redis",
|
||||||
|
"gRPC",
|
||||||
|
];
|
||||||
|
|
||||||
|
const experience = [
|
||||||
|
{
|
||||||
|
company: "inkstory.net",
|
||||||
|
position: "Fullstack Developer",
|
||||||
|
startDate: new Date("2023-04-01"),
|
||||||
|
endDate: new Date("2025-02-01"),
|
||||||
|
achievements: [
|
||||||
|
"Developed and maintained an Android application using Kotlin, MVVM, Jetpack, and Coroutines",
|
||||||
|
"Integrated the application with REST APIs, including caching and image loading",
|
||||||
|
"Developed and maintained backend services, including APIs, authentication, and data synchronization",
|
||||||
|
"Deployed and maintained backend infrastructure, logging, and monitoring",
|
||||||
|
"Designed and maintained PostgreSQL database schemas",
|
||||||
|
"Developed and optimized SQL queries, indexes, and database migrations",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const projects = [
|
||||||
|
{
|
||||||
|
name: "inkstory.net",
|
||||||
|
url: "https://inkstory.net",
|
||||||
|
description:
|
||||||
|
"A Fullstack project that I was a maintainer of for 2 years, actively used by many people.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Componentable",
|
||||||
|
url: "https://github.com/MyleAtaraxia/Componentable",
|
||||||
|
description: "A single class library for the Godot Game Engine that introduces components to it, I use it quite often in my pet projects because of how much I enjoy the querying system"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await prisma.profile.upsert({
|
await prisma.$transaction(async (tx) => {
|
||||||
where: { id: PROFILE_ID },
|
await tx.profile.upsert({
|
||||||
create: {
|
where: {
|
||||||
id: PROFILE_ID,
|
id: PROFILE_ID,
|
||||||
...profile,
|
},
|
||||||
},
|
create: {
|
||||||
update: profile,
|
id: PROFILE_ID,
|
||||||
|
...profile,
|
||||||
|
},
|
||||||
|
update: profile,
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.link.deleteMany({
|
||||||
|
where: {
|
||||||
|
profileId: PROFILE_ID,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.skill.deleteMany({
|
||||||
|
where: {
|
||||||
|
profileId: PROFILE_ID,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.experience.deleteMany({
|
||||||
|
where: {
|
||||||
|
profileId: PROFILE_ID,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.project.deleteMany({
|
||||||
|
where: {
|
||||||
|
profileId: PROFILE_ID,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.link.createMany({
|
||||||
|
data: links.map((link) => ({
|
||||||
|
...link,
|
||||||
|
profileId: PROFILE_ID,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.skill.createMany({
|
||||||
|
data: skills.map((name) => ({
|
||||||
|
name,
|
||||||
|
profileId: PROFILE_ID,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.experience.createMany({
|
||||||
|
data: experience.map((entry) => ({
|
||||||
|
...entry,
|
||||||
|
profileId: PROFILE_ID,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.project.createMany({
|
||||||
|
data: projects.map((project) => ({
|
||||||
|
...project,
|
||||||
|
profileId: PROFILE_ID,
|
||||||
|
})),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,4 +148,4 @@ try {
|
|||||||
await main();
|
await main();
|
||||||
} finally {
|
} finally {
|
||||||
await prisma.$disconnect();
|
await prisma.$disconnect();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user