Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know which is my current environment at Phoenix framework

I am following a phoenix book which says:

Be careful. The ecto.migrate task will migrate the database for your current environment. So far, we’ve been running the dev environment. To change the environment, you’d set the MIX_ENV operating-system environment variable.

But I dont know which is mi current environment, I print echo MIX_ENV variable and it's empty, how can I knowwhich environment I am in and/or change from environments?

like image 528
lapinkoira Avatar asked Aug 14 '17 22:08

lapinkoira


1 Answers

If the MIX_ENV environment variable is empty Mix.env defaults to :dev:

$ iex -S mix
> Mix.env
# => :dev

If you set MIX_ENV to another existing environment (test or prod, then Mix.env will return it:

$ MIX_ENV=test iex -S mix
> Mix.env
# => :test

There's no need to define another config.

To get something from your config use for example Application.get_env/2:

Application.get_env(:your_app_name, YourAppName)[:adapter]
# => Ecto.Adapters.Postgres
like image 88
guitarman Avatar answered Oct 07 '22 21:10

guitarman