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>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package schema
|
|
|
|
import (
|
|
"context"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db/common"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
|
)
|
|
|
|
// 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) {
|
|
const op = "schema.MigrateStore"
|
|
|
|
d, err := common.SqlOpen(dialect.String(), url)
|
|
if err != nil {
|
|
return false, errors.Wrap(ctx, err, op)
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
return true, nil
|
|
}
|