Phoenix: Moving Repo config & other config to dev.secret.exs

Created on 9 Sep 2015  路  7Comments  路  Source: phoenixframework/phoenix

Currently database config is stored in the dev.exs, this means we are keeping the local database passwords in the code, which gets committed into repo.

I believe we can avoid this if we move database config to dev.secret.exs

This will also ensure that different team members working on same codebase need not change the config after pulling from repo to suit their local config.

Need to do the following

  • Create dev.secret.exs & test.secret.exs
  • Move database config to dev.secret.exs & test.secret.exs
  • Import them to dev.exs & text.exs
  • Add secret files to .gitignore

Please let me know if this feature should be added, will make changes and submit PR

Most helpful comment

Is util to have?

import_config "dev.secret.exs", ignore_if_notexists: true
or
import_config/2

All 7 comments

:-1:
For testing and dev is fine to put default values.

If I run tests do not make any sens after clone
repo to add this test.secret.exs to be able to run tests.
1) no time
2) I don't now what to write
3) I need to read conf example to write correct conf
4) For my team in same location, is fast to use same
dev/test server interlanly.

For CI/testing if you add this test.secret.exs
prepare script need to generate this file.

What you can do, this is my proposal:
To add option for import_config
http://elixir-lang.org/docs/v1.0/mix/Mix.Config.html#import_config/1
ignore_if_notexists
or
to add second version
import_config/2

and to add in test.exs
on the end of the file:

import_config "test.secret.exs", ignore_if_notexists: true
same for dev.exs
import_config "dev.secret.exs", ignore_if_notexists: true

Now we stil have values in test.exs/dev.exs (see automatic testing/CI)
but any team/developer if want can just add file test.secret.exs/dev.secret.exs
put new conf options and go.

Note:
for prod env this file remain _require_: throw exception if prod.secret.exs not exists
import_config "prod.secret.exs"
or
import_config "prod.secret.exs", ignore_if_notexists: false

But you can do this now:

if checkIfConfFileExists do
  import_config "test.secret.exs"
end

Agreed with @Tica2. The current default is fine for the huge majority of users. If you need special rules within your team, it is quite easy to add a dev.secret.exs yourself, it doesn't make much sense as a default though.

Thank you!

Is util to have?

import_config "dev.secret.exs", ignore_if_notexists: true
or
import_config/2

No. You should just have the file there, honestly.

:+1: Perfect!

then you have to at least create the config/dev.secret.exs file with blank content
or you get an error dev.secret.exs does not exist because of import_config "dev.secret.exs"
or if you need to, override the default database username and password in dev.exs with the ones in dev.secret.exs

Was this page helpful?
0 / 5 - 0 ratings