0
在我的Rails 4应用程序中,我在开发和测试中使用默认的Sqlite3,而在生产中使用Postgresql(Heroku)。Rails 4:从sqlite3迁移后在开发环境中设置Postgresql
我刚刚从Sqlite3切换到Postgresql的所有三个环境,一切工作正常。
我目前的database.yml看起来像这样:
default: &default
adapter: postgresql
encoding: unicode
username: XXX
password: <--- empty --->
database: name-of-my-app
pool: 5
development:
<<: *default
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
host: localhost
production:
<<: *default
host: localhost
正如你所看到的,我使用的是默认的用户名(我的Mac OSX用户名)和密码(没有密码)和它们在硬编码database.yml文件。
如果我理解正确,从我在这里和那里阅读,这是一个双不好的做法,我应该改为:
定义自定义的用户名和密码
与环境,这样做变量
这是正确的,那么正确的做法是什么?
真棒,非常感谢你为这个详细而明确的答案。真的很有帮助。我将根据您的建议更新我的database.yml文件。再次感谢。 –