2022-07-26 20:19:09 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2021-04-08 20:54:32 -04:00
|
|
|
package schema
|
|
|
|
|
|
2022-07-26 20:19:09 +00:00
|
|
|
import (
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db/schema/internal/edition"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db/schema/migration"
|
|
|
|
|
)
|
2021-04-08 20:54:32 -04:00
|
|
|
|
2021-09-10 09:31:27 -04:00
|
|
|
// PartialEditions is used by TestCreatePartialEditions. It is a map of edition
|
|
|
|
|
// names to the max version that should be included.
|
|
|
|
|
type PartialEditions map[string]int
|
|
|
|
|
|
|
|
|
|
// TestCreatePartialEditions is used by tests to create a subset of the Edition migrations.
|
|
|
|
|
func TestCreatePartialEditions(dialect Dialect, p PartialEditions) edition.Editions {
|
|
|
|
|
editions.Lock()
|
|
|
|
|
defer editions.Unlock()
|
|
|
|
|
|
|
|
|
|
e := make(edition.Editions, 0, len(p))
|
|
|
|
|
for _, ee := range editions.m[dialect] {
|
|
|
|
|
maxVer, ok := p[ee.Name]
|
|
|
|
|
if ok {
|
|
|
|
|
edition := edition.Edition{
|
|
|
|
|
Name: ee.Name,
|
|
|
|
|
Dialect: ee.Dialect,
|
|
|
|
|
Priority: ee.Priority,
|
|
|
|
|
LatestVersion: nilVersion,
|
2022-07-26 20:19:09 +00:00
|
|
|
Migrations: make(migration.Migrations),
|
2021-09-10 09:31:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for k, b := range ee.Migrations {
|
|
|
|
|
if k > maxVer {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
edition.Migrations[k] = b
|
|
|
|
|
if k > edition.LatestVersion {
|
|
|
|
|
edition.LatestVersion = k
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
e = append(e, edition)
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-10 09:31:27 -04:00
|
|
|
return e
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|