Skip to content

Commit 586a8e2

Browse files
committed
add GCLOUD_SQL_INSTANCE option while still using postgres url
1 parent 3965925 commit 586a8e2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

datastore.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ func getDBConnection(store *Datastore) *runner.DB {
171171
host, port, _ := net.SplitHostPort(u.Host)
172172
dbName := strings.Replace(u.Path, "/", "", 1)
173173

174+
if host == "GCLOUD_SQL_INSTANCE" {
175+
// USE THE GCLOUD_SQL_INSTANCE SETTING instead... e.g. host= /cloudsql/INSTANCE_CONNECTION_NAME // JC I wonder if it is always /cloudsql
176+
host = store.Settings.Get("GCLOUD_SQL_INSTANCE")
177+
}
178+
179+
store.Logger.Info("dbname=" + dbName + " user=" + username + " host=" + host + " port=" + port + " sslmode=disable") // no pass
180+
174181
db, _ := sql.Open("postgres", "dbname="+dbName+" user="+username+" password="+pass+" host="+host+" port="+port+" sslmode=disable")
175182
err = db.Ping()
176183
if err != nil {

0 commit comments

Comments
 (0)