Hi guys, is there a way I can run seeds from sever...
# orm-help
g
Hi guys, is there a way I can run seeds from several locations on command? In my project I have 2 packages each with its own prisma folder and everything in it, including seeds. the suggestions from the doc doesn't work for me as I need to specify 2 different path for seeds and prior I need to dynamically setup the
DATABASE_URL
which is working fine for migrations, but now for seeding i'm unsure how to proceed 🤔 In my script I tried running:
Copy code
const seeds = spawnSync('npx', ['ts-node', './src/package/package_1/prisma/seed.ts']);
but i get the error:
Copy code
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module './seed.ts'
Require stack:
- /application/src/packages/package_1/prisma/imaginaryUncacheableRequireResolveScript
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at requireResolveNonCached (/application/node_modules/ts-node/dist/bin.js:549:16)
    at getProjectSearchDir (/application/node_modules/ts-node/dist/bin.js:519:40)
    at phase3 (/application/node_modules/ts-node/dist/bin.js:267:27)
    at bootstrap (/application/node_modules/ts-node/dist/bin.js:47:30)
    at main (/application/node_modules/ts-node/dist/bin.js:33:12)
    at Object.<anonymous> (/application/node_modules/ts-node/dist/bin.js:579:5)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/application/src/packages/package_1/prisma/imaginaryUncacheableRequireResolveScript'
  ]
}
Any ideas? 😄 Thanks in advance 🙂
✅ 1
@Raphael Etim any chance you could point me in the right direction here? 🙂
r
Hi @Gustavo 👋
I'm taking a look now and would get back with a response
g
amazing! thank you 🙂
r
Have you tried running the seed for one using the recommended approach to see if it executes?
g
Thanks for replying Raphael, it turns out my problem is a ts bundling issue, and not a prisma one. to give more context: in development mode it works just fine, either way using the version I posted above or having the
prisma
prop specified in my `package.json`as:
Copy code
"prisma": {
        "seed": "ts-node prisma/seed.ts"
    },
like docs show, the thing here is that as I have several, i need to run command from the specific package location first. In my example using
spawnSync
I needed to pass the option:
cwd
to specify the location from which the command should be ran.
r
I'm glad you were able to resolve this.
✅ 1