Data Seeding

This commit is contained in:
Myle
2026-09-21 17:03:38 +03:00
parent e0b4db93b2
commit 1a5faa8087
+125 -9
View File
@@ -2,6 +2,7 @@ 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");
}
@@ -13,18 +14,133 @@ const prisma = new PrismaClient({
const PROFILE_ID = "00000000-0000-4000-8000-000000000001";
const profile = {
name: "Whoami",
description: "Seeded profile",
name: "Myle Ataraxia",
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() {
await prisma.profile.upsert({
where: { id: PROFILE_ID },
create: {
id: PROFILE_ID,
...profile,
},
update: profile,
await prisma.$transaction(async (tx) => {
await tx.profile.upsert({
where: {
id: PROFILE_ID,
},
create: {
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,
})),
});
});
}