Skip to content

Commit 4dbdfd7

Browse files
committed
feat: extend Provider interface with FindBinary, CreateSandbox, Start, Stop
1 parent 6d59eb7 commit 4dbdfd7

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

providers/mysql/mysql.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ func (p *MySQLProvider) DefaultPorts() providers.PortRange {
3232
}
3333
}
3434

35+
func (p *MySQLProvider) FindBinary(version string) (string, error) {
36+
return "", fmt.Errorf("MySQLProvider.FindBinary: use sandbox package directly (not yet migrated)")
37+
}
38+
39+
func (p *MySQLProvider) CreateSandbox(config providers.SandboxConfig) (*providers.SandboxInfo, error) {
40+
return nil, fmt.Errorf("MySQLProvider.CreateSandbox: use sandbox package directly (not yet migrated)")
41+
}
42+
43+
func (p *MySQLProvider) StartSandbox(dir string) error {
44+
return fmt.Errorf("MySQLProvider.StartSandbox: use sandbox package directly (not yet migrated)")
45+
}
46+
47+
func (p *MySQLProvider) StopSandbox(dir string) error {
48+
return fmt.Errorf("MySQLProvider.StopSandbox: use sandbox package directly (not yet migrated)")
49+
}
50+
3551
func Register(reg *providers.Registry) error {
3652
return reg.Register(NewMySQLProvider())
3753
}

providers/provider.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,39 @@ import (
55
"sort"
66
)
77

8+
// SandboxConfig holds provider-agnostic sandbox configuration.
9+
type SandboxConfig struct {
10+
Version string
11+
Dir string // sandbox directory path
12+
Port int // primary port
13+
AdminPort int // admin/management port (0 if not applicable)
14+
Host string // bind address
15+
DbUser string // admin username
16+
DbPassword string // admin password
17+
Options map[string]string // provider-specific key-value options
18+
}
19+
20+
// SandboxInfo describes a deployed sandbox instance.
21+
type SandboxInfo struct {
22+
Dir string
23+
Port int
24+
Socket string
25+
Status string // "running", "stopped"
26+
}
27+
828
// Provider is the core abstraction for deploying database infrastructure.
9-
// Phase 2a defines a minimal interface (Name, ValidateVersion, DefaultPorts).
10-
// Phase 2b will add CreateSandbox, Start, Stop, Destroy, HealthCheck when
11-
// ProxySQL and other providers need them.
1229
type Provider interface {
1330
Name() string
1431
ValidateVersion(version string) error
1532
DefaultPorts() PortRange
33+
// FindBinary returns the path to the provider's main binary, or error if not found.
34+
FindBinary(version string) (string, error)
35+
// CreateSandbox deploys a new sandbox instance.
36+
CreateSandbox(config SandboxConfig) (*SandboxInfo, error)
37+
// StartSandbox starts a stopped sandbox.
38+
StartSandbox(dir string) error
39+
// StopSandbox stops a running sandbox.
40+
StopSandbox(dir string) error
1641
}
1742

1843
type PortRange struct {

providers/provider_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ type mockProvider struct{ name string }
77
func (m *mockProvider) Name() string { return m.name }
88
func (m *mockProvider) ValidateVersion(version string) error { return nil }
99
func (m *mockProvider) DefaultPorts() PortRange { return PortRange{BasePort: 9999, PortsPerInstance: 1} }
10+
func (m *mockProvider) FindBinary(version string) (string, error) { return "/usr/bin/mock", nil }
11+
func (m *mockProvider) CreateSandbox(config SandboxConfig) (*SandboxInfo, error) { return &SandboxInfo{Dir: "/tmp/mock"}, nil }
12+
func (m *mockProvider) StartSandbox(dir string) error { return nil }
13+
func (m *mockProvider) StopSandbox(dir string) error { return nil }
1014

1115
func TestRegistryRegisterAndGet(t *testing.T) {
1216
reg := NewRegistry()

0 commit comments

Comments
 (0)