migrate

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

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

func NewLoader

func NewLoader(fsys fs.FS) *Loader

func (*Loader) Load

func (l *Loader) Load() ([]Migration, error)

type Meta

type Meta struct {
	Filename string
	Version  int
	Name     string
}

type MigrateCommand

type MigrateCommand struct {
	Database string `cli:"required,short=d,env=PGT_DATABASE,help=database connection string"`
	Source   string `cli:"required,short=s,env=PGT_MIGRATION_SOURCE,help=path to migrations directory"`
	Target   *int   `cli:"short=t,env=PGT_MIGRATION_TARGET,help=version to target,default=latest"`

	VersionTable string `cli:"env=PGT_VERSION_TABLE"`

	Yes bool `cli:"short=y,help=bypass all confirmation prompts"`

	Test               bool `cli:"env=PGT_TEST,help=enable test mode"`
	TestDatabaseName   string
	RetainTestDatabase bool

	Dump        string `cli:"env=PGT_DUMP,help=file path to dump schema to"`
	DumpCommand string `cli:"env=PGT_DUMP_COMMAND,help=command used to dump schema"`

	MaxBlockDuration  time.Duration `cli:"env=PGT_MAX_BLOCK_DURATION"`
	MaxBlockProcesses int           `cli:"env=PGT_MAX_BLOCK_PROCESSES"`
	// contains filtered or unexported fields
}

func NewMigrateCommand

func NewMigrateCommand(interactive bool) *MigrateCommand

func (*MigrateCommand) Run

func (cmd *MigrateCommand) Run(ctx context.Context) error

func (*MigrateCommand) SetupCommand

func (*MigrateCommand) SetupCommand(cmd *cli.Command)

type Migration

type Migration struct {
	Meta
	Up   Step
	Down Step
}

type MigrationError

type MigrationError struct {
	Err error
	Meta
	LineNum   int
	ColumnNum int
}

func (MigrationError) Error

func (e MigrationError) Error() string

type Migrator

type Migrator struct {
	BeforeExec func(meta Meta, step Step) error
	// contains filtered or unexported fields
}

func NewMigrator

func NewMigrator(conn *pgx.Conn, versionTableName string, migrations []Migration) *Migrator

func (*Migrator) MaxVersion

func (m *Migrator) MaxVersion() int

func (*Migrator) MigrateTo

func (m *Migrator) MigrateTo(ctx context.Context, targetVersion int) (err error)

func (*Migrator) Migration

func (m *Migrator) Migration(version int) Migration

type Step

type Step struct {
	Name       string
	Config     StepConfig
	SQL        string
	LineNumber int
}

func (Step) PositionToLineCol

func (s Step) PositionToLineCol(pos int) (int, int)

type StepConfig

type StepConfig struct {
	DisableTransaction bool
}

type VersionTableManager

type VersionTableManager struct {
	TableName string
}

func (*VersionTableManager) CheckExists

func (m *VersionTableManager) CheckExists(ctx context.Context, conn *pgx.Conn) (ok bool, err error)

func (*VersionTableManager) FinishVersionDown

func (m *VersionTableManager) FinishVersionDown(ctx context.Context, conn *pgx.Conn, version int) error

func (*VersionTableManager) FinishVersionUp

func (m *VersionTableManager) FinishVersionUp(ctx context.Context, conn *pgx.Conn, version int) error

func (*VersionTableManager) GetCurrentVersion

func (m *VersionTableManager) GetCurrentVersion(ctx context.Context, conn *pgx.Conn) (int, error)

func (*VersionTableManager) InsertVersionUp

func (m *VersionTableManager) InsertVersionUp(ctx context.Context, conn *pgx.Conn, version int) error

func (*VersionTableManager) Migration

func (m *VersionTableManager) Migration() Migration

func (*VersionTableManager) StartVersionDown

func (m *VersionTableManager) StartVersionDown(ctx context.Context, conn *pgx.Conn, version int) error

func (*VersionTableManager) StartVersionUp

func (m *VersionTableManager) StartVersionUp(ctx context.Context, conn *pgx.Conn, version int) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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