Running DB migrations during CI/CD pipeline
Hey there π
I've been looking into the proper way of running DB migrations (with Prisma in my case) as a part of deployment process. Trying to understand what's the proper phase for this on Railway. E.g. Heroku has the "Release" phase defined specifically for this task https://devcenter.heroku.com/articles/release-phase. I've seen that in one of your templates migrations are ran during the build phase https://github.com/railwayapp-templates/nextjs-prisma/blob/main/package.json#L7, which works, but doesn't look like the best solution, since build and release are kinda separate phases. And running migrations via railway cli from local computer doesn't look very good either.
Did I miss any other piece of documentation? What would be the general advice for such cases?
Thanks!
GitHub
nextjs-prisma/package.json at main Β· railwayapp-templates/nextjs-pr...
Contribute to railwayapp-templates/nextjs-prisma development by creating an account on GitHub.
14 Replies
Project ID:
N/A
N/A
you can absolutely do a release phase on railway
if you share your current railway.json file and your desired migration command I'd be happy to modify your railway.json file to include a release phase/command
you can even have a migration stage
Don't have a custom config file now, nixpack defaults seems to work quite nite in my case. But where would you put the release phase in the config? π€ Couldn't find anything similar here https://docs.railway.app/deploy/config-as-code
every deployment has a railway.json file
but unfortunately I'm not at my computer anymore, so I can't make this modification for you
every deployment has a railway.json fileI'm pretty sure I don't have a railway.json file π
you might not in your project, but every deployment does get a railway.json generated for it
I forgot the button to view it though
Ah, interesting, I think I've found it in the deployment details
do you have vscode?
What do you mean?
haha okay that's a no
I'll get back to you later today
sure thing, thanks. I would appreciate a link to the docs or the conceptual description of how to get the same or similar "release" phase as you'd have on Heroku, not really looking for a specific solution for current project
it's hard to put into words, I'm not good at words, later today I will modify that railway.json you sent to have a release phase
Thanks man, appreciate it a lot! So when exactly in the workflow will the release phase run? Is it happening before deploy? What happens if it fails?
I went with adding the
nixpacks.toml
to the project with the following content
Seems to be working, although not 100% what I was looking for, as it still runs as a part of build process. But I believe there's no separate "release phase" concept on Railway.
@Brody thanks for your help!