【发布时间】:2018-04-22 01:24:50
【问题描述】:
我正在开发一个在 Heroku 上设置的网络应用程序。我希望其他人能够自己使用它,所以我正在尝试创建一个“部署到 Heroku”按钮以包含在我的存储库的自述文件中。
按照 Heroku 的文档1、2,我创建了一个 app.json 文件,其中概述了 Heroku 配置应用程序所需的所有内容。这是我的app.json 文件的样子:
{
"name": "[title]",
"author": "[author]",
"description": "[desc]",
"repository": "[https://github.com/[user]/[repo]",
"logo": "[url]",
"addons": [
"heroku-postgresql:hobby-dev",
"wwwhisper:solo"
],
"scripts": {
"postdeploy": "node server/models/database.js"
},
"env": {
"TZ": "America/Los_Angeles"
}
}
如您所见,postdeploy 脚本应该调用database.js 脚本,如下所示:
const pg = require('pg');
const connectionString = process.env.DATABASE_URL;
const client = new pg.Client(connectionString);
client.connect();
client.query('CREATE TABLE IF NOT EXISTS table_name (id uuid, url VARCHAR(2000), \
title TEXT, description TEXT, been_visited BOOLEAN DEFAULT false, created_at TIMESTAMP DEFAULT NOW())', (err, res) => {
if (err) {
client.end();
return console.error('error with PostgreSQL database', err);
}
});
client.end();
我知道查询在本地测试时有效,但是当我使用上述app.json 测试按钮时,我仍然收到错误error: relation "tanabata_tree" does not exist - 表示从未创建过表。
我在哪里/我做错了什么?
1:https://devcenter.heroku.com/articles/heroku-button https://devcenter.heroku.com/articles/heroku-button
【问题讨论】:
标签: node.js postgresql express heroku heroku-postgres