mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
fix(postgres): connect over a Unix socket
TREK_DB_URL could not name a Unix socket. MikroORM builds the pool from the URL's own host and drops a host parameter, so postgresql://trek@localhost/trek?host=/var/run/postgresql connected to localhost over TCP. A percent-encoded socket path as the host reached the pool, but the client tools got it undecoded in PGHOST, so backups, restores and the safety copy before a migration failed. The server address is now read once, the way libpq reads a connection URL: a host or port parameter takes the place of the URL's own, and a host written into the URL is percent-decoded. The pool and the client tools both get that address. The wiki and .env.example show the socket form.
This commit is contained in:
@@ -28,6 +28,8 @@ describe('resolveEngine', () => {
|
||||
expect(engine.ormOptions()).toEqual({
|
||||
driver: TrekPostgreSqlDriver,
|
||||
clientUrl: PG_URL,
|
||||
host: 'db.example',
|
||||
port: 5432,
|
||||
pool: { min: 0, max: 7 },
|
||||
driverOptions: {},
|
||||
// Puts pg_temp last on every new connection's search_path (session-search-path.ts).
|
||||
@@ -35,6 +37,17 @@ describe('resolveEngine', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('ENGINE-004: a Unix socket reaches the pool, as a host parameter or as a percent-encoded host', () => {
|
||||
const viaParam = resolveEngine(
|
||||
deriveDb({ TREK_DB_URL: 'postgresql://trek:s3cret@localhost/trek?host=/var/run/postgresql' }),
|
||||
).ormOptions();
|
||||
expect(viaParam).toMatchObject({ host: '/var/run/postgresql', port: undefined });
|
||||
const encoded = resolveEngine(
|
||||
deriveDb({ TREK_DB_URL: 'postgresql://trek:s3cret@%2Fvar%2Frun%2Fpostgresql:5433/trek' }),
|
||||
).ormOptions();
|
||||
expect(encoded).toMatchObject({ host: '/var/run/postgresql', port: 5433 });
|
||||
});
|
||||
|
||||
it('ENGINE-003: describes a Postgres database without its password', () => {
|
||||
const engine = resolveEngine(deriveDb({ TREK_DB_URL: `${PG_URL}?sslmode=require&password=other` }));
|
||||
expect(engine.describe()).toBe('Postgres postgresql://trek:***@db.example:5432/trek');
|
||||
|
||||
Reference in New Issue
Block a user