How to seed a Prod DB using Prisma, remix and fly

221 Views Asked by At

I have been trying to seed my production db using Remix.run , prisma and fly.

It works fine local but when i try and SSH into my fly instance i get

npx prisma db seed
Running seed command `tsx prisma/seed.ts` ...

An error occurred while running the seed command:
Error: Command failed with ENOENT: tsx prisma/seed.ts
spawn tsx ENOENT

I have tried installing with ts-node and that doesnt work. If i try and install tsx in the instance it does not work? Ive read things online that move ts-node and typescript to dependencies should fix but it doesnt work for me?

I seem to get this typescript error the whole time

npx prisma db seed
Running seed command `ts-node prisma/seed.ts` ...
node:internal/modules/cjs/loader:942
  throw err;
  ^

Error: Cannot find module 'typescript'
Require stack:
- /app/node_modules/ts-node/dist/util.js
- /app/node_modules/ts-node/dist/bin.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:939:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at projectLocalResolveHelper (/app/node_modules/ts-node/dist/util.js:117:24)
    at resolveCompiler (/app/node_modules/ts-node/dist/configuration.js:232:22)
    at resolveAndLoadCompiler (/app/node_modules/ts-node/dist/configuration.js:225:26)
    at findAndReadConfig (/app/node_modules/ts-node/dist/configuration.js:48:28)
    at phase3 (/app/node_modules/ts-node/dist/bin.js:254:67)
    at bootstrap (/app/node_modules/ts-node/dist/bin.js:47:30)
    at main (/app/node_modules/ts-node/dist/bin.js:33:12)
    at Object.<anonymous> (/app/node_modules/ts-node/dist/bin.js:579:5) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/app/node_modules/ts-node/dist/util.js',
    '/app/node_modules/ts-node/dist/bin.js'
  ]
}

Node.js v18.0.0

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

Not really sure what to try next - have literally tried everything I have found online. (compiling to js being one of them)

1

There are 1 best solutions below

0
On

Generally, seeding is a one-time process and should be handled carefully in production.

Check out this document from Epic Stack https://github.com/epicweb-dev/epic-stack/blob/main/docs/database.md

It has an entire section on seeding production using Prisma.