'Error: Self-signed Certificate' When Running Knex Migrations on Heroku

Viewed 307

Update #1

Unfortunately, I cannot find a screenshot from when I was working on the issue using postgrator. I ended up going with knex to try and connect to heroku instead.

However, when I run 'heroku run npm run migrate' I run into the following issue:

heroku run knex migrate:latest
Running knex migrate:latest on ⬢ stormy-hollows-73700... up, 
run.6282 (Free)
Error: self signed certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1507:34)
at TLSSocket.emit (events.js:376:20)
at TLSSocket._finishInit (_tls_wrap.js:932:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:706:12)

package.json

{
"name": "express-boilerplate",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"migrate": "knex migrate:latest",
"create-migration": "knex migrate:make $1",
"migrate:test": "env NODE_ENV=test npm run migrate",
"seed": "psql -d chirp-app -f seeds/seed.posts.sql; psql -d chirp- 
app -f seeds/seed.replies.sql",
"test": "mocha --require test/setup.js",
"dev": "nodemon src/server.js",
"start": "node src/server.js",
"predeploy": "npm audit",
"deploy": "git push heroku main"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"helmet": "^4.2.0",
"knex": "^0.95.4",
"morgan": "^1.10.0",
"pg": "^8.0.3",
"postgrator-cli": "^3.3.0",
"uuid": "^8.3.2",
"xss": "^1.0.8"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.2.1",
"nodemon": "^2.0.7",
"supertest": "^6.0.1"
} 
}

knexfile.js

`const dotenv = require('dotenv')
dotenv.config()

module.exports = {
client: 'pg',
connection: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false }
};`

knex migration:

`exports.up = function (knex) {
return Promise.all(
[knex.schema.createTable('posts', table => {
table.string('id', 36)
table.string('title', 50)
table.string('content')
}),
knex.schema.createTable('replies', table => {
table.string('id', 36)
table.string('title', 50)
table.string('postid', 36)
})]
)
};

exports.down = function (knex) {
knex.schem.dropTable('posts')
knex.schema.dropTable('replies')
};`

Let me know if I should present this information differently, add or remove files as I am learning how to use this platform. Thanks!

1 Answers

I ended up creating a knex migration and was able to validate my database on heroku.

I did have to make a "seed:live" script that runs seeds using postgres though. ex: "scripts": {..."seed:live": "heroku pg:psql -f seeds/seed.posts.sql; heroku pg:psql -f seeds/seed.replies.sql"...}

to validate seeding the database:

heroku pg:psql -f seeds/seed.posts.sql; heroku pg:psql -f seeds/seed.replies.sql --> Connecting to postgresql-cubed-11974 INSERT 0 3 --> Connecting to postgresql-cubed-11974 INSERT 0 2

but now it works!

Related