metadata

package
v0.94.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const CompatibleSince = "v0.94.0"

CompatibleSince defines the Compatible Since version, which is used by the `compatible_since` field in `metadata`. See https://dmd.tanna.dev/concepts/compatible-since/ for more details

Variables

View Source
var ErrNoCompatibleSince = errors.New("metadata: no `compatible_since` was found in the `metadata` table")

ErrNoCompatibleSince indicates that the given database did not have the `compatible_since` entry in the `metadata` table, for instance if it was initialised before v0.91.0

Functions

func IsCompatible

func IsCompatible(ctx context.Context, sqlDB *sql.DB, currentVersion string) (compatible bool, compatibleSince string, err error)

IsCompatible determines whether the database is compatible with the given `currentVersion` (either hardcoded by a caller, for instance if you're pinning to a specific set of database schemas, or pulled via version information)

An error is returned, which is either `ErrNoCompatibleSince`, to indicate that the `compatible_since` field could not be found in the database, or an error when retrieving or parsing the resulting `compatible_since` Otherwise, `compatible` is whether you should be able to safely use the versions together, and `compatibleSince` is the `compatible_since` value for reference

Example
// first, we need to set up our database
ctx := context.Background()
sqlDB, err := sql.Open("sqlite", ":memory:")
if err != nil {
	log.Fatal(err)
}

err = repositories.CreateTables(ctx, sqlDB)
if err != nil {
	log.Fatal(err)
}

meta := db.New(sqlDB)
// NOTE that this isn't meant to be the same version of DMD that this test runs against, purely an example
err = meta.SetDMDVersion(ctx, "v0.100.0")
if err != nil {
	log.Fatal(err)
}

// in this example, we'll pretend that there's been a breaking change introduced after v0.99.0, which results in v0.100.0
err = meta.SetCompatibleSince(ctx, "v0.100.0")
if err != nil {
	log.Fatal(err)
}

// now, see if we're compatible

// this should fail, as we're trying to run a /really old/ version
compatible, since, err := IsCompatible(ctx, sqlDB, "v0.1.0")
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Is v0.1.0   compatible with v0.100.0? %v: Only compatible since %v\n", compatible, since)

// this should pass, as we're trying to run a newer version of the CLI
compatible, since, err = IsCompatible(ctx, sqlDB, "v0.150.0")
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Is v0.150.0 compatible with v0.100.0? %v: Compatible since %v\n", compatible, since)
Output:

Is v0.1.0   compatible with v0.100.0? false: Only compatible since v0.100.0
Is v0.150.0 compatible with v0.100.0? true: Compatible since v0.100.0

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL