How to manage Rails database.yml

What is the best way to handle Rails database.yml if several people are working on a project and the location of the database is different (in particular, the socket).

+82
mysql svn ruby-on-rails
Sep 19 '09 at 23:51
source share
5 answers

First move database.yml to the template file.

If you are on Git:

 git mv config/database.yml config/database.yml.example git commit -m "moved database.yml to an example file" 

Or if you are in Subversion:

 svn move config/database.yml config/database.yml.example svn ci -m "moved database.yml to an example file" 

Second, ignore the .yml version.

If you are on Git:

 cat > .gitignore config/database.yml git add .gitignore git commit -m "ignored database.yml" 

If you are in Subversion:

 svn propset svn:ignore config "database.yml" 

Third, install Where is your database.yml, dude? :

 script/plugin install git://github.com/technicalpickles/wheres-your-database-yml-dude 

This plugin warns developers before starting any Rake tasks if they have not created their own local version of config/database.yml .

Fourth, configure the Capistrano deployment task:

 # in RAILS_ROOT/config/deploy.rb: after 'deploy:update_code', 'deploy:symlink_db' namespace :deploy do desc "Symlinks the database.yml" task :symlink_db, :roles => :app do run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml" end end 

Fifth, download the database.yml server version:

 scp config/database.yml user@my_server.com:/path_to_rails_app/shared/config/database.yml 
+159
Sep 20 '09 at 2:17
source share

In Capistrano 3, instead of adding a new task, you can simply do:

 set :linked_files, %w{config/database.yml} 
+16
May 11 '14 at 17:17
source share

You can use the svn: ignore property so that this file is not a version.

Instructions are here.

+2
Sep 19 '09 at 23:56
source share

Another method that uses capistrano ERb to request credentials during deployment.

http://www.simonecarletti.com/blog/2009/06/capistrano-and-database-yml/

+2
Mar 02 2018-11-11T00:
source share

In addition to the answers above, I wrote a rake task like "Where is your database.yml, dude?", But allowing you to store sample templates for any configuration file. Check this out: https://github.com/Velid/exemplify

As an alternative to writing individual production configurations and linking them through Capistrano, I would also suggest using environment variables for your credentials:

 password: <%= ENV['PROD_DATABASE_PASSWORD'] %> 

There are many tools and ways to make this affordable.

0
Jul 16 '14 at 7:32
source share



All Articles