Reputation: 2109
I'm working in a team in a Rails project.
Each of us have a local database for development purpose. We have a problem: Everyone have different configuration for the local database. When someone make a commit without reset the /config/database.yml
the other members of the team can't use their database because the access is not configured.
Can I have a local configuration not commited? To each one can works without problem and without the need of re-set the file every time? Sometime like the local_settings.py
in Django
Upvotes: 2
Views: 659
Reputation: 9336
Add config/database.yml
in to the .gitignore
file at root path of your rails-app.
Copy config/database.yml
with the values you need for production into config/database_example.yml
.
Now you can modify your local database and in production you copy config/database_expample.yml
to config/database.yml
If the config file is ignored by git, everyone can change it locally without getting tracked by git.
EDIT: HERE YOU SEE HOW YOU CAN REMOVE FILE FROM TRACKING!!! Ignore files that have already been committed to a Git repository
Upvotes: 2
Reputation: 102046
You can configure the database in Rails via both the config/database.yml
file and the DATABASE_URL
env var. They are merged but settings from DATABASE_URL
take precedence.
A good solution is to check in the config/database.yml
with a basic configuration thats just enough to support postgres.app
or whatever is the most common solution.
Developers that need other settings can set the DATABASE_URL
env var to customize the database configuration. Gems like figaro and dotenv make this easier.
If you have ever wondered this how Heroku manages to use the correct DB no matter what you throw into database.yml
and the DATABASE_URL
ENV var is how you should be configuring your production DB.
Why should I use ENV vars and not more database_*.yaml files?
The twelve-factor app stores config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code; unlike config files, there is little chance of them being checked into the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System Properties, they are a language- and OS-agnostic standard.
https://12factor.net/config
Upvotes: 4