drift

package
v0.0.0-...-2d2b994 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNegativeID  = errors.New("migration ID must not be negative")
	ErrDuplicateID = errors.New("duplicate migration ID")
)

Functions

func Migrate

func Migrate(ctx context.Context, io IO, db *sql.DB, migrationsDir string, until *MigrationID) error

Migrate runs all unapplied migrations in ID order, least to greatest. It skips any migrations that have already been applied.

If until is non-nil, this will also skip any migrations with IDs greater than it.

func NewFile

func NewFile(io IO, migrationsDir string, id MigrationID, slug string, tmpl *template.Template) (string, error)

NewFile creates a new migration file with a placeholder comment in it.

func Renumber

func Renumber(io IO, dir string, write bool) error

func Setup

func Setup(migrationsDir string) (string, error)

Setup creates the "init" migration that will prepare the database for migrations. This will create the migrations directory if needed.

Types

type IO

type IO interface {
	Logf(format string, args ...interface{})
	LogTable(cols []string, rows [][]string)
	Infof(format string, args ...interface{})
	Debugf(format string, args ...interface{})
}

type MigrationID

type MigrationID int64

A MigrationID is a nonnegative integer that will be used to sort migrations.

This will often be a Unix timestamp in seconds, so it's represented as as an int64 for easy conversion. That technically allows negative numbers (although getting one in modern times would be concerning!), so use NewMigrationID to check for negative values.

func NewMigrationID

func NewMigrationID(i int64) (MigrationID, error)

func (*MigrationID) Set

func (m *MigrationID) Set(s string) error

func (*MigrationID) String

func (m *MigrationID) String() string

func (*MigrationID) Type

func (*MigrationID) Type() string

func (MigrationID) Width

func (m MigrationID) Width() int

type TemplateData

type TemplateData struct {
	ID   MigrationID
	Slug string
}

Jump to

Keyboard shortcuts

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