1

I'm trying to get sequelize going on GAE. But am struggling with the cloud SQL proxy that uses sockets on non-standard paths.

My understanding is that a url would get passed direct to the pg library, and based on this post, it would suggest the below string is what I need

I've setup the db configuration to be

{
  url: 'postgresql:///db_user:db_password@/db_name?host=./cloudsql/my-project-1234:us-central1:my-cloud-sql-instance', 
  dialect: 'postgres'
}

However, if I run ./node_modules/.bin/sequelize db:migrate I end up with the error:

ERROR: database "db_user:db_password@/db_name" does not exist
ChrisJ
  • 2,486
  • 21
  • 40

1 Answers1

2

After a lot of trial and error, it is possible to pass the socket path using the host variable, but there are a few gotcha's:

  1. The path must be absolute, that is, it must start with a / (otherwise it assumes it is a hostname)
  2. The socket path must be 108 characters or less on a Linux-based operating system. If I placed the socket in a subfolder with my project (which was in my home directory), I got ENOENT (file not found), but moving the sockets to /cloudsql in the root path fixed it.
  3. It will assume that path is the directory and append /.s.PGSQL.5432 to that (which is fine because Google's SQL proxy socket is in that file)

So with the following config, I was able to run a database migration through google's cloud SQL proxy:

{
    username: 'my_user',
    password: 'my_password',
    database: 'my_database',
    host: `/cloudsql/my-app-12345:us-central1:my_database`,
    logging: false,
    dialect: 'postgres',
    // Google cloud_sql_proxy is encrypted, so no need to encrypt
    ssl: false,
    dialectOptions: {
        ssl: false,
    },
    operatorsAliases: false,
}
Craig Finch
  • 978
  • 7
  • 21
ChrisJ
  • 2,486
  • 21
  • 40
  • spent a hell lot of time trying to figure this out! And in the end I found your Github issue and this SO post... I also came to the same solution... hope I would have seen this earlier ;P would have saved me a lot of time and trouble.... Thank you! – riyaz-ali Aug 20 '18 at 15:31
  • Thank you for this! Worked when I deployed – Kim Merino Apr 18 '19 at 23:53