[英]Working on a rails app locally with a remote Postgres connection?
Is there a way to configure the database.yml file to connect to Heroku's Postgres remotely? 有没有一种方法可以配置database.yml文件以远程连接到Heroku的Postgres?
I'm having trouble understanding how Heroku, Rails and PG gem work together. 我无法了解Heroku,Rails和PG gem如何一起工作。
It looks like during deployment, Heroku re-writes the database.yml file - is it possible to see the contents of this updated .yml file and use it locally? 看起来在部署期间,Heroku重新编写了database.yml文件-是否可以查看此更新的.yml文件的内容并在本地使用?
Below are the steps to access Heroku db from local development: 以下是从本地开发访问Heroku数据库的步骤:
Login to your heroku account. 登录到您的heroku帐户。
Navigate to this URL https://postgres.heroku.com/databases/ OR you can get heroku db url by running this command in the terminal: heroku pg:credentials:url
导航至以下URL https://postgres.heroku.com/databases/,或者您可以通过在终端中运行以下命令来获取heroku数据库url: heroku pg:credentials:url
Select your application database. 选择您的应用程序数据库。
You will able to see your heroku pg credentials: 您将能够看到您的heroku pg凭据:
Host xxxxxxxxx.77777.amazonaws.com Database 42feddfddeee Username 44444444444 Port xxxx Password 777sfsadferwefsdferwefsdf
collect above details and put in your databse.yml file development evn: 收集以上详细信息,并放入您的databse.yml文件开发evn中:
adapter: postgresql host: < host > # HOST port: < port > # Port database: < database name > # Database Name username: < user_name > # User Name password: '< password >' # Password
Restart you application, 重新启动您的应用程序,
Best of luck..!! 祝你好运.. !!
I am a bit of a newbie and may have misunderstood your question - but. 我是新手,可能误解了您的问题-但是。 Developed a ROR application using postgress database. 使用postgress数据库开发了ROR应用程序。 Then uploaded to Heroku. 然后上传到Heroku。 I ran DB/Migrate/schema.rb
to set up the remote Postgresql database. 我运行DB/Migrate/schema.rb
来设置远程Postgresql数据库。
From memory heroku run rake db:init
(but I could be wrong). 从内存heroku运行rake db:init
(但我可能是错的)。 Whenver I update the database in develpment to get update in Heroku I have to promote code and run heroku run rake db:migrate
每当我以开发方式更新数据库以在Heroku中获取更新时,我都必须升级代码并运行heroku run rake db:migrate
From my config/dtabase.yml
从我的config/dtabase.yml
development:
adapter: postgresql
encoding: unicode
database: di_development
pool: 5
username: davidlee
password:
test:
adapter: postgresql
encoding: unicode
database: di_test
pool: 5
username: davidlee
password:
production:
adapter: postgresql
encoding: unicode
database: di_production
pool: 5
username: user
password:
Pierre 皮埃尔
I am not a postgres user but this should work. 我不是postgres用户,但是应该可以。 You can alter your database.yml
to include host
and port
您可以更改您的database.yml
以包括host
和port
production:
adapter: postgresql
encoding: unicode
database: di_production
pool: 5
username: user
password:
host: heroku.host.name
port: <postgres listen port>
And of course, you should allow connection on the server side, both at the firewall level and database level. 当然,您应该允许在服务器端进行防火墙级别和数据库级别的连接。
A simple hack to see contents of #{Rails.root}/config/database.yml
is to write code to load this yml into an object, then print it out on the UI 查看#{Rails.root}/config/database.yml
内容的简单技巧是编写代码以将该yml加载到对象中,然后在UI上将其打印出来
DB_CONFIG = YAML.load(File.read("#{Rails.root}/config/database.yml", __FILE__))
puts DB_CONFIG["production"].inspect # or what ever method you want to print it
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.