From 107725b09ea571696c77abb27319a0b42234483d Mon Sep 17 00:00:00 2001 From: Christoph Etzel Date: Tue, 19 Mar 2024 11:10:07 +0100 Subject: [PATCH 1/4] use custom network for local database --- internal/gen/types/typescript/typescript.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/gen/types/typescript/typescript.go b/internal/gen/types/typescript/typescript.go index b979992d2..08f649dd9 100644 --- a/internal/gen/types/typescript/typescript.go +++ b/internal/gen/types/typescript/typescript.go @@ -39,6 +39,7 @@ func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas return nil } + networkID := "host" if utils.IsLocalDatabase(dbConfig) { if err := utils.AssertSupabaseDbIsRunning(); err != nil { return err @@ -47,6 +48,9 @@ func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas if strings.Contains(utils.Config.Api.Image, "v9") { postgrestV9Compat = true } + + // Use custom network when connecting to local database + networkID = utils.NetId } fmt.Fprintln(os.Stderr, "Connecting to", dbConfig.Host, dbConfig.Port) @@ -75,7 +79,7 @@ func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas Cmd: []string{"node", "dist/server/server.js"}, }, container.HostConfig{ - NetworkMode: container.NetworkMode("host"), + NetworkMode: container.NetworkMode(networkID), }, network.NetworkingConfig{}, "", From 4ead59af63fecc65e8d59c0ae199554efb2e8058 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 20 Mar 2024 14:50:47 +0700 Subject: [PATCH 2/4] Update internal/gen/types/typescript/typescript.go --- internal/gen/types/typescript/typescript.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/gen/types/typescript/typescript.go b/internal/gen/types/typescript/typescript.go index 08f649dd9..5a6a7a2de 100644 --- a/internal/gen/types/typescript/typescript.go +++ b/internal/gen/types/typescript/typescript.go @@ -50,6 +50,8 @@ func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas } // Use custom network when connecting to local database + dbConfig.Host = utils.DbAliases[0] + dbConfig.Port = 5432 networkID = utils.NetId } From bdb7cfac75fed85085674a73629b0fed5612fc1f Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Wed, 20 Mar 2024 15:05:13 +0700 Subject: [PATCH 3/4] fix: save original url --- internal/gen/types/typescript/typescript.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/gen/types/typescript/typescript.go b/internal/gen/types/typescript/typescript.go index 5a6a7a2de..96124b6c3 100644 --- a/internal/gen/types/typescript/typescript.go +++ b/internal/gen/types/typescript/typescript.go @@ -17,6 +17,7 @@ import ( ) func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas []string, postgrestV9Compat bool, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error { + originalURL := utils.ToPostgresURL(dbConfig) // Add default schemas if --schema flag is not specified if len(schemas) == 0 { schemas = utils.RemoveDuplicates(append([]string{"public"}, utils.Config.Api.Schemas...)) @@ -54,14 +55,14 @@ func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas dbConfig.Port = 5432 networkID = utils.NetId } - - fmt.Fprintln(os.Stderr, "Connecting to", dbConfig.Host, dbConfig.Port) // pg-meta does not set username as the default database, ie. postgres if len(dbConfig.Database) == 0 { dbConfig.Database = "postgres" } + + fmt.Fprintln(os.Stderr, "Connecting to", dbConfig.Host, dbConfig.Port) escaped := utils.ToPostgresURL(dbConfig) - if require, err := isRequireSSL(ctx, escaped, options...); err != nil { + if require, err := isRequireSSL(ctx, originalURL, options...); err != nil { return err } else if require { // node-postgres does not support sslmode=prefer From 32575a2220f0ab3dcd1e14568e12b398ee695ee5 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Thu, 21 Mar 2024 09:13:17 +0700 Subject: [PATCH 4/4] chore: update mocks for new pgx --- internal/testing/pgtest/mock.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/testing/pgtest/mock.go b/internal/testing/pgtest/mock.go index eda0376c8..32402db31 100644 --- a/internal/testing/pgtest/mock.go +++ b/internal/testing/pgtest/mock.go @@ -32,11 +32,15 @@ type MockConn struct { func (r *MockConn) getStartupMessage(config *pgx.ConnConfig) []pgmock.Step { var steps []pgmock.Step // Add auth message + params := map[string]string{"user": config.User} + if len(config.Database) > 0 { + params["database"] = config.Database + } steps = append( steps, pgmock.ExpectMessage(&pgproto3.StartupMessage{ ProtocolVersion: pgproto3.ProtocolVersionNumber, - Parameters: map[string]string{"database": config.Database, "user": config.User}, + Parameters: params, }), pgmock.SendMessage(&pgproto3.AuthenticationOk{}), )