migrate

package
v0.0.0-...-710d95f Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMigrationsTable = "_migrations"

Variables

This section is empty.

Functions

This section is empty.

Types

type Migration

type Migration struct {
	File string
	Up   func(db dbx.Builder) error
	Down func(db dbx.Builder) error
}

type MigrationsList

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

MigrationsList defines a list with migration definitions

func (*MigrationsList) Item

func (l *MigrationsList) Item(index int) *Migration

Item returns a single migration from the list by its index.

func (*MigrationsList) Items

func (l *MigrationsList) Items() []*Migration

Items returns the internal migrations list slice.

func (*MigrationsList) Register

func (l *MigrationsList) Register(
	up func(db dbx.Builder) error,
	down func(db dbx.Builder) error,
	optFilename ...string,
)

Register adds new migration definition to the list.

If `optFilename` is not provided, it will try to get the name from its .go file.

The list will be sorted automatically based on the migrations file name.

type Runner

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

Runner defines a simple struct for managing the execution of db migrations.

func NewRunner

func NewRunner(db *dbx.DB, migrationsList MigrationsList) (*Runner, error)

NewRunner creates and initializes a new db migrations Runner instance.

func (*Runner) Down

func (r *Runner) Down(toRevertCount int) ([]string, error)

Down reverts the last `toRevertCount` applied migrations (in the order they were applied).

On success returns list with the reverted migrations file names.

func (*Runner) Run

func (r *Runner) Run(args ...string) error

Run interactively executes the current runner with the provided args.

The following commands are supported: - up - applies all migrations - down [n] - reverts the last n applied migrations

func (*Runner) Up

func (r *Runner) Up() ([]string, error)

Up executes all unapplied migrations for the provided runner.

On success returns list with the applied migrations file names.

Jump to

Keyboard shortcuts

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