Is it possible to "release" a mix task?

I have been working with the ideas from this post: Is it possible to run migrations as a different user? - #5 by hauleth about running migrations as a different user. This is for running on production machine for security reasons we do not wish to allow the app to have permissions to create or modify tables.

Is it possible to build a mix task into an executable? Like escript? Because then we could use OptionParser or similar to read command-line arguments. Or maybe that is too difficult because it would need this separate script to connect to the same PostGres database (but using a different username/password). Maybe it is better to simply prompt the user for input from iex? Perhaps using something like Cowrie ā€” cowrie v0.3.0 ?

I hope am explaining this situation clearly. Iā€™m not sure what options are possible.

Thank you

I would go with two different repos MyApp.Repo for the app and MyApp.Migrator.Repo for the migrations with another credentials.

Then within an Application.start_phase/3 one calls

{:ok, pid} = MyApp.Migrator.Repo.start_link()
Ecto.Migrator.run(MyApp.Migrator.Repo, :up, all: true)
:ok = MyApp.Migrator.Repo.stop(pid)
1 Like