Skip to content

Commit

Permalink
feat(rdb): fetch latest engine version from API (#2317)
Browse files Browse the repository at this point in the history
  • Loading branch information
jremy42 authored Dec 12, 2024
1 parent 1b02856 commit 520fa31
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions api/rdb/v1/rdb_utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rdb

import (
"fmt"
"time"

"github.com/scaleway/scaleway-sdk-go/errors"
Expand Down Expand Up @@ -199,3 +200,25 @@ func (s *API) WaitForReadReplica(req *WaitForReadReplicaRequest, opts ...scw.Req
}
return readReplica.(*ReadReplica), nil
}

func (s *API) FetchLatestEngineVersion(engineName string) (*EngineVersion, error) {
engines, err := s.ListDatabaseEngines(&ListDatabaseEnginesRequest{})
if err != nil {
return nil, err
}

var latestEngineVersion *EngineVersion
for _, engine := range engines.Engines {
if engine.Name == engineName {
if len(engine.Versions) > 0 {
latestEngineVersion = engine.Versions[0]
break
}
}
}

if latestEngineVersion == nil {
return nil, fmt.Errorf("no versions found for engine: %s", engineName)
}
return latestEngineVersion, nil
}

0 comments on commit 520fa31

Please sign in to comment.