* [COMPLIANCE] Update Copyright and License Headers * chore: make gen to generate files with copyright headers * chore: update missed copyright headers --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
117 lines
2.6 KiB
Go
117 lines
2.6 KiB
Go
// Copyright IBM Corp. 2020, 2025
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package schema_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/db/schema"
|
|
"github.com/hashicorp/boundary/internal/db/schema/internal/edition"
|
|
"github.com/hashicorp/boundary/internal/db/schema/migration"
|
|
"github.com/hashicorp/boundary/testing/dbtest"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMigrateStore(t *testing.T) {
|
|
dialect := dbtest.Postgres
|
|
ctx := context.Background()
|
|
|
|
c, u, _, err := dbtest.StartUsingTemplate(dialect, dbtest.WithTemplate(dbtest.Template1))
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
require.NoError(t, c())
|
|
})
|
|
|
|
ran, err := schema.MigrateStore(ctx, schema.Dialect(dialect), u, schema.WithEditions(
|
|
edition.Editions{
|
|
{
|
|
Name: "oss",
|
|
Dialect: schema.Postgres,
|
|
LatestVersion: 1,
|
|
Migrations: migration.Migrations{
|
|
1: migration.Migration{
|
|
Statements: []byte(`select 1`),
|
|
Version: 1,
|
|
Edition: "oss",
|
|
},
|
|
},
|
|
Priority: 0,
|
|
},
|
|
},
|
|
))
|
|
assert.NoError(t, err)
|
|
assert.True(t, ran)
|
|
|
|
ran, err = schema.MigrateStore(ctx, schema.Dialect(dialect), u, schema.WithEditions(
|
|
edition.Editions{
|
|
{
|
|
Name: "oss",
|
|
Dialect: schema.Postgres,
|
|
LatestVersion: 1,
|
|
Migrations: migration.Migrations{
|
|
2: migration.Migration{
|
|
Statements: []byte(`select 1`),
|
|
Version: 2,
|
|
Edition: "oss",
|
|
},
|
|
},
|
|
Priority: 0,
|
|
},
|
|
},
|
|
))
|
|
assert.NoError(t, err)
|
|
assert.False(t, ran)
|
|
|
|
ran, err = schema.MigrateStore(ctx, schema.Dialect(dialect), u, schema.WithEditions(
|
|
edition.Editions{
|
|
{
|
|
Name: "oss",
|
|
Dialect: schema.Postgres,
|
|
LatestVersion: 2,
|
|
Migrations: migration.Migrations{
|
|
1: migration.Migration{
|
|
Statements: []byte(`select 1`),
|
|
Version: 1,
|
|
Edition: "oss",
|
|
},
|
|
2: migration.Migration{
|
|
Statements: []byte(`select 1`),
|
|
Version: 2,
|
|
Edition: "oss",
|
|
},
|
|
},
|
|
Priority: 0,
|
|
},
|
|
},
|
|
))
|
|
assert.NoError(t, err)
|
|
assert.True(t, ran)
|
|
ran, err = schema.MigrateStore(ctx, schema.Dialect(dialect), u, schema.WithEditions(
|
|
edition.Editions{
|
|
{
|
|
Name: "oss",
|
|
Dialect: schema.Postgres,
|
|
LatestVersion: 2,
|
|
Migrations: migration.Migrations{
|
|
1: migration.Migration{
|
|
Statements: []byte(`select 1`),
|
|
Version: 1,
|
|
Edition: "oss",
|
|
},
|
|
2: migration.Migration{
|
|
Statements: []byte(`select 1`),
|
|
Version: 2,
|
|
Edition: "oss",
|
|
},
|
|
},
|
|
Priority: 0,
|
|
},
|
|
},
|
|
))
|
|
assert.NoError(t, err)
|
|
assert.False(t, ran)
|
|
}
|