core

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateVersion  = errors.New("duplicate version")
	ErrNotCorrectVersion = errors.New("version must be above 0")
	ErrNotSetUp          = errors.New("not set up function")
	ErrNotSetDown        = errors.New("not set down function")
)

Errors.

Functions

This section is empty.

Types

type Config

type Config struct {
	Cmd MigrateCmd
	To  uint
}

Config migration configuration.

type Core

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

Core contains business logic for migrate database.

func New

func New(logger zerolog.Logger, fs FS, repo Repo) *Core

New builds and returns new instance business logic.

func (*Core) DownTo added in v0.8.0

func (c *Core) DownTo(ctx context.Context, versionTo uint, migrates ...Migrate) error

DownTo rollback to a specific version.

func (*Core) Migrate

func (c *Core) Migrate(ctx context.Context, dir string, cfg Config) error

Migrate migrates according to the settings.

func (*Core) NewMigrate

func (c *Core) NewMigrate(_ context.Context, dir, name string) error

NewMigrate create and save new migrate file.

func (*Core) Reset added in v0.8.0

func (c *Core) Reset(ctx context.Context, migrates ...Migrate) error

Reset rolls back all the migrations we've received.

func (*Core) Up added in v0.8.0

func (c *Core) Up(ctx context.Context, migrates ...Migrate) error

Up performs all the migrations received.

func (*Core) UpTo added in v0.8.0

func (c *Core) UpTo(ctx context.Context, versionTo uint, migrates ...Migrate) error

UpTo migration to a specific version.

type FS added in v0.8.0

type FS interface {
	fs.FS
	// Walk for walks on dir.
	Walk(string, func(string, fs.FileInfo) error) error
	// Mkdir make new dir if doesn't exist dir name.
	Mkdir(path string) error
	// SaveFile save new file.
	SaveFile(path string, buf []byte) error
}

FS manages file system.

type Migrate

type Migrate struct {
	Version uint
	Query   Query
}

Migrate contains migrate information.

type MigrateCmd

type MigrateCmd uint8

MigrateCmd migration command.

const (
	Up     MigrateCmd = iota + 1 // up
	UpTo                         // up-to
	DownTo                       // down-to
	Reset                        // reset
)

Migration enum.

func (MigrateCmd) String

func (i MigrateCmd) String() string

type Query

type Query struct {
	Up   string `sql:"up"`
	Down string `sql:"down"`
}

Query contains `up` and `down` query.

type Repo added in v0.8.0

type Repo interface {
	// Up makes migrate to database.
	Up(context.Context, Migrate) error
	// Rollback one migrate.
	Rollback(context.Context, Migrate) error
	// Version returns current migrate version from database.
	Version(context.Context) (uint, error)
}

Repo provides to database.

Jump to

Keyboard shortcuts

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