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

What environment variables should we use for database configuration? #2400

Closed
ri8ika opened this issue Feb 14, 2019 · 9 comments
Closed

What environment variables should we use for database configuration? #2400

ri8ika opened this issue Feb 14, 2019 · 9 comments
Assignees

Comments

@ri8ika
Copy link

ri8ika commented Feb 14, 2019

After following medium blog, I set the following variables:

DATABASE_URL
DB_DATABASE
DB_HOST
DB_PASSWORD
DB_PORT
DB_USER

But this is not working.

After some research I found this issue:

strongloop/loopback-boot#4

But I am still not sure what database environment variables are available to use in loopback 4.


For further information, I have used the followings inside application.ts inside the constructor:

this.bind('datasources.config.db').to({
      name: 'postgres',
      connector: 'postgres',
      hostname: process.env.DB_HOST,
      port: process.env.DB_PORT,
      user: process.env.DB_USER,
      password: process.env.DB_PASSWORD,
      database: process.env.DB_DATABASE,
    });
    this.bind('datasources.db').toClass(PostgresDataSource);

I think this is not getting bound, because when try to run migrate on heroku, I get the following error:

Connection fails: Error: connect ECONNREFUSED 127.0.0.1:5432
@dhmlau
Copy link
Member

dhmlau commented Feb 14, 2019

@ri8ika , I think the error occurred because the IP is not correct. I haven't tried it on Heroku but I think you need to modify the index.js. Please see https://loopback.io/doc/en/lb4/deploying_to_ibm_cloud_kubernetes.html#step-2-modify-deploy-testindexjs.

@dhmlau dhmlau transferred this issue from loopbackio/loopback.io Feb 14, 2019
@dhmlau
Copy link
Member

dhmlau commented Feb 14, 2019

I'm transferring your issue to loopback-next repo. That's where it should be anyway.

@dhmlau
Copy link
Member

dhmlau commented Feb 14, 2019

You might also wanna see:
#2176

Hope it helps.

@dhmlau dhmlau self-assigned this Feb 15, 2019
@ri8ika
Copy link
Author

ri8ika commented Feb 15, 2019

Hmm, I'm still getting the error even after using Procfile to run index.js when I try to migrate:

Error: connect ECONNREFUSED 127.0.0.1:5432

I also tried setting up url which was missing, but it still didn't help me.

@dhmlau
Copy link
Member

dhmlau commented Feb 15, 2019

Sorry, i misunderstood your issue and it's actually complaining about cannot connect to the Postgresql. Looking at the code snippet in the original comment, should hostname be host instead? It's because in the datasource.json, it's in the form of:

{
  "name": "ds",
  "connector": "postgresql",
  "url": "",
  "host": "localhost", <---- HERE
  "port": 5432,
  "user": "root",
  "password": "pass",
  "database": "testdb"
}

@ri8ika
Copy link
Author

ri8ika commented Feb 15, 2019

Good catch. But I'm still having same issue.

@dhmlau
Copy link
Member

dhmlau commented Feb 16, 2019

@ri8ika, one last thing I can think of. In this tutorial https://loopback.io/doc/en/lb4/Deploying-to-IBM-Cloud.html#updating-application, it binds the new value in src/index.ts:

app.bind('datasources.config.db').to(updatedDatasourceDb);

I'm not sure what's the difference between setting it here vs in application.ts, perhaps @hacksparrow might be able to answer.
There are users in the above mentioned issue who were able to deploy to Heroku, they might have some more insight.

@ri8ika
Copy link
Author

ri8ika commented Feb 16, 2019

Still no luck.

@dhmlau
Copy link
Member

dhmlau commented Aug 24, 2020

@ri8ika, I wasn't able to reproduce this issue. Since this issue was opened more than a year ago, I'd like to close this issue as non-reproducible. If you still encounter this issue, please feel free to ping here or open a new issue. Thanks.

@dhmlau dhmlau closed this as completed Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants