Francesco
How to run a custom module when starting a release in production?
Hello!
I have made a data migration module following this article which allows me to run custom modules responsible for modifying the data that already lives in production. These might be as simple as running an update query on a table, or they might update data in an external system. Data migrations essentially mimics ecto migrations by having a folder full of migration modules, and it uses a table to track which data migration modules have already been run.
The goal is to run this data migration module when we deploy our release so that we can keep our data consistent without any downtime or manual intervention.
The problem is that I’m very new to elixir releases and I’m very lost on how to go about running this data migration module (that will in turn run all our unrun data migrations). How do I go about running a module when we deploy a release? Is there a best practice for this?
Thanks in advance for the help!
Most Liked
ehayun
If you want to run it from elixir, create migration module that follow elixir application loader (like genserver or so) put it in the application file and add it to the startup applications
def start(_type, _args) do
children = [
# Start the Ecto repository
Justice.Repo,
# Start the Telemetry supervisor
JusticeWeb.Telemetry,
# Start the PubSub system
{Phoenix.PubSub, name: Justice.PubSub},
Justice.Migrate, # <==============================================
# Start the Endpoint (http/https)
JusticeWeb.Endpoint
# Start a worker by calling: Justice.Worker.start_link(arg)
# {Justice.Worker, arg}
]
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










