mysql

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	StatusRollingBack = "rolling back"
	StatusApplying    = "applying"
	StatusApplied     = "applied"
)
View Source
const (
	MigrationExtension = ".sql"
)

Variables

View Source
var (
	NoErrAlreadyApplied = errors.New("migration has already been applied")
	NoErrDoesNotExist   = errors.New("migration does not exist")
)

Functions

func GetMigrationNamesFromFilenames added in v1.0.4

func GetMigrationNamesFromFilenames(filenameList []string) ([]string, []error)

func Init

func Init(tableName string, connection *sql.DB) error

func NormalizeQuery

func NormalizeQuery(query string) string

Types

type Migration

type Migration struct {
	// ID will contain the database-assigned auto-incremented ID of the migration
	ID int64 `json:"id" yaml:"id"`
	// Name contains the name of the migration derived from the migration file name
	Name string `json:"name" yaml:"name"`
	// Up contains a SQL command that should result in a up-version shift of the database schema
	Up string `json:"up" yaml:"up"`
	// Down contains a SQL command that should result in a down-version shift of the database schema
	Down string `json:"down" yaml:"down"`
	// Error contains any error that happened
	Error *string `json:"error" yaml:"error"`
	// Status contains the status of the migration
	Status string `json:"status" yaml:"status`
	// AppliedAt holds the timestamp when the migration was successfully applied to the database
	AppliedAt *time.Time `json:"applied_at" yaml:"applied_at"`
	// CreatedAt holds the timestamp when the migration was initialised in the database
	CreatedAt *time.Time `json:"created_at" yaml:"created_at"`
}

func New

func New(name, up, down string) *Migration

func NewFromDB added in v1.0.2

func NewFromDB(name, tableName string, connection *sql.DB) (*Migration, error)

func NewFromFile

func NewFromFile(name, upFilePath, downFilePath string) (*Migration, error)

func (*Migration) Apply

func (m *Migration) Apply(tableName string, connection *sql.DB) error

func (*Migration) Resolve

func (m *Migration) Resolve(tableName string, connection *sql.DB) error

func (*Migration) Rollback

func (m *Migration) Rollback(tableName string, connection *sql.DB) error

func (*Migration) Validate

func (m *Migration) Validate(tableName string, connection *sql.DB) error

type Migrations added in v1.0.2

type Migrations []*Migration

func NewFromDirectory added in v1.0.4

func NewFromDirectory(directoryPath string) (Migrations, error)

func (Migrations) Len added in v1.0.2

func (m Migrations) Len() int

Len implements the sort.Interface

func (Migrations) Less added in v1.0.2

func (m Migrations) Less(i, j int) bool

Less implements the sort.Interface

func (Migrations) Swap added in v1.0.2

func (m Migrations) Swap(i, j int)

Swap implements the sort.Interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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