go_migrator

package module
v0.0.0-...-e6936e5 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPartsCountForFileName = 3
	DirectionTextUp              = "up"
	DirectionTextDown            = "down"
	MigrationFileNameHelpText    = "%s invalid migration file name format, should be of format {version}_{title}.{up|down}.{extension}"

	MigrationDirectionUp MigrationDirection = iota
	MigrationDirectionDown

	FileNameDefaultExtensionDelimiter = "."
	FileNameVersionPlaceholder        = "{version}"
	FileNameDirectionPlaceholder      = "{direction}"
	FileNameExtensionPlaceholder      = "{extension}"

	CommandUsageHelpText = "Description:\n  Execute a migration to a specified version or the latest available version." +
		"\n\nUsage:\n  ./main [options] [<version>] [<direction>] " +
		"\n\nArguments:\n  version                     The version number (YYYYMMDDHHMMSS) to migrate to." +
		"\n  direction                   The direction to apply a migration towards. Possible values - up, down" +
		"\n\nOptions:\n      migrate                Applies all the unapplied migrations in the ascending order." +
		"\n      up                     Rolls up the migration by one version." +
		"\n      down                   Rolls down the migration by one version." +
		"\n      execute                Applies the specified migration. No warning is given even if the migration is already applied. " +
		"Usage - ./main execute <version> <direction>" +
		"\n      version                Displays the current DB migration version."
)

Variables

This section is empty.

Functions

func DefaultFileNameFormat

func DefaultFileNameFormat() string

Types

type Config

type Config struct {
	AbsoluteMigrationsDirectory string
	Debug                       bool

	// Filename config
	// TODO - allow overriding of this value via interface implementation
	// TODO - Filename config made part of this config in order to allow customization in future
	FileNameVersionDelimiter string
	VersionIndexByDelimiter  int
	PartsCountByDelimiter    int
	FileNameFormat           string
}

func NewConfig

func NewConfig(
	directory string,
	debug bool,
) Config

type MigrationDirection

type MigrationDirection int

func (MigrationDirection) IsValid

func (m MigrationDirection) IsValid() bool

func (MigrationDirection) String

func (m MigrationDirection) String() string

type MigrationInstruction

type MigrationInstruction struct {
	Version   int
	Direction MigrationDirection
	Command   string
}

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

func NewMigrator

func NewMigrator(
	directory string,
	debug bool,
	driver db.DriverInterface,
) (*Migrator, error)

func NewMigratorWithConfig

func NewMigratorWithConfig(
	config Config,
	driver db.DriverInterface,
) *Migrator

func (Migrator) Down

func (m Migrator) Down() error

func (Migrator) Execute

func (m Migrator) Execute(version int, direction MigrationDirection) error

func (Migrator) Migrate

func (m Migrator) Migrate() error

func (Migrator) Up

func (m Migrator) Up() error

func (*Migrator) Version

func (m *Migrator) Version() (int, error)

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

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