Rename root, api and sdk module paths (imports, go.mod, go_package, ldflags, build scripts, buf configs) and regenerate protobuf/gateway code with the project's pinned toolchain. Wire identifiers unchanged. api gets a local replace for sdk; root/api/sdk require v0.1.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
117 lines
2.7 KiB
Go
117 lines
2.7 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package schema_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db/schema"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db/schema/internal/edition"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db/schema/migration"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/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)
|
|
}
|