Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions internal/gen/types/typescript/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...))
Expand All @@ -39,6 +40,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
Expand All @@ -47,15 +49,20 @@ func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas
if strings.Contains(utils.Config.Api.Image, "v9") {
postgrestV9Compat = true
}
}

fmt.Fprintln(os.Stderr, "Connecting to", dbConfig.Host, dbConfig.Port)
// Use custom network when connecting to local database
dbConfig.Host = utils.DbAliases[0]
dbConfig.Port = 5432
networkID = utils.NetId
}
// 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
Expand All @@ -75,7 +82,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{},
"",
Expand Down
6 changes: 5 additions & 1 deletion internal/testing/pgtest/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
)
Expand Down