db-migrate/node-db-migrate

Migrations not executed with Node 18, stuck on connecting

tomiadebanjo opened this issue · 13 comments

I'm submitting a...

  • Bug report
  • Feature request
  • Question

Current behavior

After upgrading to Node 18, db-migrate does not execute the migrations but exits silently without any error message.

We are using a PostgreSQL db. db-migrate seems to try connect, but no matter if the database is running or not, the process exists without any notice.

After going back to Node v16 everything works again as expected.

Expected behavior

Migrations should run

Minimal reproduction of the problem with instructions


      const dbmigrate = DBMigrate.getInstance(true, {
        config: {
          'heroku-ssl': {
            url: databaseUrl,
            addIfNotExists: {
              native: true,
              sslmode: 'require',
              rejectUnauthorized: false,
            },
            overwrite: {
              native: true,
              sslmode: 'require',
              rejectUnauthorized: false,
            },
          }
        },
        cmdOptions: {
          table: 'schema_migrations',
          'migrations-dir': migrationsDirPath,
          verbose: true,
        },
      });
     dbmigrate.up()

What is the motivation / use case for changing the behavior?

Environment



db-migrate version: 0.11.11
db-migrate-pg: 1.2.1
Database version: PostgreSQL 14.7

Additional information:
- Node version: 18.15.0
- Platform:  Heroku

Others:

Runs locally on Node18, but fails to run in a node docker container - node:18.15.0-alpine3.16

Similar to these previous issues - #692 and #709

@wzrdtales Can you have a look?

not enough information.

include verbose run
include database version

only common information i can share:

remove native: true, it doesn't work properly with node 18 anymore, also the issues are mostly appearing together with SSL. See brianc/node-libpq#94

if you're using ssl auth, this might be your issue. i just ported from the cockroachdb driver the SSL handling over to the pg driver version v1.2.3. It accepts and uses the same params which are used with the native pg lib.

Example

{
  "dev": {
    "user": {"ENV": "user"},
    "driver": "pg",
    "database": {"ENV": "database"},
    "native": true,
    "host": { "ENV": "host" },
    "port": 26257,
    "ssl": {
      "sslrootcert": { "ENV": "ca_crt" },
      "sslcert": { "ENV": "ssl_cert" },
      "sslkey": { "ENV": "ssl_key" },
      "sslmode": { "ENV": "ssl_mode" }
    }
  }
}

@wzrdtales
Database version - PostgreSQL 14.7
Logs for a verbose run with the native config removed


[INFO] require: db-migrate-pg
[INFO] connecting
[INFO] connected
[SQL] show server_version_num
"message":"Migration Failed: no pg_hba.conf entry for host \"*\", user \"*******\", database \"********\", no encryption"

Logs for a verbose run with the native config


[INFO] require: db-migrate-pg
[INFO] connecting
Segmentation fault

It runs locally on Node18 but fails to run in a node docker container - node:18.15.0-alpine3.16.
Any thoughts on how to get other logs about the segmentation fault or the library errors?

these are not verbose logs. verbose logs contain more information. do not strip information away... .

anyhow the segmentation fault on node 18 is expected with native. so stop using it. I can't do anything about it, this is the fault of brianc/node-libpq#94 . So you will have to ask there for a fix.

the latest pg driver and cockroachdb driver do have a config parser for the SSL parameters to work with the non native version, that is what we are using since this broke (we use the cockroachdb driver).

and btw. it runs locally only b/c of some special constraints then in your setup. The whole issue is about openssl being upgraded to version 3.

Okay, thanks. I'll check my setup to try to find the special constraints. Heroku only provides a DB connection string. We don't have the SSL parameters for the non-native mode.

end of story is, find out how to run it without the native mode. If there are issues with the non native mode and you provide me with the information what exactly doesn't work, I can look what can be done.

and that you don't have ssl params is wrong.

sslmode: 'require',

in your example it is there. I suggest just install the latest db-migrate-pg driver and just try with native disabled, it may just work

Using the latest db-migrate-pg driver fixed the issue.