migration

package
v1.56.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

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

func HeadRevision(engine string) (string, error)

HeadRevision returns the latest migration revision for the given engine.

func MigrationNames

func MigrationNames(engine string) ([]string, error)

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 Run

func Run(ctx context.Context, cfg *Config, revision string) error

Run runs the migrations for the configured datastore engine up to the given revision.

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

func VerifiableMigrationName(engine string) (string, error)

VerifiableMigrationName returns the earliest migration at which the given engine's current datastore code can open the datastore and read and write data.

func Version

func Version(ctx context.Context, cfg *Config) (string, error)

Version returns the migration revision the configured datastore is currently at.

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

func (cfg *Config) CredentialsProvider(ctx context.Context) (datastore.CredentialsProvider, error)

CredentialsProvider returns the configured datastore credentials provider, or nil if none is configured.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL