Files
threshold/internal/db/schema/schema.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.1 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
2021-01-25 14:43:50 -07:00
// SPDX-License-Identifier: BUSL-1.1
2023-02-02 17:15:17 -08:00
package schema
import (
"context"
"github.com/hashicorp/boundary/internal/db/common"
"github.com/hashicorp/boundary/internal/errors"
)
2021-01-25 14:43:50 -07:00
// MigrateStore executes the migrations needed to initialize the store. It
// returns true if migrations actually ran; false if the database is already current
// or if there was an error. Supports the WithEditions(...) option.
func MigrateStore(ctx context.Context, dialect Dialect, url string, opt ...Option) (bool, error) {
2021-01-25 14:43:50 -07:00
const op = "schema.MigrateStore"
d, err := common.SqlOpen(dialect.String(), url)
if err != nil {
return false, errors.Wrap(ctx, err, op)
}
2021-04-08 20:54:32 -04:00
sMan, err := NewManager(ctx, dialect, d, opt...)
if err != nil {
return false, errors.Wrap(ctx, err, op)
}
defer sMan.Close(ctx)
st, err := sMan.CurrentState(ctx)
if err != nil {
return false, errors.Wrap(ctx, err, op)
}
if st.Initialized && st.MigrationsApplied() {
return false, nil
}
if _, err := sMan.ApplyMigrations(ctx); err != nil {
return false, errors.Wrap(ctx, err, op)
}
2021-01-25 14:43:50 -07:00
return true, nil
}