@@ -73,22 +73,13 @@ type APIError struct {
7373}
7474
7575// ConfigUpdateRequest represents a request to update DBLab config.
76+ // Uses flat structure matching DBLab's ConfigProjection fields.
7677type ConfigUpdateRequest struct {
77- Retrieval * RetrievalConfigUpdate `json:"retrieval,omitempty"`
78- }
79-
80- // RetrievalConfigUpdate represents retrieval config fields to update.
81- type RetrievalConfigUpdate struct {
82- DBSource * DBSourceConfig `json:"dbSource,omitempty"`
83- }
84-
85- // DBSourceConfig represents the source database connection config.
86- type DBSourceConfig struct {
87- Host string `json:"host,omitempty"`
88- Port int `json:"port,omitempty"`
89- DBName string `json:"dbname,omitempty"`
90- Username string `json:"username,omitempty"`
91- Password string `json:"password,omitempty"`
78+ Host * string `json:"host,omitempty"`
79+ Port * int64 `json:"port,omitempty"`
80+ DBName * string `json:"dbname,omitempty"`
81+ Username * string `json:"username,omitempty"`
82+ Password * string `json:"password,omitempty"`
9283}
9384
9485// DBLabClient provides methods to interact with the DBLab Engine API.
@@ -227,39 +218,28 @@ func (c *DBLabClient) Health(ctx context.Context) error {
227218}
228219
229220// UpdateSourceConfig updates the source database connection in DBLab config.
221+ // DBLab automatically reloads the configuration after the update.
230222func (c * DBLabClient ) UpdateSourceConfig (ctx context.Context , host string , port int , dbname , username , password string ) error {
223+ port64 := int64 (port )
231224 updateReq := ConfigUpdateRequest {
232- Retrieval : & RetrievalConfigUpdate {
233- DBSource : & DBSourceConfig {
234- Host : host ,
235- Port : port ,
236- DBName : dbname ,
237- Username : username ,
238- Password : password ,
239- },
240- },
225+ Host : & host ,
226+ Port : & port64 ,
227+ DBName : & dbname ,
228+ Username : & username ,
229+ Password : & password ,
241230 }
242231
243232 bodyBytes , err := json .Marshal (updateReq )
244233 if err != nil {
245234 return fmt .Errorf ("failed to marshal config update: %w" , err )
246235 }
247236
248- resp , err := c .doRequest (ctx , http .MethodPatch , "/admin/config" , bytes .NewReader (bodyBytes ))
237+ resp , err := c .doRequest (ctx , http .MethodPut , "/admin/config" , bytes .NewReader (bodyBytes ))
249238 if err != nil {
250239 return fmt .Errorf ("failed to update DBLab config: %w" , err )
251240 }
252241 defer resp .Body .Close ()
253242
254- var result APIResponse
255- if err := json .NewDecoder (resp .Body ).Decode (& result ); err != nil {
256- return fmt .Errorf ("failed to decode config update response: %w" , err )
257- }
258-
259- if result .Status != "OK" {
260- return fmt .Errorf ("config update failed: %s" , result .Message )
261- }
262-
263243 return nil
264244}
265245
0 commit comments