V
V
Victor Nasonov2020-12-18 15:44:13
Node.js
Victor Nasonov, 2020-12-18 15:44:13

Why does db-migrate throw a self signed certificate error?

I decided to add migrations to my project, I'm trying to use db-migrate configured database.json here is the config:

{
  "prod": {
      "driver": "pg",
      "user": {"ENV": "USER"},
      "password": {"ENV": "PGPASSWORD"},
      "host": {"ENV": "PGHOST"},
      "database": {"ENV": "PGDATABASE"},
      "port": {"ENV": "PGPORT"},
      "ssl": "true",
      "schema": "public"
    },
  "dev": {
    "driver": "pg",
    "user": {"ENV": "USER"},
    "password": {"ENV": "PGPASSWORD"},
    "host": {"ENV": "PGHOST"},
    "database": {"ENV": "PGDATABASE"},
    "port": {"ENV": "PGPORT"},
    "ssl": "true",
    "schema": "public"
  }
}

The database is on the heroku server. It connects to the database without errors via DBeaver.
Created a migration:
'use strict';

var dbm;
var type;
var seed;

/**
  * We receive the dbmigrate dependency from dbmigrate initially.
  * This enables us to not have to rely on NODE_PATH.
  */
exports.setup = function(options, seedLink) {
  dbm = options.dbmigrate;
  type = dbm.dataType;
  seed = seedLink;
};

exports.up = function(db) {
  db.createTable('users', {
    id: { type: 'int', primaryKey: true, autoIncrement: true },
    email: 'string',
    password: 'string',
    confirmed: 'int',
    hash: 'string',
    salt: 'string',
    name: 'string',
    surname: 'string',
    link: 'string',
    hostname: 'string',
    avatar: 'string'
  }, callback);
};

exports.down = function(db) {
  db.dropTable('users', callback);
};

exports._meta = {
  "version": 1
};

I execute db-migrate up, outputs:
C:\Users\kvono\Desktop\project> db-migrate up
[ERROR] AssertionError [ERR_ASSERTION]: ifError got unwanted exception: self signed certificate
at module.exports (C:\Program Files\ nodejs\node_modules\db-migrate\lib\commands\helper\assert.js:9:14)
at C:\Program Files\nodejs\node_modules\db-migrate\lib\commands\up.js:19:14
at C :\Program Files\nodejs\node_modules\db-migrate\connect.js:17:7
at C:\Program Files\nodejs\node_modules\db-migrate\lib\driver\index.js:95:9
at Client._connectionCallback (C:\Users\kvono\Desktop\project\node_modules\db-migrate-pg\index.js:710:7)
at Client._handleErrorWhileConnecting (C:\Users\kvono\Desktop\project\node_modules\pg\lib\ client.js:305:19)
at Client._handleErrorEvent (C:\Users\kvono\Desktop\project\node_modules\pg\lib\client.js:315:19)
at Connection.emit (node:events:376:20)
at TLSSocket.reportStreamError (C: \Users\kvono\Desktop\project\node_modules\pg\lib\connection.js:53:12)
at TLSSocket.onConnectSecure (node:_tls_wrap:1498:34)
at TLSSocket.emit (node:events:376:20)
at TLSSocket._finishInit (node:_tls_wrap:933:8)
at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:707:12)
Why is db-migrate throwing a self signed certificate error? How to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Nasonov, 2020-12-18
@kvonosan

I installed knex, here is my config with which the connection worked (knexfile.js):

require('dotenv').config()

module.exports = {

  development: {
    client: 'postgresql',
    connection: {
      database: process.env.PGDATABASE,
      user:     process.env.PGUSER,
      password: process.env.PGPASSWORD,
      ssl: { rejectUnauthorized: false }
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    }
  },

  staging: {
    client: 'postgresql',
    connection: {
      database: process.env.PGDATABASE,
      user:     process.env.PGUSER,
      password: process.env.PGPASSWORD,
      ssl: { rejectUnauthorized: false }
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    }
  },

  production: {
    client: 'postgresql',
    connection: {
      database: process.env.PGDATABASE,
      user:     process.env.PGUSER,
      password: process.env.PGPASSWORD,
      ssl: { rejectUnauthorized: false }
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    }
  }

};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question