【问题标题】:How do I configure heroku psql database using .sh files?如何使用 .sh 文件配置 heroku psql 数据库?
【发布时间】:2019-12-01 20:14:56
【问题描述】:

我有一个托管在 heroku 上的网络应用程序,我正在尝试使用我在离线测试中使用的相同脚本来设置我的数据库,但在 heroku 上我不确定如何运行我的 .sh 脚本:

dropdb -U node_user mydb
createdb -U node_user mydb

psql -U node_user mydb < ./bin/sql/firsttable.sql
psql -U node_user mydb < ./bin/sql/secondtable.sql
psql -U node_user mydb < ./bin/sql/thridtable.sql

每个 .sql 文件都包含 sql 命令,例如:

CREATE TABLE firsttable(
    id SERIAL PRIMARY KEY,
    title VARCHAR(64),
    user VARCHAR(64),
    date TIMESTAMP
);

如何在 heroku 的 psql 上运行我的 .sh 脚本,以便创建所有表?

【问题讨论】:

    标签: node.js heroku psql heroku-postgres


    【解决方案1】:

    通过连接到 Heroku 上的数据库,使用本地 psql 从您的计算机上运行它们。

    为此,您只需要凭证即可:

    $ heroku pg:credentials:url
    

    请注意,您将无法使用 dropdbcreatedb 在 Heroku 上删除和创建数据库。

    对于 SQL 文件,您可以按如下方式运行它们:

    $ psql $(heroku pg:credentials:url | grep 'postgres://') -f local_file.sql
    

    【讨论】:

    • ...但您将无法使用dropdbcreatedb。如果需要,请改用heroku pg:reset
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多