1

Well, when I enter heroku bash and try to run npx typeorm migration:run it just throws me an error: enter image description here

What's weird is that locally it works when the DATABASE is on localhost like this in .env file: DATABASE_URL=postgres://postgres:docker@localhost:5432/gittin

This is my ormconfig.js:

module.exports = {
    "type": "postgres",
    "url": process.env.DATABASE_URL,
    "entities": ["dist/entities/*.js"],
    "cli": {
        "migrationsDir": "src/database/migrations",
        "entitiesDir": "src/entities"
    }
}

Yes, I added the heroku postgres addon to the app.

PS: If needed, this is the repo of the project: https://github.com/joaocasarin/gittin

João Casarin
  • 674
  • 2
  • 9
  • 27
  • Have you seen [this](https://dba.stackexchange.com/questions/83984/connect-to-postgresql-server-fatal-no-pg-hba-conf-entry-for-host)? – Carlo Corradini Jul 16 '21 at 14:41
  • 1
    I've also found [this](https://help.heroku.com/DR0TTWWD/seeing-fatal-no-pg_hba-conf-entry-errors-in-postgres). I think you have to edit ```ormconfig.js``` and add: ```ssl: process.env.NODE_ENV === 'production'```. This enables *ssl* only if *Node.js* environment is **production** allowing for a secure connection in *Heorku* and also a "non secure" connection for local developement. – Carlo Corradini Jul 16 '21 at 14:48
  • Hi @CarloCorradini , I can't see how the first link can help me, because I'm not finding the conf file, and still, the connection would still request the SSL activated... Regarding your second comment, I tried your way, but as I was researching, the `ssl` field in the ormconfig.js should not be a boolean value, it should be an object like this: https://gist.github.com/joaocasarin/85c29ca545ddc77cafcd8a5aa41af49a – João Casarin Jul 16 '21 at 16:45
  • It works, I've used ```ssl``` in many projects :). For an example take a look [here](https://github.com/GiovanniZotta/fog_cloud_project/blob/main/graphmarket/services/service-products/bootstrap.ts#L18). PS: Have you tried? – Carlo Corradini Jul 16 '21 at 16:54
  • @CarloCorradini yes I did try, here is the new error: https://user-images.githubusercontent.com/48847394/125986054-ac5f51fc-2d23-474c-ba3e-73bbdbe7a197.png – João Casarin Jul 16 '21 at 17:26
  • and the `ormconfig.js`: https://github.com/joaocasarin/gittin/blob/main/ormconfig.js – João Casarin Jul 16 '21 at 17:27
  • UPDATE: using `"ssl": process.env.NODE_ENV === 'production' ? { rejectUnauthorized: false } : false` instead worked. – João Casarin Jul 16 '21 at 17:37
  • [Please don't post screenshots of text](https://meta.stackoverflow.com/a/285557/354577). They can't be searched or copied, or even consumed by users of adaptive technologies like screen readers. Instead, paste the code as text directly into your question. If you select it and click the `{}` button or Ctrl+K the code block will be indented by four spaces, which will cause it to be rendered as code. – ChrisGPT was on strike Jul 17 '21 at 01:47

1 Answers1

0

As I was discussing with Carlo in the comments, I had to add the ssl property in the ormconfig.js, but not only setting it to true when the environment was production. So according to this, I had to put { rejectUnauthorized: false } when production mode, and just false when not.

So the ormconfig.js is like this right now:

module.exports = {
    "type": "postgres",
    "ssl": process.env.NODE_ENV === 'production' ? { rejectUnauthorized: false } : false,
    "url": process.env.DATABASE_URL,
    "entities": ["dist/entities/*.js"],
    "cli": {
        "migrationsDir": "src/database/migrations",
        "entitiesDir": "src/entities"
    }
}
João Casarin
  • 674
  • 2
  • 9
  • 27