code100x / daily-code

https://projects.100xdevs.com/
585 stars 722 forks source link

bug: Project manual local setup is failing. #476

Open decoded-satapathy opened 1 week ago

decoded-satapathy commented 1 week ago

Describe the bug Database seeding fails while running the setupDB.sh script while setting the project up locally.

To Reproduce Steps to reproduce the behavior:

  1. Follow the steps in the README.md to set the project locally (the one that doesn't use docker-compose)
  2. After running the script setupDB.sh, I got the error that the seeding has failed due to Unique constraint failed on the fields: (`id`)

Expected behavior The expected behavior was that the script would run and the docker container running Postgres that starts would have some dummy data.

Screenshots or GIFs image

PrismaClientKnownRequestError: 
Invalid `db.track.create()` invocation in
/home/osatapathy/kirat-Cohort/cohort-1-to-100/week_20_openAPI/daily-code/packages/db/prisma/seed.ts:9:32

  6 const promises: Promise<any>[] = [];
  7 seedsData.forEach((seed) => {
  8   if (!hashID.includes(seed.data.id)) {
→ 9     const promise = db.track.create(
Unique constraint failed on the fields: (`id`)
    at In.handleRequestError (/home/osatapathy/kirat-Cohort/cohort-1-to-100/week_20_openAPI/daily-code/node_modules/@prisma/client/runtime/library.js:122:6854)
    at In.handleAndLogRequestError (/home/osatapathy/kirat-Cohort/cohort-1-to-100/week_20_openAPI/daily-code/node_modules/@prisma/client/runtime/library.js:122:6188)
    at In.request (/home/osatapathy/kirat-Cohort/cohort-1-to-100/week_20_openAPI/daily-code/node_modules/@prisma/client/runtime/library.js:122:5896)
    at async l (/home/osatapathy/kirat-Cohort/cohort-1-to-100/week_20_openAPI/daily-code/node_modules/@prisma/client/runtime/library.js:127:11167)
    at async Promise.all (index 5)
    at async main (/home/osatapathy/kirat-Cohort/cohort-1-to-100/week_20_openAPI/daily-code/packages/db/prisma/seed.ts:15:3) {
  code: 'P2002',
  clientVersion: '5.12.0',
  meta: { modelName: 'Track', target: [ 'id' ] }
}

An error occurred while running the seed command:
Error: Command failed with exit code 1: ts-node prisma/seed.ts

Info (please complete the following information):

Additional context My hypothesis is that the seed data has some duplicate id value and the quickest solution if that's the problem is, is to reupload the dummy data from the actual database.

Chaitanya1672 commented 1 week ago

Hi @decoded-satapathy, I also got this error when I was trying to reseed the data. Have you previously seeded that data? If it's true then you should remove data first.

vanshaj-sharma commented 1 hour ago

hello @decoded-satapathy @Chaitanya1672, I was trying to setup the project locally for the first time, and got the following issue (attached below), my machine has postgres locally running on port 5432 so i've made relevant changes to connect the db to a docker postgres container. Asus@DESKTOP-5TBFKPS MINGW64 /d/my-git-contributions-folder/daily-code/packages/db (main) $ ./setupDB.sh =================DB Setup================= .env file exists Will you use a Local DB (L) or Cloud DB (C) L Will you use Postgres Server (P) or Docker Setup (D) D Setting up Docker time="2024-06-29T11:29:41+05:30" level=warning msg="D:\\my-git-contributions-folder\\daily-code\\packages\\db\\docker-compose.yml:version` is obsolete" [+] Running 1/0 ✔ Container db-postgres-1 Running 0.0s =================Container is up================= =================Migrating DB================= node:internal/modules/cjs/loader:1147 throw err; ^

Error: Cannot find module 'D:\my-git-contributions-folder\daily-code\node_modules\node_modules\prisma\build\index.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15) at Module._load (node:internal/modules/cjs/loader:985:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { code: 'MODULE_NOT_FOUND', requireStack: [] }

Node.js v20.11.0 Seeds not applied. Proceeding to seed. =================Seeding DB================= node:internal/modules/cjs/loader:1147 throw err; ^

Error: Cannot find module 'D:\my-git-contributions-folder\daily-code\node_modules\node_modules\prisma\build\index.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15) at Module._load (node:internal/modules/cjs/loader:985:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { code: 'MODULE_NOT_FOUND', requireStack: [] }

Node.js v20.11.0`

Screenshot (35)

vanshaj-sharma commented 1 hour ago

I am facing the same errors while using a cloud data base as well, `Asus@DESKTOP-5TBFKPS MINGW64 /d/my-git-contributions-folder/daily-code/packages/db (main) $ ./setupDB.sh =================DB Setup================= .env file exists Will you use a Local DB (L) or Cloud DB (C) C Enter the DB URI of your Cloud DB postgresql://test_owner:da8RqY4rDIX@ep-steep-waterfall-a5rgxxnl.us-east-2.aws.neon.tech/100xdevs?sslmode=require =================Migrating DB================= node:internal/modules/cjs/loader:1147 throw err; ^

Error: Cannot find module 'D:\my-git-contributions-folder\daily-code\node_modules\node_modules\prisma\build\index.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15) at Module._load (node:internal/modules/cjs/loader:985:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { code: 'MODULE_NOT_FOUND', requireStack: [] }

Node.js v20.11.0 Seeds not applied. Proceeding to seed. =================Seeding DB================= node:internal/modules/cjs/loader:1147 throw err; ^

Error: Cannot find module 'D:\my-git-contributions-folder\daily-code\node_modules\node_modules\prisma\build\index.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15) at Module._load (node:internal/modules/cjs/loader:985:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { code: 'MODULE_NOT_FOUND', requireStack: [] }

Node.js v20.11.0`