Unable to connect to Cloud SQL (PostgreSQL) instance using Sequelize #17102
-
I've been trying to run migration scripts and therefore connect to the Cloud SQL instance. However, already sitting here for almost two days trying to make this work I'm running out of ideas on how to diagnose the problem. For starters, I am able to connect to my instance from my local machine without problems: $ gcloud sql connect my-project-postgres-dev --user=postgres Sequelize ConfigInspired by this example, this is how I am preparing the configuration for Sequelize in the development-environment: // File: config.js
const dotenv = require('dotenv');
const { Connector, IpAddressTypes, AuthTypes } = require('@google-cloud/cloud-sql-connector');
dotenv.config();
let dbConfig;
if (ENVIRONMENT === 'development') {
const connector = new Connector();
const clientOpts = connector.getOptions({
instanceConnectionName: process.env.CLOUD_SQL_INSTANCE,
ipType: IpAddressTypes.PUBLIC,
authType: process.env.DB_PASSWORD ? AuthTypes.PASSWORD : AuthTypes.IAM,
});
dbConfig = {
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
dialect: process.env.DB_DIALECT,
dialectOptions: clientOpts,
};
} else { /* brevity */ }
console.log(`[config.js] config`, dbConfig);
module.exports = dbConfig; For the $ GOOGLE_APPLICATION_CREDENTIALS=sa-cred.json sequelize-cli db:migrate The [config.js] config {
username: 'postgres',
password: 'password',
host: '12.34.56.78',
database: 'projectdb-dev',
dialect: 'postgres',
dialectOptions: Promise { <pending> }
} However, nothing will happen as I'll just get a timout error:
I've also tried this using # Step to install dependencies
- name: 'gcr.io/cloud-builders/npm'
args: [ 'install' ]
# Step to apply Sequelize migrations
- name: 'gcr.io/cloud-builders/npm'
entrypoint: 'bash'
args:
- '-c'
- GOOGLE_APPLICATION_CREDENTIALS=$_GOOGLE_APPLICATION_CREDENTIALS npm run db:migrate The result is the same. I'd just get a timeout. It's not clear to me whether this is an issue with Sequelize or whether I am doing something wrong here. Can somebody configm that Cloud SQL should work? If so: What am I missing here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Your call to |
Beta Was this translation helpful? Give feedback.
Then your best bet will be to use ESM, otherwise you would have to set up a messy setup to achieve async initialization.
This gist explains how to configure a TS project to use ESM
Once you've done that, you can simply use
await
, as top-level-await will be available