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
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package postgres_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCurrentStatePreEdition(t *testing.T) {
|
|
ctx := context.Background()
|
|
p, db, _ := setup(ctx, t)
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
create table boundary_schema_version (
|
|
version bigint primary key,
|
|
dirty boolean not null
|
|
);`)
|
|
require.NoError(t, err)
|
|
_, err = db.ExecContext(ctx, `
|
|
insert into boundary_schema_version
|
|
(version, dirty)
|
|
values
|
|
(1001, false);`)
|
|
require.NoError(t, err)
|
|
|
|
version, initialized, err := p.CurrentState(ctx, "oss")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, version, 1001)
|
|
assert.True(t, initialized)
|
|
}
|
|
|
|
func TestCurrentStateOldSchemaTable(t *testing.T) {
|
|
ctx := context.Background()
|
|
p, db, _ := setup(ctx, t)
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
create table schema_migrations (
|
|
version bigint primary key,
|
|
dirty boolean not null
|
|
);`)
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
_, err = db.ExecContext(ctx, `
|
|
insert into schema_migrations
|
|
(version, dirty)
|
|
values
|
|
(1001, false);`)
|
|
require.NoError(t, err)
|
|
|
|
version, initialized, err := p.CurrentState(ctx, "oss")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, version, 1001)
|
|
assert.True(t, initialized)
|
|
}
|