service

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMigrationVersionReserved = errors.New("migration version reserved")

Functions

This section is empty.

Types

type Console

type Console interface {
	Confirm(s string) bool
	Info(message string)
	InfoLn(message string)
	Infof(message string, a ...any)
	Success(message string)
	SuccessLn(message string)
	Successf(message string, a ...any)
	Warn(message string)
	WarnLn(message string)
	Warnf(message string, a ...any)
	Error(message string)
	ErrorLn(message string)
	Errorf(message string, a ...any)
	Fatal(err error)
	NumberPlural(count int, one, many string) string
}

type File

type File interface {
	Exists(fileName string) (bool, error)
	Open(filename string) (io.ReadCloser, error)
	ReadAll(filename string) ([]byte, error)
}

type Migration

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

func NewMigration

func NewMigration(
	options *Options,
	console Console,
	file File,
	repo Repository,
) *Migration

func (*Migration) ApplyFile

func (m *Migration) ApplyFile(ctx context.Context, entity *entity.Migration, fileName string, safely bool) error

func (*Migration) ApplySQL

func (m *Migration) ApplySQL(
	ctx context.Context,
	safely bool,
	version,
	upSQL string,
) error

func (*Migration) BeginCommand

func (m *Migration) BeginCommand(sqlQuery string) time.Time

func (*Migration) EndCommand

func (m *Migration) EndCommand(start time.Time)

func (*Migration) ExecQuery

func (m *Migration) ExecQuery(ctx context.Context, sqlQuery string) error

func (*Migration) Exists added in v0.4.0

func (m *Migration) Exists(ctx context.Context, version string) (bool, error)

func (*Migration) InitializeTableHistory

func (m *Migration) InitializeTableHistory(ctx context.Context) error

func (*Migration) Migrations

func (m *Migration) Migrations(ctx context.Context, limit int) (entity.Migrations, error)

func (*Migration) NewMigrations

func (m *Migration) NewMigrations(ctx context.Context) (entity.Migrations, error)

func (*Migration) RevertFile

func (m *Migration) RevertFile(ctx context.Context, entity *entity.Migration, fileName string, safely bool) error

func (*Migration) RevertSQL

func (m *Migration) RevertSQL(
	ctx context.Context,
	safely bool,
	version,
	downSQL string,
) error

func (*Migration) SQLQueryOutput

func (m *Migration) SQLQueryOutput(sqlQuery string) string

type Options

type Options struct {
	MaxSQLOutputLength int
	Directory          string
	Compact            bool

	Username string
	Password string
}

type Repository

type Repository interface {
	// ExistsMigration returns true if version of migration exists
	ExistsMigration(ctx context.Context, version string) (bool, error)
	// Migrations returns applied migrations history.
	Migrations(ctx context.Context, limit int) (entity.Migrations, error)
	// HasMigrationHistoryTable returns true if migration history table exists.
	HasMigrationHistoryTable(ctx context.Context) (exists bool, err error)
	// InsertMigration inserts the new migration record.
	InsertMigration(ctx context.Context, version string) error
	// RemoveMigration removes the migration record.
	RemoveMigration(ctx context.Context, version string) error
	// ExecQuery executes a query without returning any rows.
	// The args are for any placeholder parameters in the query.
	ExecQuery(ctx context.Context, query string, args ...any) error
	ExecQueryTransaction(ctx context.Context, fnTx func(ctx context.Context) error) error
	DropMigrationHistoryTable(ctx context.Context) error
	CreateMigrationHistoryTable(ctx context.Context) error
	MigrationsCount(ctx context.Context) (int, error)
	TableNameWithSchema() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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