migrator

package
v0.0.0-...-97aed24 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	COMMAND_CREATE  = "create"
	COMMAND_UP      = "up"
	COMMAND_DOWN    = "down"
	COMMAND_GOTO    = "goto"
	COMMAND_LIST    = "list"
	COMMAND_VERSION = "version"
	COMMAND_FIX     = "fix"
	COMMAND_FORCE   = "force"

	DIRECTION_UP   = "up"
	DIRECTION_DOWN = "down"
)

Variables

View Source
var (
	Fmt_success   = color.New(color.FgGreen, color.Bold)
	Fmt_error     = color.New(color.FgRed, color.Bold)
	Fmt_highlight = color.New(color.FgYellow, color.Bold)
)

Functions

This section is empty.

Types

type Migrator

type Migrator struct {
	DBRepository *dbrepo.DBRepo
	App          *config.AppConfig
	// contains filtered or unexported fields
}

func NewMigrator

func NewMigrator(path string, db *dbrepo.DBRepo, a *config.AppConfig) (*Migrator, error)

NewMigrator creates a *Migrator that can migrate a DB to different migration versions

func (Migrator) Create

func (m Migrator) Create(desc string) error

Create creates an up and down migration file in the configured migration directory

func (Migrator) CurrentVersion

func (m Migrator) CurrentVersion() (string, error)

CurrentVersion returns the current db migration version

func (Migrator) Down

func (m Migrator) Down(toVersion string) error

Down migrates a DB down for N number of migrations

func (*Migrator) FindMigrationGaps

func (m *Migrator) FindMigrationGaps(mvs []models.MigrationVersion, currentVersion string) (migrationGaps map[string]models.MigrationVersion, lastValidVersion string)

FindMigrationGaps finds all migrations that are older than the current migration version and have not yet been run and returns them as a slice of models.MigrationVersion. The last migration version (lastValidVersion) that was migrated before the oldest migration gap version is also returned as this is usefull for the fix command

func (Migrator) Force

func (m Migrator) Force(toVersion string) error

Force sets the current migration version without running any migrations

func (*Migrator) GetConfirmation

func (m *Migrator) GetConfirmation(promptMsg string, trueValues []string) error

GetConfirmation prompts users to confirm whether they want to continue with a command

func (Migrator) GetMigrationVersionInfo

func (m Migrator) GetMigrationVersionInfo() ([]models.MigrationVersion, error)

GetMigrationVersionInfo gathers details of all migrated versions and migrations files

func (Migrator) GetMigrationVersionInfoMap

func (m Migrator) GetMigrationVersionInfoMap() (map[string]*models.MigrationVersion, error)

GetMigrationVersionInfoMap reads all files in the migration directory and parses the filenames to determine all the migration vesions and descriptions. There details are return in a map of models.MigrationVersion items

func (Migrator) GetMigrationsToRun

func (m Migrator) GetMigrationsToRun(mvs []models.MigrationVersion, currentVersion, toVersion, migrationDirection, command string) ([]models.MigrationVersion, error)

GetMigrationsToRun determines which migrations must be run and returns the result as a slice of models.MigrationVersion

func (Migrator) Goto

func (m Migrator) Goto(toVersion string) error

Goto migrates a DB to the migration specified by version

func (*Migrator) Migrate

func (m *Migrator) Migrate(command, toVersion string) error

Migrate migrates a db from the current version to the specified toVersion

func (Migrator) Up

func (m Migrator) Up(toVersion string) error

Up migrates a DB up for N number of migrations

Jump to

Keyboard shortcuts

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