Organize DB Schema Migration Code and DB Init Checks (#842)

Create Schema Manager and propagate contexts into the DB calls downstream.
Add checks at controller startup and database init for correct schema version and schema migration dirty bit being set.
This commit is contained in:
Todd Knight authored and GitHub committed 2021-01-19 10:40:41 -07:00
1 parent c141a050e5
commit ec6151d174
83 files changed
+2425 -1176

No files matched your search

+6 -3
View File
@@ -10,6 +10,7 @@ import (
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/hashicorp/boundary/internal/db/schema"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/oplog/store"
wrapping "github.com/hashicorp/go-kms-wrapping"
@@ -23,6 +24,7 @@ func TestSetup(t *testing.T, dialect string, opt ...TestOption) (*gorm.DB, strin
var cleanup func() error
var url string
var err error
ctx := context.Background()
opts := getTestOpts(opt...)
@@ -36,13 +38,14 @@ func TestSetup(t *testing.T, dialect string, opt ...TestOption) (*gorm.DB, strin
assert.NoError(t, cleanup(), "Got error cleaning up db in docker.")
})
default:
cleanup = func() error { return nil }
url = opts.withTestDatabaseUrl
}
_, err = InitStore(dialect, cleanup, url)
_, err = schema.InitStore(ctx, dialect, url)
if err != nil {
t.Fatal(err)
t.Fatalf("Couldn't init store on existing db: %v", err)
}
db, err := gorm.Open(dialect, url)
if err != nil {
t.Fatal(err)