首先,我强烈建议您每月支付额外的 50 美元。为此,您会得到各种很酷的东西,例如forking 和pipelines,以及这有点骇人听闻的事实。老实说,当您清除暂存数据库时,我真的不知道这是否最终会擦除您的生产数据。请在尝试之前进行备份。
我将此答案视为对技术挑战而非业务决策的回答。废话不多说,
使用 Heroku Postgres 模式在同一个数据库上设置多个环境
首先,我删除了现有的开发数据库并将生产数据库添加到我的生产应用程序中。
heroku addons:add heroku-postgresql:crane
> Adding heroku-postgresql:crane on test-shared-app... done, v# ($50/mo)
> Attached as HEROKU_POSTGRESQL_RED_URL
这在RED 颜色下附加了一个数据库,因此请将HEROKU_POSTGRESQL_RED_URL 替换为适合您应用的颜色。
这会将数据库附加到生产应用程序,但我们需要连接到同一个应用程序以进行暂存。首先,创建暂存模式
heroku run "bundle exec rails runner 'ActiveRecord::Base.connection.execute(%q{CREATE SCHEMA staging})'"
接下来,创建临时应用程序。请参阅Managing Multiple Environments for an App 了解更多信息。
heroku create --remote staging test-shared-app-staging
heroku config:set RACK_ENV=staging RAILS_ENV=staging --remote staging
然后,从现有应用中复制环境数据。 在网址末尾添加?schema_search_path=staging。
heroku config --remote heroku --shell
# make note of your database URLs
heroku config:set --remote staging \
DATABASE_URL=postgres://...?schema_search_path=staging \
HEROKU_POSTGRESQL_RED_URL=postgres://...?schema_search_path=staging
然后推送到登台
git push staging master
现在,在 staging 上运行迁移
heroku run --remote staging bundle exec rake db:migrate
然后尝试一下。
我的“应用程序”在http://test-shared-app.herokuapp.com/posts 和http://test-shared-app-staging.herokuapp.com/posts 运行。你可以在https://github.com/benmanns/heroku-shared-app查看源代码。