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-09-10 09:31:27 -04:00
|
|
|
package schema_test
|
2021-01-19 10:40:41 -07:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2021-09-10 09:31:27 -04:00
|
|
|
"github.com/hashicorp/boundary/internal/db/schema"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db/schema/internal/edition"
|
2022-07-26 20:19:09 +00:00
|
|
|
"github.com/hashicorp/boundary/internal/db/schema/migration"
|
2021-07-30 08:49:56 -04:00
|
|
|
"github.com/hashicorp/boundary/testing/dbtest"
|
2021-01-19 10:40:41 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
2021-01-25 14:43:50 -07:00
|
|
|
func TestMigrateStore(t *testing.T) {
|
2021-07-30 08:49:56 -04:00
|
|
|
dialect := dbtest.Postgres
|
2021-01-19 10:40:41 -07:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2021-07-30 08:49:56 -04:00
|
|
|
c, u, _, err := dbtest.StartUsingTemplate(dialect, dbtest.WithTemplate(dbtest.Template1))
|
2021-01-19 10:40:41 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
require.NoError(t, c())
|
|
|
|
|
})
|
|
|
|
|
|
2021-09-10 09:31:27 -04:00
|
|
|
ran, err := schema.MigrateStore(ctx, schema.Dialect(dialect), u, schema.WithEditions(
|
|
|
|
|
edition.Editions{
|
|
|
|
|
{
|
|
|
|
|
Name: "oss",
|
|
|
|
|
Dialect: schema.Postgres,
|
|
|
|
|
LatestVersion: 1,
|
2022-07-26 20:19:09 +00:00
|
|
|
Migrations: migration.Migrations{
|
|
|
|
|
1: migration.Migration{
|
|
|
|
|
Statements: []byte(`select 1`),
|
|
|
|
|
Version: 1,
|
|
|
|
|
Edition: "oss",
|
|
|
|
|
},
|
2021-09-10 09:31:27 -04:00
|
|
|
},
|
|
|
|
|
Priority: 0,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
))
|
2021-01-19 10:40:41 -07:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.True(t, ran)
|
2021-09-10 09:31:27 -04:00
|
|
|
|
|
|
|
|
ran, err = schema.MigrateStore(ctx, schema.Dialect(dialect), u, schema.WithEditions(
|
|
|
|
|
edition.Editions{
|
|
|
|
|
{
|
|
|
|
|
Name: "oss",
|
|
|
|
|
Dialect: schema.Postgres,
|
|
|
|
|
LatestVersion: 1,
|
2022-07-26 20:19:09 +00:00
|
|
|
Migrations: migration.Migrations{
|
|
|
|
|
2: migration.Migration{
|
|
|
|
|
Statements: []byte(`select 1`),
|
|
|
|
|
Version: 2,
|
|
|
|
|
Edition: "oss",
|
|
|
|
|
},
|
2021-09-10 09:31:27 -04:00
|
|
|
},
|
|
|
|
|
Priority: 0,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
))
|
2021-01-19 10:40:41 -07:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.False(t, ran)
|
|
|
|
|
|
2021-09-10 09:31:27 -04:00
|
|
|
ran, err = schema.MigrateStore(ctx, schema.Dialect(dialect), u, schema.WithEditions(
|
|
|
|
|
edition.Editions{
|
|
|
|
|
{
|
|
|
|
|
Name: "oss",
|
|
|
|
|
Dialect: schema.Postgres,
|
|
|
|
|
LatestVersion: 2,
|
2022-07-26 20:19:09 +00:00
|
|
|
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",
|
|
|
|
|
},
|
2021-09-10 09:31:27 -04:00
|
|
|
},
|
|
|
|
|
Priority: 0,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
))
|
2021-01-19 10:40:41 -07:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.True(t, ran)
|
2021-09-10 09:31:27 -04:00
|
|
|
ran, err = schema.MigrateStore(ctx, schema.Dialect(dialect), u, schema.WithEditions(
|
|
|
|
|
edition.Editions{
|
|
|
|
|
{
|
|
|
|
|
Name: "oss",
|
|
|
|
|
Dialect: schema.Postgres,
|
|
|
|
|
LatestVersion: 2,
|
2022-07-26 20:19:09 +00:00
|
|
|
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",
|
|
|
|
|
},
|
2021-09-10 09:31:27 -04:00
|
|
|
},
|
|
|
|
|
Priority: 0,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
))
|
2021-01-19 10:40:41 -07:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.False(t, ran)
|
|
|
|
|
}
|