migrator

package module
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMigrationsBadType = errors.New("migrations must be slice of struct")
)

Functions

This section is empty.

Types

type Migration added in v1.3.0

type Migration struct {
	Version int
	Name    string
	Up      string
	Down    string
}

func (Migration) FileName added in v1.3.0

func (m Migration) FileName(optionalDelta ...int) string

func (Migration) String added in v1.3.0

func (m Migration) String(optionalDelta ...int) string

type Migrations added in v1.3.0

type Migrations []Migration

type Migrator

type Migrator struct {
	Scope  string
	DB     db.DB
	Logger logger.Logger
	// contains filtered or unexported fields
}

func NewMigrator added in v1.3.0

func NewMigrator(optionalScope ...string) *Migrator

func (*Migrator) CanonicalScope

func (m *Migrator) CanonicalScope() string

CanonicalScope returns valid scope name.

func (*Migrator) Migrate

func (m *Migrator) Migrate() (err error)

Migrate executes the up SQL for all the migrations that have not yet been run.

func (*Migrator) NewMigration added in v1.3.0

func (m *Migrator) NewMigration(models ...PsqlModel) (Migrations, error)

NewMigration generates migration file based on the differences between schemas in the database and psql models.

func (*Migrator) Rollback

func (m *Migrator) Rollback() (err error)

Rollback executes the down SQL of last migration.

func (*Migrator) SetConnection added in v1.3.0

func (m *Migrator) SetConnection(dbConn db.DB)

func (*Migrator) SetLogger added in v1.3.0

func (m *Migrator) SetLogger(logger logger.Logger)

func (*Migrator) SetMigrations

func (m *Migrator) SetMigrations(migrations interface{}) error

SetMigrations imports migrations.

func (*Migrator) Versions added in v1.1.0

func (m *Migrator) Versions() (migrated, unmigrated []int)

Versions returns version numbers of migrations that have been run and not yet been run.

type PsqlModel added in v1.3.0

type PsqlModel interface {
	Columns() []string
	ColumnDataTypes() map[string]string
	TableName() string
	Schema() string
	DropSchema() string
}

Jump to

Keyboard shortcuts

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