mix ecto.setup programmatically

According to Phoenix Release Docs you an create a App.Release module to mimic ecto.migrate programmatically for deployment.

But I am looking for a way for a fresh installation, if the database does not exist yet and has to be bootstrapped. Mix Ecto.setup would do that for me in dev environment. But in production with mix release?


It really depends on your database of choice and your production setup. For example, mix ecto.create/setup do a bunch of assumptions about your database, such as it is running in the same machine as the application server, but that’s actually unlikely in prod. Also different OS distributions may require different tweaking, so the best option in my mind is to look into your DB+OS combo and do the setup yourself, especially as it is a one-off.


Although I wrote ‘production’ I meant actually ‘in Devops’. So I want to create whole setups in a pipeline, after it has been built and released. For this I need a way to make sure the i.e. database container is up and running and ready for a migration.

I was assuming ecto.setup is handling the different database setups. Of course I provide parameter for the deployment so that elixir is aware of the database.

In a ‘real’ production environment, the db user naturally has no permissions to create or drop databases.