Tag: heroku postgres

如何利用Heroku的“postdeploy”脚本在预置的Heroku PostgreSQL数据库中创build表?

我正在Heroku上设置一个Web应用程序。 我希望别人能够自己使用它,所以我试图创build一个“部署到Heroku”button,以包含在我的存储库的自述文件。 跟着Heroku的文档1,2 ,我创build了一个app.json文件,概述了Herokuconfiguration应用程序所需的所有内容。 这是我的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 […]

用于在KNEX / BookshelfJS中定义“池”的语法

首先,我对这里的所有东西都很陌生…而且对于StackOverflow来说是新的东西,所以提前做个新手道歉,我已经准备好迎接我的颠簸了… LOL。 我们使用Heroku.addon作为Postgres,并利用/引用全局环境variables来访问正确的数据库。 我们的应用程序根目录中有一个config.js文件,如下所示: db: process.env.DB_URL || { client: 'pg', connection: { database: 'db_name', user: 'user_name' } }, 在这里有人能够引导我如何将初始化“自定义池”信息的代码集成到此设置中,如[ http://knexjs.org/#Installation-pooling] [ http://knexjs.org/#Installation-pooling] /#安装-池] var knex = require('knex')({ client: 'mysql', connection: { host : '127.0.0.1', user : 'your_database_user', password : 'your_database_password', database : 'myapp_test' }, pool: { min: 0, max: 7 } }); 在Heroku上,process.env.DB_URL是一个复杂的URL,类似于: postgres://(redacted)@ec5-87-1-47-54.compute-1.amazonaws.com:5432/d8n2e9ebd0q9it 所以,我希望有一个干净的方式来传递'自定义池'的信息,以及在这里或另一个文件/位置。 […]

看到错误模块未find:“pg-native”在heroku应用程序

我正在尝试使用postgres插件和一个也在使用react的heroku节点应用程序。 我正在使用这个反应buildpack支持heroku中的反应: https : //github.com/opike/create-react-app-buildpack.git 当我尝试添加该行时: var pg = require('pg'); 当我尝试在本地运行heroku应用程序时出现以下编译错误: >heroku local web [OKAY] Loaded ENV .env File as KEY=VALUE Format [WARN] ENOENT: no such file or directory, open 'Procfile' [OKAY] package.json file found – trying 'npm start' 4:15:19 PM web.1 | > test-app@0.1.0 start /Users/oliverpike/dev/heroku/ofp-react 4:15:19 PM web.1 | > react-scripts start 4:15:20 […]

如何连接postgres数据库与Auth0

当我连接Heroku postgres数据库与Auth0然后我得到以下错误。 could not connect to postgres db { [error: no pg_hba.conf entry for host "XXXXXXXX", user "XXXXXX", database "XXXXXX", SSL off] name: 'error', length: 161, severity: 'FATAL', code: '28000', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'auth.c', line: […]

Node.js和postgres LISTEN

我想使用Heroku,PostgreSQL和Node.js,并设置它,以便随时在我的postgres数据库中添加loggingNode.js将该行的内容打印到控制台。 我试图按照这些指示设置它: http://lheurt.blogspot.com/2011/11/listen-to-postgresql-inserts-with.html http://bjorngylling.com/2011-04-13/postgres-listen-notify-with-node-js.html 这里是node.js代码 var pg = require('pg'); conString = '/*my database connection*/'; var client = new pg.Client(conString); client.connect(function(err) { if(err) { return console.error('could not connect to postgres', err); } client.connect(); client.query('LISTEN "loc_update"'); client.on('notification', function(data) { console.log(data.payload); }); }); 这是在postgres数据库上执行的function String function = "CREATE FUNCTION notify_trigger() RETURNS trigger AS $$ " + "DECLARE " […]

摩卡+ Nodejs + Heroku .env文件

我在Heroku上运行的NodeJS上有一个REST应用程序。 我有我的.env文件设置为本地开发和工作正常,每当我运行领class在本地服务我的应用程序。 当我将它部署到我的heroku服务器时,该应用程序也运行良好。 我正在尝试使用Mocha / Supertest / should / assert为我的应用编写unit testing。 当我通过Mocha运行我的应用程序时,它不会加载.env文件来获取我的环境variables – 在我的情况下是PSQL数据库的URL。 因此,我所有涉及数据库I / O超时的testing。 我一直在互联网search解决scheme,但我似乎无法find有用的东西。 这是一些示例代码: app.js: var application_root = __dirname, express = require("express"), port = process.env.PORT || 4482; pg = require('pg').native, client = new pg.Client(process.env.DATABASE_URL); // Connect To DB client.connect(); (…) app.get('/api', function (req, res) { res.send('PS API is running'); }); […]

无法从本地节点应用程序以sequelize连接到heroku postgresql数据库

我试图从Sequelize的本地nodejs应用程序连接到Heroku postgresql数据库。 我遵循这两个指南,一切都在英雄服务器端的工作完全正常,但我的节点应用程序将不会连接到heroku当我在我的Mac本地运行它。 http://sequelizejs.com/articles/heroku https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku 以下是我如何启动本地应用程序: DATABASE_URL=$(heroku config:get DATABASE_URL) nodemon 得到我: Sequelize: Unable to connect to the database: 但是我通过这样做得到正确的URL: echo $(heroku config:get DATABASE_URL) 这些命令工作正常: heroku pg:psql psql $(heroku config:get DATABASE_URL) 这是我的nodejs代码: var match = process.env.DATABASE_URL.match(/postgres:\/\/([^:]+):([^@]+)@([^:]+):(\d+)\/(.+)/) sequelize = new Sequelize(match[5], match[1], match[2], { dialect: 'postgres', protocol: 'postgres', port: match[4], host: match[3], logging: false }) sequelize .authenticate() […]