This refactors the schema package and subpackages to support editions.
An Edition is a collection of sql migrations. A given boundary binary
can have multiple migration editions. The `schema.Manager` is updated to
apply the necessary migrations in the correct order, leveraging an
Edition's priority to determine the order in which the separate Editions
are applied.
The sql migration files are now nested under a directory for the
edition.
This also switches from the generated code to using embed, which
eliminates the need for the `make migrations` target and the generated
code. As such this commit removes the target and generated code.
See:
https://pkg.go.dev/embed
162 lines
2.1 KiB
Go
162 lines
2.1 KiB
Go
package schema_test
|
|
|
|
import (
|
|
"embed"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/db/schema"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type testEdition struct {
|
|
name string
|
|
dialect schema.Dialect
|
|
fs embed.FS
|
|
priority int
|
|
}
|
|
|
|
var (
|
|
//go:embed testdata/one
|
|
one embed.FS
|
|
|
|
//go:embed testdata/two
|
|
two embed.FS
|
|
|
|
//go:embed testdata/three
|
|
three embed.FS
|
|
)
|
|
|
|
func TestRegisterEditionPanics(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
editions []testEdition
|
|
}{
|
|
{
|
|
"unsupportedDialect",
|
|
[]testEdition{
|
|
{
|
|
"one",
|
|
schema.Dialect("mongodb"),
|
|
one,
|
|
0,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"duplicateName",
|
|
[]testEdition{
|
|
{
|
|
"one",
|
|
schema.Postgres,
|
|
one,
|
|
0,
|
|
},
|
|
{
|
|
"one",
|
|
schema.Postgres,
|
|
one,
|
|
1,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"duplicatePriority",
|
|
[]testEdition{
|
|
{
|
|
"one",
|
|
schema.Postgres,
|
|
one,
|
|
0,
|
|
},
|
|
{
|
|
"two",
|
|
schema.Postgres,
|
|
two,
|
|
0,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Panics(t, func() {
|
|
for _, e := range tt.editions {
|
|
schema.RegisterEdition(e.name, e.dialect, e.fs, e.priority)
|
|
}
|
|
}, tt.name)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRegisterEdition(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
editions []testEdition
|
|
}{
|
|
{
|
|
"singleEdition",
|
|
[]testEdition{
|
|
{
|
|
"one",
|
|
schema.Postgres,
|
|
one,
|
|
0,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"twoEditions",
|
|
[]testEdition{
|
|
{
|
|
"one",
|
|
schema.Postgres,
|
|
one,
|
|
0,
|
|
},
|
|
{
|
|
"two",
|
|
schema.Postgres,
|
|
one,
|
|
1,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"threeEditions",
|
|
[]testEdition{
|
|
{
|
|
"one",
|
|
schema.Postgres,
|
|
one,
|
|
0,
|
|
},
|
|
{
|
|
"two",
|
|
schema.Postgres,
|
|
one,
|
|
1,
|
|
},
|
|
{
|
|
"three",
|
|
schema.Postgres,
|
|
one,
|
|
3,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.NotPanics(t, func() {
|
|
schema.TestClearEditions(t)
|
|
for _, e := range tt.editions {
|
|
schema.RegisterEdition(e.name, e.dialect, e.fs, e.priority)
|
|
}
|
|
}, tt.name)
|
|
})
|
|
}
|
|
schema.TestClearEditions(t)
|
|
}
|