twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
Other
20.14k stars 2.24k forks source link

Error when trying to connect to a remote postgresql instance #6242

Closed ricardotenv closed 4 months ago

ricardotenv commented 4 months ago

I inserted the PostgreSQL connection string instead of the database container URI.

This is an error in the logs of the 'server' container:

server-1  | /app/packages/twenty-server/dist/src/utils/assert.js:27
server-1  |         throw new Error(message);
server-1  |         ^
server-1  | 
server-1  | Error: An instance of EnvironmentVariables has failed the validation:
server-1  |  - property PG_DATABASE_URL has failed the following constraints: isUrl 
server-1  | 
server-1  |     at assert (/app/packages/twenty-server/dist/src/utils/assert.js:27:15)
server-1  |     at Object.validate (/app/packages/twenty-server/dist/src/engine/integrations/environment/environment-variables.js:465:24)
server-1  |     at ConfigModule.forRoot (/app/node_modules/@nestjs/config/dist/config.module.js:67:45)
server-1  |     at Object.<anonymous> (/app/packages/twenty-server/dist/src/engine/integrations/environment/environment.module.js:28:34)
server-1  |     at Module._compile (node:internal/modules/cjs/loader:1256:14)
server-1  |     at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
server-1  |     at Module.load (node:internal/modules/cjs/loader:1119:32)
server-1  |     at Module._load (node:internal/modules/cjs/loader:960:12)
server-1  |     at Module.require (node:internal/modules/cjs/loader:1143:19)
server-1  |     at require (node:internal/modules/cjs/helpers:121:18)
server-1  | 
server-1  | Node.js v18.17.1

I am using a custom docker-compose.yml to use a remote database.

version: "3.9"
name: twenty

services:
  change-vol-ownership:
    image: ubuntu
    user: root
    volumes:
      - server-local-data:/tmp/server-local-data
      - docker-data:/tmp/docker-data
    command: >
      bash -c "
      chown -R 1000:1000 /tmp/server-local-data
      && chown -R 1000:1000 /tmp/docker-data"

  server:
    image: twentycrm/twenty:${TAG}
    volumes:
      - server-local-data:/app/packages/twenty-server/${STORAGE_LOCAL_PATH:-.local-storage}
      - docker-data:/app/docker-data
    ports:
      - "3000:3000"
    environment:
      PORT: 3000
      PG_DATABASE_URL: postgresql://postgres.ijtvlpxvvdamgcbocylg:${POSTGRES_PASSWORD}@aws-0-us-east-1.pooler.supabase.com:6543/postgres
      SERVER_URL: ${SERVER_URL}
      FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
      MESSAGE_QUEUE_TYPE: ${MESSAGE_QUEUE_TYPE}
      ENABLE_DB_MIGRATIONS: "true"
      SIGN_IN_PREFILLED: ${SIGN_IN_PREFILLED}
      STORAGE_TYPE: ${STORAGE_TYPE}
      STORAGE_S3_REGION: ${STORAGE_S3_REGION}
      STORAGE_S3_NAME: ${STORAGE_S3_NAME}
      STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}
      ACCESS_TOKEN_SECRET: ${ACCESS_TOKEN_SECRET}
      LOGIN_TOKEN_SECRET: ${LOGIN_TOKEN_SECRET}
      REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
      FILE_TOKEN_SECRET: ${FILE_TOKEN_SECRET}
    depends_on:
        change-vol-ownership:
          condition: service_completed_successfully

      # db:
      #   condition: service_healthy
    healthcheck:
      test: curl --fail http://localhost:3000/healthz
      interval: 5s
      timeout: 5s
      retries: 10
    restart: always
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.server.rule=Host(`${SERVER_URL}`)"
      - "traefik.http.routers.server.entrypoints=websecure"
      - "traefik.http.routers.server.tls=true"
      - "traefik.http.services.server.loadbalancer.server.port=3000"

  worker:
    image: twentycrm/twenty:${TAG}
    command: ["yarn", "worker:prod"]
    environment:
      PG_DATABASE_URL: postgresql://postgres.ijtvlpxvvdamgcbocylg:${POSTGRES_PASSWORD}@aws-0-us-east-1.pooler.supabase.com:6543/postgres
      SERVER_URL: ${SERVER_URL}
      FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
      MESSAGE_QUEUE_TYPE: ${MESSAGE_QUEUE_TYPE}

      ENABLE_DB_MIGRATIONS: "false" # it already runs on the server

      STORAGE_TYPE: ${STORAGE_TYPE}
      STORAGE_S3_REGION: ${STORAGE_S3_REGION}
      STORAGE_S3_NAME: ${STORAGE_S3_NAME}
      STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}
      ACCESS_TOKEN_SECRET: ${ACCESS_TOKEN_SECRET}
      LOGIN_TOKEN_SECRET: ${LOGIN_TOKEN_SECRET}
      REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
      FILE_TOKEN_SECRET: ${FILE_TOKEN_SECRET}
    depends_on:
      # db:
      #   condition: service_healthy
      server:
        condition: service_healthy
    restart: always

  # db:
  #   image: twentycrm/twenty-postgres:${TAG}
  #   volumes:
  #     - db-data:/bitnami/postgresql
  #   environment:
  #     POSTGRES_PASSWORD: ${POSTGRES_ADMIN_PASSWORD}
  #   healthcheck:
  #     test: pg_isready -U twenty -d default
  #     interval: 5s
  #     timeout: 5s
  #     retries: 10
  #   restart: always

volumes:
  docker-data:
  #db-data:
  server-local-data:

Observations:

greptile-apps[bot] commented 4 months ago

Ensure the PG_DATABASE_URL is correctly formatted and valid. The validation logic is located in /packages/twenty-server/src/engine/integrations/environment/environment-variables.js. The error is thrown in /packages/twenty-server/src/utils/assert.js. Verify the connection string format and update if necessary.

References

/packages/twenty-server/.env.example /packages/twenty-server/.env.test /packages/twenty-server/scripts/render-run.sh

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/twentyhq/twenty/main) · [Edit Issue Bot Settings](https://app.greptile.com/apps/github)
ricardotenv commented 4 months ago

Ensure the PG_DATABASE_URL is correctly formatted and valid. The validation logic is located in /packages/twenty-server/src/engine/integrations/environment/environment-variables.js. The error is thrown in /packages/twenty-server/src/utils/assert.js. Verify the connection string format and update if necessary.

References

/packages/twenty-server/.env.example /packages/twenty-server/.env.test /packages/twenty-server/scripts/render-run.sh

About Greptile

You helped me; the problem was a lack of attention on my part. The protocol is postgres:// and I passed postgresql://.