Running prisma migrate deploy in a production server
Hi all, I was wondering if I should be running prisma generate before prisma migrate deploy in a production server, I feel like I haven't seen this in any of the docs I've seen. I'm currently executing this:
2 Replies
Skipping coffee for instant knowledge! Let's brew that AI answer now.
Based on the knowledge sources provided, I can answer your question about running
prisma migrate deploy
in a production server.
You are correct in running prisma migrate deploy
in your production environment. This command is specifically designed for applying pending migrations in non-development environments like staging, testing, or production.
However, regarding your question about running prisma generate
before prisma migrate deploy
, the knowledge sources don't explicitly state that this is necessary in production. The prisma generate
command is typically used to generate Prisma Client, which is usually done during the build process or development phase.
That being said, running prisma generate
before prisma migrate deploy
in production is not harmful and can ensure that your Prisma Client is up-to-date with any schema changes. This approach aligns with the general deployment workflow described in the Prisma documentation.
Here's a relevant quote from the Prisma documentation on deploying database changes:
"To apply pending migrations to staging, testing, or production environments, run the migrate deploy
command as part of your CI/CD pipeline"
Your current execution order seems appropriate:
1. prisma generate
(to ensure Prisma Client is up-to-date)
2. prisma migrate deploy
(to apply any pending migrations)
3. Seed the database (if necessary)
4. Start your application
This approach ensures that your database schema is up-to-date and that your Prisma Client reflects any recent changes before your application starts.
Remember, it's generally recommended to run these commands as part of an automated CI/CD pipeline rather than manually on the production server. Also, ensure that your production database URL is correctly set in your environment variables.Hey 👋
There is no harm in running
prisma generate
before running migrate deploy
command. You can continue doing so