migrator

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Table            string
	StatementTimeout string
	FileMask         string
}

func NewDefaultConfig added in v0.2.0

func NewDefaultConfig() Config

type Migration

type Migration struct {
	Filename      string
	Data          []byte
	Md5Sum        string
	Transactional bool
}

func NewMigration

func NewMigration(rootDir, filename string) (Migration, error)

func (*Migration) ToDB

func (m *Migration) ToDB() *PgMigration

type Migrations

type Migrations []Migration

func (Migrations) FirstNonTransactional

func (mm Migrations) FirstNonTransactional() (*Migration, bool)

func (Migrations) ToDB

func (mm Migrations) ToDB() []PgMigration

type Migrator

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

func NewMigrator

func NewMigrator(db *pg.DB, cfg Config, rootDir string) *Migrator

func (*Migrator) DryRun

func (m *Migrator) DryRun(ctx context.Context, filenames []string, chCurrentFile chan string) error

DryRun tries to apply migrations. Runs migrations inside single transaction and always rolls back it returns err, if apply done with error or if non-transactional migration was found

func (*Migrator) Last

func (m *Migrator) Last(ctx context.Context, num int) ([]PgMigration, error)

Last shows applied migrations

func (*Migrator) Plan

func (m *Migrator) Plan(ctx context.Context) ([]string, error)

Plan reads filenames from migrator root dir, fetch completed filenames from db, compare its and returns .

func (*Migrator) Redo

func (m *Migrator) Redo(ctx context.Context, chCurrentFile chan string) (*PgMigration, error)

Redo rerun last migration

func (*Migrator) Run

func (m *Migrator) Run(ctx context.Context, filenames []string, chCurrentFile chan string) error

Run run migrations from files, apply transactional and non transactional

func (*Migrator) Skip added in v0.3.0

func (m *Migrator) Skip(ctx context.Context, filenames []string, chCurrentFile chan string) error

Skip marks migrations as completed

func (*Migrator) Verify

func (m *Migrator) Verify(ctx context.Context) ([]PgMigration, error)

Verify compare md5 sum applied migrations with migrations in filesystem. It returns invalid migrations by md5sum.

type PgMigration

type PgMigration struct {
	ID            int        `pg:"id,pk"`
	Filename      string     `pg:"filename,use_zero"`
	StartedAt     time.Time  `pg:"startedAt,use_zero"`
	FinishedAt    *time.Time `pg:"finishedAt"`
	Transactional bool       `pg:"transactional,use_zero"`
	Md5sum        string     `pg:"md5sum,use_zero"`
	Md5sumLocal   string     `pg:"-"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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