nallwhy
What is the best practice to run ecto migration before deploying?
I’m deploying my app with fly.io.
I have no idea how to run ecto migration before deploying.
If I don’t do that, new version app will make errors because of broken DB schema.
I only have the information about prod DB in secrets of fly.io, not in local.
Marked As Solved
stefanchrobot
Take a look at the Phoenix’s deployment guide. I think people usually run the migrations right before the app starts. I run those as one Docker command:
CMD ["sh", "-c", "bin/app eval MyApp.Release.migrate && bin/app start"]
Also Liked
trisolaran
I don’t think you need to take any special care. Ecto takes care of this case by locking the migrations table:
Another reason to love Ecto ![]()
zachallaun
Highly recommend the Safe Ecto Migrations series of posts — gave me a lot more confidence and understanding in this area.
trisolaran
Yes. The first instance to acquire the lock will run the migrations. All other instances will wait for the first instance to finish and release the lock - they will then acquire the lock in turn, see the database already migrated, and do nothing.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









