Skip to content

Commit

Permalink
feat(cli): add shadow database host configuration
Browse files Browse the repository at this point in the history
- Add ShadowHost config option to control shadow database connection
- Default to Hostname if ShadowHost not set
  • Loading branch information
nzlz committed Dec 19, 2024
1 parent f81c17b commit c6e660e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/db/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ func CreateShadowDatabase(ctx context.Context, port uint16) (string, error) {
func ConnectShadowDatabase(ctx context.Context, timeout time.Duration, options ...func(*pgx.ConnConfig)) (conn *pgx.Conn, err error) {
// Retry until connected, cancelled, or timeout
policy := start.NewBackoffPolicy(ctx, timeout)
config := pgconn.Config{Port: utils.Config.Db.ShadowPort}
config := pgconn.Config{
Host: utils.Config.Db.ShadowHost,
Port: utils.Config.Db.ShadowPort,
}
connect := func() (*pgx.Conn, error) {
return utils.ConnectLocalPostgres(ctx, config, options...)
}
Expand Down Expand Up @@ -201,7 +204,7 @@ func DiffDatabase(ctx context.Context, schema []string, config pgconn.Config, w
}
fmt.Fprintln(w, "Diffing schemas:", strings.Join(schema, ","))
source := utils.ToPostgresURL(pgconn.Config{
Host: utils.Config.Hostname,
Host: utils.Config.Db.ShadowHost,
Port: utils.Config.Db.ShadowPort,
User: "postgres",
Password: utils.Config.Db.Password,
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ func NewConfig(editors ...ConfigEditor) config {
Enabled: true,
GlobPatterns: []string{"./seed.sql"},
},
ShadowHost: "127.0.0.1",
ShadowPort: 54320,
},
Realtime: realtime{
Image: realtimeImage,
Expand Down
1 change: 1 addition & 0 deletions pkg/config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type (
Image string `toml:"-"`
Port uint16 `toml:"port"`
ShadowPort uint16 `toml:"shadow_port"`
ShadowHost string `toml:"shadow_host"`
MajorVersion uint `toml:"major_version"`
Password string `toml:"-"`
RootKey string `toml:"-" mapstructure:"root_key"`
Expand Down

0 comments on commit c6e660e

Please sign in to comment.