popx

package
v0.0.185 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: Apache-2.0 Imports: 21 Imported by: 20

Documentation

Index

Constants

View Source
const (
	Pending = "Pending"
	Applied = "Applied"
)

Variables

This section is empty.

Functions

func ParameterizedMigrationContent added in v0.0.185

func ParameterizedMigrationContent(params map[string]interface{}) func(mf Migration, c *pop.Connection, r []byte, usingTemplate bool) (string, error)

func WithMigrationContentMiddleware added in v0.0.183

func WithMigrationContentMiddleware(middleware func(content string, err error) (string, error)) func(*MigrationBoxPkger) *MigrationBoxPkger

func WithTemplateValues added in v0.0.183

func WithTemplateValues(v map[string]interface{}) func(*MigrationBoxPkger) *MigrationBoxPkger

Types

type Migration added in v0.0.185

type Migration struct {
	// Path to the migration (./migrations/123_create_widgets.up.sql)
	Path string
	// Version of the migration (123)
	Version string
	// Name of the migration (create_widgets)
	Name string
	// Direction of the migration (up)
	Direction string
	// Type of migration (sql)
	Type string
	// DB type (all|postgres|mysql...)
	DBType string
	// Runner function to run/execute the migration
	Runner func(Migration, *pop.Connection, *pop.Tx) error
}

Migration handles the data for a given database migration

func (Migration) Run added in v0.0.185

func (mf Migration) Run(c *pop.Connection, tx *pop.Tx) error

Run the migration. Returns an error if there is no mf.Runner defined.

type MigrationBoxPkger added in v0.0.183

type MigrationBoxPkger struct {
	Migrator

	Dir pkger.Dir
	// contains filtered or unexported fields
}

MigrationBoxPkger is a wrapper around pkger.Dir and Migrator. This will allow you to run migrations from migrations packed inside of a compiled binary.

func NewMigrationBoxPkger added in v0.0.183

func NewMigrationBoxPkger(dir pkger.Dir, c *pop.Connection, l *logrusx.Logger, opts ...func(*MigrationBoxPkger) *MigrationBoxPkger) (*MigrationBoxPkger, error)

NewMigrationBoxPkger from a packr.Dir and a Connection.

migrations, err := NewMigrationBoxPkger(pkger.Dir("/migrations"))

type MigrationContent added in v0.0.183

type MigrationContent func(mf Migration, c *pop.Connection, r []byte, usingTemplate bool) (string, error)

type MigrationStatus added in v0.0.185

type MigrationStatus struct {
	State   string
	Version string
	Name    string
}

type MigrationStatuses added in v0.0.185

type MigrationStatuses []MigrationStatus

func (MigrationStatuses) HasPending added in v0.0.185

func (m MigrationStatuses) HasPending() bool

func (MigrationStatuses) Write added in v0.0.185

func (m MigrationStatuses) Write(out io.Writer) error

type Migrations added in v0.0.185

type Migrations []Migration

Migrations is a collection of Migration

func (*Migrations) Filter added in v0.0.185

func (mfs *Migrations) Filter(f func(mf Migration) bool)

func (Migrations) Len added in v0.0.185

func (mfs Migrations) Len() int

func (Migrations) Less added in v0.0.185

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

func (Migrations) Swap added in v0.0.185

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

type Migrator added in v0.0.183

type Migrator struct {
	Connection *pop.Connection
	SchemaPath string
	Migrations map[string]Migrations
	// contains filtered or unexported fields
}

Migrator forms the basis of all migrations systems. It does the actual heavy lifting of running migrations. When building a new migration system, you should embed this type into your migrator.

func NewMigrator added in v0.0.183

func NewMigrator(c *pop.Connection, l *logrusx.Logger) Migrator

NewMigrator returns a new "blank" migrator. It is recommended to use something like MigrationBox or FileMigrator. A "blank" Migrator should only be used as the basis for a new type of migration system.

func (Migrator) CreateSchemaMigrations added in v0.0.183

func (m Migrator) CreateSchemaMigrations(ctx context.Context) error

CreateSchemaMigrations sets up a table to track migrations. This is an idempotent operation.

func (Migrator) Down added in v0.0.183

func (m Migrator) Down(ctx context.Context, step int) error

Down runs pending "down" migrations and rolls back the database by the specified number of steps.

func (Migrator) DumpMigrationSchema added in v0.0.183

func (m Migrator) DumpMigrationSchema(ctx context.Context) error

DumpMigrationSchema will generate a file of the current database schema based on the value of Migrator.SchemaPath

func (Migrator) MigrationIsCompatible added in v0.0.185

func (m Migrator) MigrationIsCompatible(dialect string, mi Migration) bool

func (Migrator) Reset added in v0.0.183

func (m Migrator) Reset(ctx context.Context) error

Reset the database by running the down migrations followed by the up migrations.

func (Migrator) Status added in v0.0.183

func (m Migrator) Status(ctx context.Context) (MigrationStatuses, error)

Status prints out the status of applied/pending migrations.

func (Migrator) Up added in v0.0.183

func (m Migrator) Up(ctx context.Context) error

Up runs pending "up" migrations and applies them to the database.

func (Migrator) UpTo added in v0.0.183

func (m Migrator) UpTo(ctx context.Context, step int) (applied int, err error)

UpTo runs up to step "up" migrations and applies them to the database. If step <= 0 all pending migrations are run.

type TestMigrator

type TestMigrator struct {
	Migrator
}

TestMigrator is a modified pop.FileMigrator

func NewTestMigrator

func NewTestMigrator(t *testing.T, c *pop.Connection, migrationPath, testDataPath string, l *logrusx.Logger) *TestMigrator

Returns a new TestMigrator After running each migration it applies it's corresponding testData sql files. They are identified by having the same version (= number in the front of the filename). The filenames are expected to be of the format ([0-9]+).*(_testdata(\.[dbtype])?.sql

Jump to

Keyboard shortcuts

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