The lack of `DATABASE_URL` doesn't stop migrating
Describe the bug
Based on https://github.com/salsita/node-pg-migrate/pull/319, node-pg-migrate should refuse to try and migrate if DATABASE_URL is not set.
However, even in an environment where there's absolutely nothing postgres-related, those checks aren't triggered, likely because pg synthesizes some default connection parameters – e.g. on my local laptop,
ConnectionParameters {
user: 'akx',
database: 'akx',
port: 5432,
host: 'localhost',
...
or in a Docker container therein, as root,
ConnectionParameters {
user: undefined,
database: undefined,
port: 5432,
host: 'localhost',
Since port and host are set, the check https://github.com/salsita/node-pg-migrate/blob/9d23d3f872d11bf331cc318b6fca3b8e8baef739/bin/node-pg-migrate.ts#L493 doesn't trigger, and even when DATABASE_URL is actually unset, migrations happen... and in my case, I got a bunch of stuff written into my default user database.
Steps to reproduce
Simplest repro in a Docker container with nothing Postgres-related:
~ $ docker run -it node:20 bash
root@ff18a4b83f32:/# cd $(mktemp -d)
root@ff18a4b83f32:/tmp/tmp.ENBeuN5UYe# npm i node-pg-migrate
added 31 packages in 1s
root@ff18a4b83f32:/tmp/tmp.ENBeuN5UYe# ./node_modules/.bin/node-pg-migrate up
could not connect to postgres: Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432
}
Logs
No response
System Info
Irrelevant, but this is for the Docker container above:
root@ff18a4b83f32:/tmp/tmp.ENBeuN5UYe# npx envinfo --system --npmPackages 'node-pg-migrate' --binaries
System:
OS: Linux 6.6 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (12) arm64 unknown
Memory: 7.06 GB / 7.66 GB
Container: Yes
Shell: 5.2.15 - /bin/bash
Binaries:
Node: 20.11.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.4 - /usr/local/bin/npm
npmPackages:
node-pg-migrate: ^7.5.2 => 7.5.2
### Used Module System
esm