简体   繁体   English

如何使用Heroku上的新数据库

[英]How to use a new database on Heroku

Originally when I provisioned a database on Heroku (free one), then I my app got a new environment variable called DATABASE_URL that points to a newly created database and my app uses this one.最初,当我在 Heroku(免费)上配置数据库时,我的应用程序获得了一个名为DATABASE_URL的新环境变量,它指向一个新创建的数据库,我的应用程序使用了这个数据库。

Today when I provisioned a new database on Heroku (paid) via the UI, I got a new environment variable called HEROKU_POSTGRESQL_MAUVE_URL that points to new database.今天,当我通过 UI 在 Heroku(付费)上配置新数据库时,我得到了一个名为HEROKU_POSTGRESQL_MAUVE_URL的新环境变量,它指向新数据库。

How do I point my Heroku app to this newly provisioned database HEROKU_POSTGRESQL_MAUVE_URL ?如何将我的 Heroku 应用程序指向这个新配置的数据库HEROKU_POSTGRESQL_MAUVE_URL

I expected my database URL to be swapped with HEROKU_POSTGRESQL_MAUVE_URL but that didn't happen.我希望我的数据库 URL 与HEROKU_POSTGRESQL_MAUVE_URL交换,但这并没有发生。

This happens when your app has multiple databases : 当您的应用程序有多个数据库时会发生这种情况

As part of the provisioning process, a DATABASE_URL config var is added to your app's configuration.作为配置过程的一部分, DATABASE_URL配置变量会添加到您的应用程序配置中。 DATABASE_URL contains the URL your app uses to access the database. DATABASE_URL包含您的应用程序用来访问数据库的 URL。 If your app already has a Heroku Postgres database and you've provisioned another one, this config var's name instead has the format HEROKU_POSTGRESQL_<COLOR>_URL (for example, HEROKU_POSTGRESQL_YELLOW_URL如果您的应用程序已经有一个 Heroku Postgres 数据库并且您已经配置了另一个数据库,则此配置变量的名称的格式HEROKU_POSTGRESQL_<COLOR>_URL (例如, HEROKU_POSTGRESQL_YELLOW_URL

You can promote your new database to make it the primary database:您可以提升新数据库以使其成为主数据库:

pg:promote updates the value of the DATABASE_URL config var with the newly promoted database's connection string. pg:promote使用新提升的数据库的连接字符串更新DATABASE_URL配置变量的值。 It also creates an alternate attachment for the old primary database, assigned with a new HEROKU_POSTGRESQL_<color>_URL config var.它还为旧的主数据库创建了一个备用附件,分配了一个新的HEROKU_POSTGRESQL_<color>_URL配置变量。 The promotion process triggers a release and restarts the app.升级过程触发发布并重新启动应用程序。

For example:例如:

heroku pg:promote HEROKU_POSTGRESQL_MAUVE_URL -a your-app

You should continue to use the DATABASE_URL environment variable to connect to your database.您应该继续使用DATABASE_URL环境变量来连接到您的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM