Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The lack of DATABASE_URL doesn't stop migrating #1220

Open
akx opened this issue Jul 2, 2024 · 0 comments · May be fixed by #1222
Open

The lack of DATABASE_URL doesn't stop migrating #1220

akx opened this issue Jul 2, 2024 · 0 comments · May be fixed by #1222
Labels
c: bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed p: 1-normal Nothing urgent
Milestone

Comments

@akx
Copy link

akx commented Jul 2, 2024

Describe the bug

Based on #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

if (!cp.host && !cp.port && !cp.database) {
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
@akx akx added the s: pending triage Pending Triage label Jul 2, 2024
@Shinigami92 Shinigami92 added c: bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed p: 1-normal Nothing urgent and removed s: pending triage Pending Triage labels Jul 2, 2024
@Shinigami92 Shinigami92 added this to the vAnytime milestone Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants