I’m currently deploying an app using Prisma using ...
# orm-help
j
I’m currently deploying an app using Prisma using AWS Elastic Beanstalk’s Nodejs platform. The only way I’ve been able to get migrations and seeding to run before building/starting the app is to do a ton of workarounds. I have to manually run the npm installation, and my start script is just a long chain of one-off scripts before actually starting Node (
npm run db:migrate && npm run db:seed && npm run all:build && node ./dist/server/index.js
). Does anyone have a documented method of getting this to work through platform hooks (or whatever the intended method is)? What I’m doing seems super hacky.
✅ 1
n
Hi Justin 👋 Did you had a look at this section in our docs which discusses caveats when deploying to AWS Elastic Beanstalk. It suggests using the
postinstall
hook to perform operations and to initialize Prisma Client. Although having an end to end guide for deploying to Elastic Beanstalk would be a good idea, I’ll pass this feedback internally.
j
It was my understanding that this section was specifically for running
prisma generate
, but I guess it would make sense that I could run the migration and seed at that point as well. I’ll give that a try on my next deploy. Thanks. 👍
I adjusted my postinstall to perform
npm run db:init
, which is defined as
Copy code
"db:init": "prisma generate && prisma migrate deploy && prisma db seed"
I’ve included an
.npmrc
to the project root, only containing
unsafe-perm=true
. My EB instance fails to launch and the logs contain the following:
Copy code
2022/08/03 01:28:30.500778 [INFO] Executing instruction: Use NPM to install dependencies
2022/08/03 01:28:30.500792 [INFO] use npm to install dependencies
2022/08/03 01:28:30.500867 [INFO] Running command /bin/sh -c npm config set jobs 1
|2022/08/03 01:28:30.855244 [INFO] Running command /bin/sh -c npm install
2022/08/03 01:29:32.435202 [INFO] 
> my-project@0.1.0 postinstall
> npm run db:init


2022/08/03 01:29:32.435500 [INFO] npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility

npm ERR! code 243
npm ERR! path /var/app/staging
npm ERR! command failed
npm ERR! command sh -c npm run db:init

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-08-03T01_28_31_138Z-debug-0.log
It would appear that moving the contents of the script directly into the
postinstall
script works.
n
So moving contents of the script to
postinstall
hook didn’t help?
j
It did help, although it’s unclear as to why.
🤔 1