From 862b7ba9c6c592020c234cac0478e998f2b094e0 Mon Sep 17 00:00:00 2001 From: ashwin-athappan Date: Sun, 10 Aug 2025 18:16:50 -0500 Subject: [PATCH] Fixed Local Startup Errors: Unique Id Error on restart of docker containers & Added openssl package to Dockerfile --- Dockerfile | 2 + docker-compose.yml | 2 +- packages/db/prisma/seed.ts | 284 +++++++++++++++++++------------------ 3 files changed, 147 insertions(+), 141 deletions(-) diff --git a/Dockerfile b/Dockerfile index abf84b32..8e023b2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,8 @@ WORKDIR /usr/src/app COPY . . +RUN apk add --no-cache openssl + RUN yarn install EXPOSE 3000 diff --git a/docker-compose.yml b/docker-compose.yml index 7b772c03..11e47eff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: build: context: . dockerfile: Dockerfile - container_name: daily-code-docker + container_name: daily-code-app environment: - DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres ports: diff --git a/packages/db/prisma/seed.ts b/packages/db/prisma/seed.ts index a00fa66d..36a81194 100644 --- a/packages/db/prisma/seed.ts +++ b/packages/db/prisma/seed.ts @@ -7,11 +7,11 @@ async function main() { if (!hashID.includes(seed.data.id)) { try { const alreadyExists = await db.track.findUnique({ - where:{ - id:seed.data.id - } - }) - if(!alreadyExists){ + where: { + id: seed.data.id, + }, + }); + if (!alreadyExists) { const track = await db.track.create({ data: seed.data, }); @@ -22,161 +22,165 @@ async function main() { } } } - - await db.categories.create({ - data: { + const categories = [ + { id: "web-development", category: "Web Development", }, - }); - - await db.categories.create({ - data: { + { id: "adv-web-development", category: "Advance Web Development", }, - }); - - await db.categories.create({ - data: { + { id: "dsa", category: "Data Structures and Algorithms", }, - }); - - await db.categories.create({ - data: { + { id: "devops", category: "Devops", }, - }); - - await db.categories.create({ - data: { + { id: "projects", category: "Projects", }, - }); - - await db.categories.create({ - data: { + { id: "extras", category: "Extras", }, - }); + ]; - await db.trackCategory.createMany({ - data: [ - { - trackId: "6SbPPXGkG8QKFOTW9BmL", - categoryId: "web-development", - }, - { - trackId: "ABEC", - categoryId: "adv-web-development", - }, - { - trackId: "Auth", - categoryId: "web-development", - }, - { - trackId: "CI-CD", - categoryId: "devops", - }, - { - trackId: "Next-Auth", - categoryId: "adv-web-development", - }, - { - trackId: "PayTM2", - categoryId: "projects", - }, - { - trackId: "Paytm", - categoryId: "projects", - }, - { - trackId: "Redis", - categoryId: "adv-web-development", - }, - { - trackId: "YOSAherHkqWXhOdlE4yE", - categoryId: "adv-web-development", - }, - { - trackId: "ZSQI8YNE0iL6sT1hJpts", - categoryId: "projects", - }, - { - trackId: "blog", - categoryId: "projects", - }, - { - trackId: "docker-2", - categoryId: "devops", - }, - { - trackId: "docker-easy", - categoryId: "devops", - }, - { - trackId: "dsa", - categoryId: "dsa", - }, - { - trackId: "dsa2", - categoryId: "dsa", - }, - { - trackId: "eooSv7lnuwBO6wl9YA5w", - categoryId: "adv-web-development", - }, - { - trackId: "g0AcDSPl74nk45ZZjRdU", - categoryId: "adv-web-development", - }, - { - trackId: "gZf9uBBNSbBR7UCqyyqT", - categoryId: "adv-web-development", - }, - { - trackId: "monorepo", - categoryId: "adv-web-development", - }, - { - trackId: "mw", - categoryId: "web-development", - }, - { - trackId: "nextjs-1", - categoryId: "adv-web-development", - }, - { - trackId: "nextjs-2", - categoryId: "adv-web-development", - }, - { - trackId: "oAjvkeRNZThPMxZf4aX5", - categoryId: "projects", - }, - { - trackId: "rendering", - categoryId: "adv-web-development", - }, - { - trackId: "senior", - categoryId: "extras", - }, - { - trackId: "ts-hard", - categoryId: "adv-web-development", - }, - { - trackId: "w5E6PT2t0IyOFM3bZxcM", - categoryId: "adv-web-development", - }, - ], + const existingCategories = await db.categories.findMany(); + + categories.forEach((category) => { + if (!existingCategories.find((cat) => cat.id === category.id)) { + db.categories.create({ data: category }).then(() => { + console.log(`Category ${category.id} created`); + }).catch(error => { + console.error(`Error creating category ${category.id}:`, error); + }); + } }); + + const trackCategories = [ + { + trackId: "6SbPPXGkG8QKFOTW9BmL", + categoryId: "web-development", + }, + { + trackId: "ABEC", + categoryId: "adv-web-development", + }, + { + trackId: "Auth", + categoryId: "web-development", + }, + { + trackId: "CI-CD", + categoryId: "devops", + }, + { + trackId: "Next-Auth", + categoryId: "adv-web-development", + }, + { + trackId: "PayTM2", + categoryId: "projects", + }, + { + trackId: "Paytm", + categoryId: "projects", + }, + { + trackId: "Redis", + categoryId: "adv-web-development", + }, + { + trackId: "YOSAherHkqWXhOdlE4yE", + categoryId: "adv-web-development", + }, + { + trackId: "ZSQI8YNE0iL6sT1hJpts", + categoryId: "projects", + }, + { + trackId: "blog", + categoryId: "projects", + }, + { + trackId: "docker-2", + categoryId: "devops", + }, + { + trackId: "docker-easy", + categoryId: "devops", + }, + { + trackId: "dsa", + categoryId: "dsa", + }, + { + trackId: "dsa2", + categoryId: "dsa", + }, + { + trackId: "eooSv7lnuwBO6wl9YA5w", + categoryId: "adv-web-development", + }, + { + trackId: "g0AcDSPl74nk45ZZjRdU", + categoryId: "adv-web-development", + }, + { + trackId: "gZf9uBBNSbBR7UCqyyqT", + categoryId: "adv-web-development", + }, + { + trackId: "monorepo", + categoryId: "adv-web-development", + }, + { + trackId: "mw", + categoryId: "web-development", + }, + { + trackId: "nextjs-1", + categoryId: "adv-web-development", + }, + { + trackId: "nextjs-2", + categoryId: "adv-web-development", + }, + { + trackId: "oAjvkeRNZThPMxZf4aX5", + categoryId: "projects", + }, + { + trackId: "rendering", + categoryId: "adv-web-development", + }, + { + trackId: "senior", + categoryId: "extras", + }, + { + trackId: "ts-hard", + categoryId: "adv-web-development", + }, + { + trackId: "w5E6PT2t0IyOFM3bZxcM", + categoryId: "adv-web-development", + }, + ]; + + const existingTrackCategories = await db.trackCategory.findMany(); + + const insertableTrackCategories = trackCategories.filter(tc => + !existingTrackCategories.find(existing => existing.trackId === tc.trackId && existing.categoryId === tc.categoryId), + ); + + if (insertableTrackCategories.length === 0) { + await db.trackCategory.createMany({ data: insertableTrackCategories }); + } } main()