Documentation
¶
Overview ¶
Package migration provides a registry of the datastore engines that can run schema migrations. It is shared by the `migrate` and `head` commands and by the generic datastore test suite. Engines register themselves via RegisterMigratableEngine from an init function; importing an engine package makes it migratable.
Index ¶
- func Engines() []string
- func HeadRevision(engine string) (string, error)
- func MigrationNames(engine string) ([]string, error)
- func RegisterMigratableEngine[D migrate.Driver[C, T], C any, T any](engineName string, manager *migrate.Manager[D, C, T], ...)
- func Run(ctx context.Context, cfg *Config, revision string) error
- func UnregisterMigratableEngineForTesting(engineName string)
- func VerifiableMigrationName(engine string) (string, error)
- func Version(ctx context.Context, cfg *Config) (string, error)
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Engines ¶
func Engines() []string
Engines returns the names of all registered migratable engines, sorted.
func HeadRevision ¶
HeadRevision returns the latest migration revision for the given engine.
func MigrationNames ¶
MigrationNames returns the names of every migration supported by the given engine, ordered from oldest to newest (head).
func RegisterMigratableEngine ¶
func RegisterMigratableEngine[D migrate.Driver[C, T], C any, T any]( engineName string, manager *migrate.Manager[D, C, T], newDriver func(ctx context.Context, cfg *Config) (D, error), verifiableMigrationName string, )
RegisterMigratableEngine makes a datastore engine migratable. It is typically called from an init function of the package defining the engine. verifiableMigrationName is the earliest migration at which the engine's current datastore code can open the datastore and read and write data.
func UnregisterMigratableEngineForTesting ¶
func UnregisterMigratableEngineForTesting(engineName string)
UnregisterMigratableEngineForTesting removes an engine from the registry. Tests that register a fake engine must call it so the engine does not leak into the registry observed by other tests in the same binary.
func VerifiableMigrationName ¶
VerifiableMigrationName returns the earliest migration at which the given engine's current datastore code can open the datastore and read and write data.
Types ¶
type Config ¶
type Config struct {
DatastoreEngine string
DatastoreURI string
CredentialsProviderName string
SpannerCredentialsFile string
SpannerEmulatorHost string
MySQLTablePrefix string
Timeout time.Duration
BatchSize uint64
// ExtraConfig holds the string value of every flag registered on the
// command being run, keyed by flag name. Engines defined outside this
// repository register their own flags on the migrate command and read them
// from here, since this package has no dedicated field for them.
ExtraConfig map[string]string
}
Config holds configuration for running database migrations.
func (*Config) CredentialsProvider ¶
CredentialsProvider returns the configured datastore credentials provider, or nil if none is configured.