Skip to content

Commit

Permalink
Fixed the logic for checking source db version compatibility and adde…
Browse files Browse the repository at this point in the history
…d it to assess migration too for PG (#2115)
  • Loading branch information
ShivanshGahlot authored Dec 24, 2024
1 parent 81c30b0 commit 23033f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 8 additions & 0 deletions yb-voyager/cmd/assessMigrationCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ func assessMigration() (err error) {
// We will require source db connection for the below checks
// Check if required binaries are installed.
if source.RunGuardrailsChecks {
// Check source database version.
log.Info("checking source DB version")
err = source.DB().CheckSourceDBVersion(exportType)
if err != nil {
return fmt.Errorf("source DB version check failed: %w", err)
}

// Check if required binaries are installed.
binaryCheckIssues, err := checkDependenciesForExport()
if err != nil {
return fmt.Errorf("failed to check dependencies for assess migration: %w", err)
Expand Down
16 changes: 13 additions & 3 deletions yb-voyager/src/srcdb/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (

const MIN_SUPPORTED_PG_VERSION_OFFLINE = "9"
const MIN_SUPPORTED_PG_VERSION_LIVE = "10"
const MAX_SUPPORTED_PG_VERSION = "16"
const MAX_SUPPORTED_PG_VERSION = "17"
const MISSING = "MISSING"
const GRANTED = "GRANTED"
const NO_USAGE_PERMISSION = "NO USAGE PERMISSION"
Expand Down Expand Up @@ -979,14 +979,24 @@ func (pg *PostgreSQL) CheckSourceDBVersion(exportType string) error {
if pgVersion == "" {
return fmt.Errorf("failed to get source database version")
}

// Extract the major version from the full version string
// Version can be like: 17.2 (Ubuntu 17.2-1.pgdg20.04+1), 17.2, 17alpha1 etc.
re := regexp.MustCompile(`^(\d+)`)
match := re.FindStringSubmatch(pgVersion)
if len(match) < 2 {
return fmt.Errorf("failed to extract major version from source database version: %s", pgVersion)
}
majorVersion := match[1]

supportedVersionRange := fmt.Sprintf("%s to %s", MIN_SUPPORTED_PG_VERSION_OFFLINE, MAX_SUPPORTED_PG_VERSION)

if version.CompareSimple(pgVersion, MAX_SUPPORTED_PG_VERSION) > 0 || version.CompareSimple(pgVersion, MIN_SUPPORTED_PG_VERSION_OFFLINE) < 0 {
if version.CompareSimple(majorVersion, MAX_SUPPORTED_PG_VERSION) > 0 || version.CompareSimple(majorVersion, MIN_SUPPORTED_PG_VERSION_OFFLINE) < 0 {
return fmt.Errorf("current source db version: %s. Supported versions: %s", pgVersion, supportedVersionRange)
}
// for live migration
if exportType == utils.CHANGES_ONLY || exportType == utils.SNAPSHOT_AND_CHANGES {
if version.CompareSimple(pgVersion, MIN_SUPPORTED_PG_VERSION_LIVE) < 0 {
if version.CompareSimple(majorVersion, MIN_SUPPORTED_PG_VERSION_LIVE) < 0 {
supportedVersionRange = fmt.Sprintf("%s to %s", MIN_SUPPORTED_PG_VERSION_LIVE, MAX_SUPPORTED_PG_VERSION)
utils.PrintAndLog(color.RedString("Warning: Live Migration: Current source db version: %s. Supported versions: %s", pgVersion, supportedVersionRange))
}
Expand Down

0 comments on commit 23033f8

Please sign in to comment.