jackc / tern

The SQL Fan's Migrator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

port ignored in tern.conf

sobafuchs opened this issue · comments

System: macOS Monterey version 12.4
tern version: 1.13.0

I'm currently facing a weird issue where port is being ignored in tern.conf. I specified it to be 9200 and tern still uses 5432. I have a docker-compose file that looks like this:

version: "3"
services:
  db:
    container_name: postgres
    restart: always
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: tern_test
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "9200:5432"
volumes:
  postgres_data:

I started this up in a separate terminal with docker-compose up, I can confirm the pg server is up and running and listening for connections. I then have the following tern.conf:

[database]
host = 127.0.0.1
port = 9200
database = tern_test
user = postgres
password = {{env "MIGRATOR_PASSWORD"}}
sslmode = prefer

When I run tern with MIGRATOR_PASSWORD=postgres tern migrate, I get the following error:

Unable to connect to PostgreSQL:
  failed to connect to `host=127.0.0.1 user=postgres database=tern_test`: dial error (dial tcp 127.0.0.1:5432: connect: connection refused)

If I change my docker-compose.yml to expose it on local port 5432, it works of course. I've also tried other ports and it only uses 5432. I'm using macOS Monterey version 12.4 (I saw another issue here specific to Windows, not sure if the OS is even relevant here).

I'm on MacOS Monterey 12.4 as well, but I am unable to reproduce the issue. I'm not using docker though. Just tern and PostgreSQL on the same machine.

Does it work if you pass port as a CLI option? What about the other settings in tern.conf? Are they definitely being read? The config file is optional so maybe it isn't being read at all.


Maybe related to #38.

It has the same issue if I pass it in as a CLI option:

~/projects/code/personal/tern-issue $ tern migrate --database tern_test --port 9200 --user postgres --password postgres --host 127.0.0.1

Unable to connect to PostgreSQL:
  failed to connect to `host=127.0.0.1 user=postgres database=tern_test`: dial error (dial tcp 127.0.0.1:5432: connect: connection refused)

Looks like the other options do get read, just not the port.

If I just use the pure config file, the other options definitely do get read. For instance, if you check the original error message in the issue, it is using the correct database name.

I was able to reproduce on Ubuntu as well. Here's the output from uname -a:

Linux 5.4.0-122-generic #138-Ubuntu SMP Wed Jun 22 15:00:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Definitely don't think this is OS-related. Whether or not postgres is containerized or not shouldn't be relevant though no? Does tern do some type of port scanning before using a port?

I can confirm tern uses the correct port if I remove my tern.conf file (as in delete it entirely) and pass all the options to the CLI. If the tern.conf file exists and I pass the options through the CLI, it uses the wrong port

I'm at a bit of a loss as to what could be happening. Could you step through in a debugger? Maybe something would become apparent then.

I had the same issue, workaround for me was specifying conn_string instead of all the other fields. I may look at it later and see if I can debug the issue.

Still unable to reproduce. I'm using the latest v2-dev.

I can replicate this behavior. Tern always uses 5432 regardless of what port is present in the config file, even deleting the port value from the config file and passing by flag does not work. Deleting the entire config file and passing all values by flag makes it work.