Search code examples
google-cloud-sqltypeorm

Typical ormconfig.json file for Google Cloud SQL?


I have been trying for hours. What should be the ormconfig.json file for Google Cloud SQL working with TypeORM? I managed to get it working with the IP of the DB locally (with mysql workbench and Google cloud proxy and whitelisting my ip) but I don't know what the connection details should be for app engine.

{
  "name": "default",
  "type": "mysql",
  "host": "/cloudsql/[project:region:instance]",
  "port": "3306",
  "username": "root",
  "password": "xxxx",
  "database": "yyy",
  "synchronize": true,
  "logging": false,
  "entities": [
    "modules/**/*.entity.js"
  ]
}

or

{
  "name": "default",
  "type": "mysql",
  "extra": {
    "socketPath": "/cloudsql/[project:region:instance]"
  },
  "username": "root",
  "password": "xxxx",
  "database": "yyy",
  "synchronize": true,
  "logging": false,
  "entities": [
    "modules/**/*.entity.js"
  ]
}

or anything else?

Thanks a lot!


Solution

  • For those interested, here is the solution:

    {
      "name": "default",
      "type": "mysql",
      "extra": {
        "socketPath": "/cloudsql/[project:region:instance]"
      },
      "username": "root",
      "password": "xxxx",
      "database": "yyy",
      "synchronize": true,
      "logging": false,
      "entities": [
        "dist/**/*.entity.js"
      ]
    }
    

    Note that I also changed the entities path