Repository: twentyhq/twenty
File: packages/twenty-server/src/engine/twenty-orm/global-workspace-datasource/global-workspace-datasource.service.ts (TypeScript)

Code before:
        url: this.twentyConfigService.get('PG_DATABASE_URL'),
        type: 'postgres',
        logging: this.twentyConfigService.getLoggingConfig(),
        entities: [],
        ssl: this.twentyConfigService.get('PG_SSL_ALLOW_SELF_SIGNED')
          ? {
              rejectUnauthorized: false,
            }
          : undefined,
        poolSize: this.twentyConfigService.get('PG_POOL_MAX_CONNECTIONS'),
        extra: {
          query_timeout: 10000, // 10 seconds,
          idleTimeoutMillis: this.twentyConfigService.get(
            'PG_POOL_IDLE_TIMEOUT_MS',
          ),
          allowExitOnIdle: this.twentyConfigService.get(
            'PG_POOL_ALLOW_EXIT_ON_IDLE',
          ),
        },
      },
      this.workspaceEventEmitter,
    );

    this.globalWorkspaceDataSourceReplica = new GlobalWorkspaceDataSource(
      {
        url: this.twentyConfigService.get('PG_DATABASE_REPLICA_URL'),
        type: 'postgres',
        logging: this.twentyConfigService.getLoggingConfig(),
        entities: [],
        ssl: this.twentyConfigService.get('PG_SSL_ALLOW_SELF_SIGNED')
          ? {
              rejectUnauthorized: false,
            }
          : undefined,
        poolSize: this.twentyConfigService.get('PG_POOL_MAX_CONNECTIONS'),
        extra: {
          query_timeout: 10000, // 10 seconds,
          idleTimeoutMillis: this.twentyConfigService.get(
            'PG_POOL_IDLE_TIMEOUT_MS',
          ),
          allowExitOnIdle: this.twentyConfigService.get(
            'PG_POOL_ALLOW_EXIT_ON_IDLE',
          ),
        },
      },
      this.workspaceEventEmitter,
    );
    await this.globalWorkspaceDataSource.initialize();
    await this.globalWorkspaceDataSourceReplica.initialize();
  }


Review comment (suggestion):
We should fallback to PG_DATABASE_URL if this one is undefined (for self-hoster, we probably won't spawn a replica DB in the image we provide to them)

Code after:
    this.globalWorkspaceDataSource = new GlobalWorkspaceDataSource(
      {
        url: this.twentyConfigService.get('PG_DATABASE_URL'),
        type: 'postgres',
        logging: this.twentyConfigService.getLoggingConfig(),
        entities: [],
        ssl: this.twentyConfigService.get('PG_SSL_ALLOW_SELF_SIGNED')
          ? {
              rejectUnauthorized: false,
            }
          : undefined,
        poolSize: this.twentyConfigService.get('PG_POOL_MAX_CONNECTIONS'),
        extra: {
          query_timeout: this.twentyConfigService.get(
            'PG_DATABASE_PRIMARY_TIMEOUT_MS',
          ),
          idleTimeoutMillis: this.twentyConfigService.get(
            'PG_POOL_IDLE_TIMEOUT_MS',
          ),
          allowExitOnIdle: this.twentyConfigService.get(
            'PG_POOL_ALLOW_EXIT_ON_IDLE',
          ),
        },
      },
      this.workspaceEventEmitter,
    );

    await this.globalWorkspaceDataSource.initialize();

    const shouldInitializeReplicaDataSource = isDefined(
      this.twentyConfigService.get('PG_DATABASE_REPLICA_URL'),
    );

    if (shouldInitializeReplicaDataSource) {
      this.globalWorkspaceDataSourceReplica = new GlobalWorkspaceDataSource(
        {
          url: this.twentyConfigService.get('PG_DATABASE_REPLICA_URL'),
          type: 'postgres',
          logging: this.twentyConfigService.getLoggingConfig(),
          entities: [],
          ssl: this.twentyConfigService.get('PG_SSL_ALLOW_SELF_SIGNED')
            ? {
                rejectUnauthorized: false,
              }
            : undefined,
          poolSize: this.twentyConfigService.get('PG_POOL_MAX_CONNECTIONS'),
          extra: {
            query_timeout: this.twentyConfigService.get(
              'PG_DATABASE_REPLICA_TIMEOUT_MS',
            ),
            idleTimeoutMillis: this.twentyConfigService.get(