尝试完全自动化 Heroku 的审查应用(测试版).Heroku 希望我们使用 db/seeds.rb 为最近启动的实例的数据库做种子.
Trying to fully automate Heroku's Review Apps (beta) for an app. Heroku wants us to use db/seeds.rb to seed the recently spun up instance's DB.
我们没有这个应用程序的 db/seeds.rb.我们想设置一个脚本来从当前父级(暂存)复制现有数据库,并将其用作正在审核的新应用的数据库.
We don't have a db/seeds.rb with this app. We'd like to set up a script to copy the existing DB from the current parent (staging) and use that as the DB for the new app under review.
这我可以手动完成:
heroku pg:copy myapp::DATABASE_URL DATABASE_URL --app myapp-pr-1384 --confirm myapp-pr-1384
但我不知道如何将 Heroku 创建的应用名称添加到 postdeploy 脚本中.
But I can't get figure out how to get the app name that Heroku creates into the postdeploy script.
有人试过这个并知道它是如何自动化的吗?
Anyone tried this and know how it might be automated?
推荐答案我遇到了同样的问题,这是我如何解决的.
I ran into this same issue and here is how I solved it.
将要从中复制的数据库 url 设置为管道基础应用程序上的环境变量.就我而言,这是 STAGING_DATABASE_URL.url 格式为 postgresql://username:password@host:port/db_name.
在您的 app.json 文件中,确保复制该变量.
In your app.json file make sure to copy that variable over.
在您的 app.json 中提供一个新的数据库,它将设置 DATABASE_URL 环境变量.
In your app.json provision a new database which will set the DATABASE_URL environment variable.
使用以下脚本复制数据库pg_dump $STAGING_DATABASE_URL |psql $DATABASE_URL
Use the following script to copy over the database pg_dump $STAGING_DATABASE_URL | psql $DATABASE_URL
这是我的 app.json 文件以供参考:
Here is my app.json file for reference:
{ "name": "app-name", "scripts": { "postdeploy": "pg_dump $STAGING_DATABASE_URL | psql $DATABASE_URL && bundle exec rake db:migrate" }, "env": { "STAGING_DATABASE_URL": { "required": true }, "HEROKU_APP_NAME": { "required": true } }, "formation": { "web": { "quantity": 1, "size": "hobby" }, "resque": { "quantity": 1, "size": "hobby" }, "scheduler": { "quantity": 1, "size": "hobby" } }, "addons": [ "heroku-postgresql:hobby-basic", "papertrail", "rediscloud" ], "buildpacks": [ { "url": "heroku/ruby" } ] }更多推荐
Heroku Review Apps:复制数据库到审查应用程序
发布评论