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

Error when trying to connect to a local postgresql instance over UNIX domain socket #8157

Closed
jc00ke opened this issue Oct 28, 2024 · 0 comments · Fixed by #8159
Closed

Error when trying to connect to a local postgresql instance over UNIX domain socket #8157

jc00ke opened this issue Oct 28, 2024 · 0 comments · Fixed by #8159

Comments

@jc00ke
Copy link
Contributor

jc00ke commented Oct 28, 2024

Postgres supports connecting over UNIX domain socket. While trying the local setup, I ran into an issue when running npx nx database:reset twenty-server:

> nx run twenty-server:command-no-deps cache:flush

> node dist/src/command/command.js cache:flush

/home/jesse/projects/ratio/twenty/packages/twenty-server/dist/src/utils/assert.js:30
        throw new Error(message);
        ^

Error: An instance of EnvironmentVariables has failed the validation:
 - property PG_DATABASE_URL has failed the following constraints: isUrl 

    at assert (/home/jesse/projects/ratio/twenty/packages/twenty-server/dist/src/utils/
assert.js:30:15)
    at Object.validate (/home/jesse/projects/ratio/twenty/packages/twenty-server/dist/s
rc/engine/core-modules/environment/environment-variables.js:553:24)
    at ConfigModule.forRoot (/home/jesse/projects/ratio/twenty/node_modules/.deno/@nest
[email protected]/node_modules/@nestjs/config/dist/config.module.js:67:45)
    at Object.<anonymous> (/home/jesse/projects/ratio/twenty/packages/twenty-server/dis
t/src/engine/core-modules/environment/environment.module.js:28:34)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:121:18)

Node.js v18.17.1
Warning: command "node dist/src/command/command.js cache:flush" exited with non-zero st
atus code
——————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target command-no-deps for project twenty-server (1s)

      With additional flags:
        cache:flush

   ✖  1/1 failed
   ✔  0/1 succeeded [0 read from cache]

Warning: command "nx command-no-deps -- cache:flush" exited with non-zero status code
——————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target database:reset for project twenty-server and 2 task(s) they depend on 
(1m)

   ✖  1/3 failed
   ✔  2/3 succeeded [2 read from cache]

postgres:///database?host=/path/to/pg/unix/domain/socket/directory fails the isUrl validator.

// Database
@IsDefined()
@IsUrl({
protocols: ['postgres'],
require_tld: false,
allow_underscores: true,
})
PG_DATABASE_URL: string;

If the options are extended with require_host: false then the validation will succeed. Here's a little repro with just validator:

> let url = "postgres:///default?host=/home/jesse/projects/twenty/.direnv/postgres/17";
undefined
> validator.isURL(url, { protocols: ["postgres"], require_tld: false, allow_underscores: true})
false
> validator.isURL(url, { protocols: ["postgres"], require_tld: false, allow_underscores: true, require_host: false })
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

1 participant