MySQL 如何管理 Rails database.yml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1449836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to manage Rails database.yml
提问by phillee
What's the best way to handle the Rails database.yml if multiple people are working on the project and database locations are different (the socket in particular).
如果多人正在处理项目并且数据库位置不同(特别是套接字),那么处理 Rails database.yml 的最佳方法是什么?
回答by James A. Rosen
First, move database.yml
to a template file.
首先,移至database.yml
模板文件。
If you're on Git:
如果你在 Git 上:
git mv config/database.yml config/database.yml.example
git commit -m "moved database.yml to an example file"
Or, if you're on Subversion:
或者,如果您使用的是 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.
其次,忽略 .yml 版本。
If you're on Git:
如果你在 Git 上:
cat > .gitignore
config/database.yml
git add .gitignore
git commit -m "ignored database.yml"
If you're on Subversion:
如果您使用的是 Subversion:
svn propset svn:ignore config "database.yml"
Third, install Where's your database.yml, dude?:
第三,安装你的database.yml 在哪里,伙计?:
script/plugin install git://github.com/technicalpickles/wheres-your-database-yml-dude
That plugin alerts developers before any Rake tasks are run if they haven't created their own local version of config/database.yml
.
如果开发人员没有创建自己的本地版本的config/database.yml
.
Fourth, set up a Capistrano deploy task:
四、设置Capistrano部署任务:
# 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, upload the server's version of database.yml:
五、上传服务器版本的database.yml:
scp config/database.yml user@my_server.com:/path_to_rails_app/shared/config/database.yml
回答by Martin Sommer
In Capistrano 3, instead of adding the new task, you can just do:
在 Capistrano 3 中,您可以执行以下操作,而不是添加新任务:
set :linked_files, %w{config/database.yml}
回答by Sam DeFabbia-Kane
You can use the svn:ignore property to prevent that file from being versioned.
您可以使用 svn:ignore 属性来防止该文件被版本控制。
回答by Paul Alexander
Yet another method that uses capistrano an ERb to prompt for the credentials during deployment.
另一种方法是使用 capistrano 和 ERb 在部署期间提示输入凭据。
http://www.simonecarletti.com/blog/2009/06/capistrano-and-database-yml/
http://www.simonecarletti.com/blog/2009/06/capistrano-and-database-yml/
回答by smugglerFlynn
In addition to above answers, I wrote a rake task similar to "Where's your database.yml, dude?", but allowing to keep template examples of any configuration file. Check it out: https://github.com/Velid/exemplify
除了上述答案之外,我还编写了一个类似于“你的 database.yml 在哪里,老兄?”的 rake 任务,但允许保留任何配置文件的模板示例。看看:https: //github.com/Velid/exemplify
As an alternative to writing separate production configs and linking them via Capistrano, I would also suggest using environment variables for your credentials:
作为编写单独的生产配置并通过 Capistrano 链接它们的替代方法,我还建议为您的凭据使用环境变量:
password: <%= ENV['PROD_DATABASE_PASSWORD'] %>
There are a lot of handytoolsand waysto do this available around.