将一张桌子推到Heroku

将一张桌子推到Heroku

本文介绍了将一张桌子推到Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 heroku pg:push 命令,该命令会将整个数据库推送到Heroku。

I am aware of the heroku pg:push command which pushes an entire database up to Heroku.

现在,我要发布产品,我希望能够仅向上推一个包含本地收集信息的特定表,而不会覆盖现有表(例如用户)。

Now that I am launching my product, I would like to be able to push up only a specific table that contains information collected locally without overwriting existing tables (such as users).

是否有命令使我只能将特定表推送到heroku?

Is there a command that enables me to only push specific tables to heroku?

推荐答案

我的建议是使用PostgreSQL转储/恢复直接使用和命令。

My suggestion is to use PostgreSQL dump/restore capabilities directly using the pg_dump and psql commands.

使用 pg_dump ,您可以从本地数据库中转储特定表

With pg_dump you can dump a specific table from your local database

$ pg_dump --data-only --table=products sourcedb > products.sql

然后从配置中获取Heroku PostgreSQL连接字符串

Then grab the Heroku PostgreSQL connection string from the configs

$ heroku config | grep HEROKU_POSTGRESQL

# example
# postgres://user3123:[email protected]:6212/db982398

并使用从Heroku中检索到的信息恢复远程数据库中的表。

and restore the table in the remote database, using the information retrieved from Heroku.

$ psql -h ec2-117-21-174-214.compute-1.amazonaws.com -p 6212 -U user3123 db982398 < products.sql

您需要自定义 -p -h -U 参数,以及数据库名称。密码将由 psql 提示。

You will need to customize the -p, -h and -U parameters, as well as the database name. The password will be prompted by psql.

您也可以使用可以过滤转储并恢复表,但是我个人更喜欢 psql

请注意,Heroku建议在一些文档中使用PostgreSQL工具,例如以获取大数据,或者只要提供的CLI命令不能涵盖此类特定情况,问题。

Note that Heroku is recommending the use of PostgreSQL tools in several documentations, such as Importing and Exporting for large data, or whenever the provided CLI commands don't cover specific cases like the one in this question.

这篇关于将一张桌子推到Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:42