Heroku Review Apps:复制数据库到审查应用程序

编程入门 行业动态 更新时间:2024-10-27 16:29:49
本文介绍了Heroku Review Apps:复制数据库到审查应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试完全自动化 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:复制数据库到审查应用程序

    本文发布于:2023-10-17 12:48:14,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1500943.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:应用程序   数据库   Heroku   Review   Apps

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!