...

Source file src/go.mongodb.org/mongo-driver/mongo/integration/unified/schema_version.go

Documentation: go.mongodb.org/mongo-driver/mongo/integration/unified

     1  // Copyright (C) MongoDB, Inc. 2017-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  package unified
     8  
     9  import (
    10  	"fmt"
    11  	"strconv"
    12  	"strings"
    13  
    14  	"go.mongodb.org/mongo-driver/mongo/integration/mtest"
    15  )
    16  
    17  var (
    18  	supportedSchemaVersions = map[int]string{
    19  		1: "1.17",
    20  	}
    21  )
    22  
    23  // checkSchemaVersion determines if the provided schema version is supported and returns an error if it is not.
    24  func checkSchemaVersion(version string) error {
    25  	// First get the major version number from the schema. The schema version string should be in the format
    26  	// "major.minor.patch", "major.minor", or "major".
    27  
    28  	parts := strings.Split(version, ".")
    29  	if len(parts) == 0 {
    30  		return fmt.Errorf("error splitting schema version %q into parts", version)
    31  	}
    32  
    33  	majorVersion, err := strconv.Atoi(parts[0])
    34  	if err != nil {
    35  		return fmt.Errorf("error converting major version component %q to an integer: %v", parts[0], err)
    36  	}
    37  
    38  	// Find the latest supported version for the major version and use that to determine if the provided version is
    39  	// supported.
    40  	supportedVersion, ok := supportedSchemaVersions[majorVersion]
    41  	if !ok {
    42  		return fmt.Errorf("major version %d not supported", majorVersion)
    43  	}
    44  	if mtest.CompareServerVersions(supportedVersion, version) < 0 {
    45  		return fmt.Errorf(
    46  			"latest version supported for major version %d is %q, which is incompatible with specified version %q",
    47  			majorVersion, supportedVersion, version,
    48  		)
    49  	}
    50  	return nil
    51  }
    52  

View as plain text