migrate

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: MIT Imports: 11 Imported by: 0

README

migrate

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LEQ

func LEQ(a Version, b Version) bool

func SQLChecksum

func SQLChecksum(script string) string

func Statements

func Statements(script string) []string

Types

type CommandFunc

type CommandFunc func(con *sql.DB) error

type Info

type Info struct {
	Migrations Migrations
}

type LogFunc

type LogFunc func(format string, args ...interface{})

type Migration

type Migration struct {
	Rank          int
	Version       Version
	Description   string
	Type          Type
	Checksum      string
	Date          time.Time
	ExecutionTime int
	Status        Status
	Execute       CommandFunc `json:"-"`
}

func (Migration) IsRepeatable

func (m Migration) IsRepeatable() bool

func (Migration) String

func (m Migration) String() string

type Migrations

type Migrations []Migration

func (Migrations) String

func (ms Migrations) String() string

type Migrator

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

func NewMigrator

func NewMigrator(log LogFunc, db *sql.DB, support Support) *Migrator

func (*Migrator) Add

func (m *Migrator) Add(mig Migration)

func (*Migrator) AddGoMigration

func (m *Migrator) AddGoMigration(version Version, description string, execute CommandFunc)

func (*Migrator) AddRepeatableGoMigration

func (m *Migrator) AddRepeatableGoMigration(description string, execute CommandFunc)

func (*Migrator) AddRepeatableSQLMigration

func (m *Migrator) AddRepeatableSQLMigration(description string, script string)

func (*Migrator) AddSQLMigration

func (m *Migrator) AddSQLMigration(version Version, description string, script string)

func (*Migrator) Baseline

func (m *Migrator) Baseline(version Version, description string) error

Baselines an existing database, excluding all migrations upto and including baselineVersion. Baseline is for introducing Migrator to existing databases by baselining them at a specific version. The will cause Migrate to ignore all migrations upto and including the baseline version. Newer migrations will then be applied as usual.

func (*Migrator) Clean

func (m *Migrator) Clean() error

Drops all objects in configured schemas Clean is a great help in development and test. It will effectively give you a fresh start, by wiping your configured schemas completely clean. All objects (tables, views, procedures, ...) will be dropped. Needless to say: do not use against your production DB!

func (*Migrator) Info

func (m *Migrator) Info() Info

The details and status information about all the migrations. List lets you know where you stand. At a glance you will see which migrations have already been applied, which other ones are still pending, when they were executed and whether they were successful or not.

func (*Migrator) Migrate

func (m *Migrator) Migrate() error

create metadata table if not exists apply missing migrations

func (*Migrator) Repair

func (m *Migrator) Repair()

Repairs the metadata table Repair is your tool to fix issues with the metadata table. It has two main uses: - Remove failed migration entries (only for databases that do NOT support DDL transactions)

func (*Migrator) Validate

func (m *Migrator) Validate()

Validates the applied migrations against the available ones. Validate helps you verify that the migrations applied to the database match the ones available locally. This is very useful to detect accidental changes that may prevent you from reliably recreating the schema.

type SQLiteSupport

type SQLiteSupport struct{}

func (SQLiteSupport) Clean

func (SQLiteSupport) Clean(db *sql.DB) error

func (SQLiteSupport) CreateMigrationsTable

func (SQLiteSupport) CreateMigrationsTable(db *sql.DB) error

func (SQLiteSupport) ExistsMigrationsTable

func (SQLiteSupport) ExistsMigrationsTable(db *sql.DB) (bool, error)

func (SQLiteSupport) ListMigrations

func (SQLiteSupport) ListMigrations(con *sql.DB) (Migrations, error)

func (SQLiteSupport) RecordMigration

func (SQLiteSupport) RecordMigration(db *sql.DB, m Migration) error

type StatementBuilder

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

func NewStatementBuilder

func NewStatementBuilder() *StatementBuilder

func (*StatementBuilder) Append

func (b *StatementBuilder) Append(line string)

func (*StatementBuilder) IsTerminated

func (b *StatementBuilder) IsTerminated() bool

func (*StatementBuilder) Statement

func (b *StatementBuilder) Statement() string

type Status

type Status string
const (
	StatusSuccess Status = "success"
	StatusFailed  Status = "failed"
)

type Support

type Support interface {
	ExistsMigrationsTable(con *sql.DB) (bool, error)
	CreateMigrationsTable(con *sql.DB) error
	RecordMigration(con *sql.DB, m Migration) error
	ListMigrations(con *sql.DB) (Migrations, error)
	Clean(con *sql.DB) error
}

type Type

type Type string
const (
	TypeGo       Type = "Go"
	TypeSQL      Type = "SQL"
	TypeBaseline Type = "Baseline"
)

type Version

type Version string
const (
	VersionNone       Version = ""
	VersionRepeatable Version = "R"
)

Jump to

Keyboard shortcuts

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