jackc / tern

The SQL Fan's Migrator
MIT License
925 stars 68 forks source link

Ignored `port` from config in Windows #38

Open inaneverb opened 2 years ago

inaneverb commented 2 years ago

Windows 11 Pro N, 21H2 Tern: 1.12.5 PostgreSQL 13.4 in Docker for Windows. Docker uses WSL2 as a backend. WSL OS: Fedora Server 34. Port mapping in docker enabled: 5432 container -> 5431 host.

I built two different binaries: for unix:amd/64, windows:amd/64. If I run an unix's binary it's OK. It can connect, do necessary work, etc. If I run window's binary I getting an error "Failed to connect" and I see a default pg port: 5432, not those which is specified in config.


Output:

iyuryevich@ElevenStation ~/Development/___/migrations/ru (master+*?) $ tern.exe status
Unable to connect to PostgreSQL:
  failed to connect to `host=127.0.0.1 user=test1 database=test_dev_01`: dial error (dial tcp 127.0.0.1:5432: connectex: No connection could be made because the target machine actively refused it.)
iyuryevich@ElevenStation ~/Development/___/migrations/ru (master+*?) $ tern status
status:   up to date
version:  4 of 4
host:     127.0.0.1
database: test_dev_01
iyuryevich@ElevenStation ~/Development/___/migrations/ru (master+*?) $ tern.exe version
tern v1.12.5
iyuryevich@ElevenStation ~/Development/___/migrations/ru (master+*?) $ tern version
tern v1.12.5
iyuryevich@ElevenStation ~/Development/___/migrations/ru (master+*?) $

tern.conf

[database]
host = 127.0.0.1
port = 5431
database = test_dev_01
user = test1
password = root
version_table = schema_version
jackc commented 2 years ago

That's very strange. I don't have convenient access to test this on Windows, but I don't see what could be different between *nix and Windows here.

lucasgpalves commented 2 weeks ago

It seems that the problem you are experiencing is due to the port setting in your tern configuration. The error indicates that the connection is trying to use the default port (5432), ignoring the specified port (5431). This can occur for various reasons, including the way environment variables are interpreted or how the connection string is configured.

[database]
user=test1 
password=root
conn_string = host=127.0.0.1 port=5431 dbname=test_dev_01  connect_timeout=10