util

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyMultiStatements

func ApplyMultiStatements(sc *bufio.Scanner, f func(string) error) error

ApplyMultiStatements will apply the splitted statements from scanner.

func ExecuteMigration

func ExecuteMigration(ctx context.Context, l *zap.Logger, executor MigrationExecutor, m *db.MigrationInfo, statement string) (migrationHistoryID int64, updatedSchema string, resErr error)

ExecuteMigration will execute the database migration. Returns the created migraiton history id and the updated schema on success.

func FindMigrationHistoryList

func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery string, queryParams []interface{}, driver db.Driver, find *db.MigrationHistoryFind, baseQuery string) ([]*db.MigrationHistory, error)

FindMigrationHistoryList will find the list of migration history.

func FormatErrorWithQuery

func FormatErrorWithQuery(err error, query string) error

FormatErrorWithQuery will format the error with failed query.

func NeedsSetupMigrationSchema

func NeedsSetupMigrationSchema(ctx context.Context, sqldb *sql.DB, query string) (bool, error)

NeedsSetupMigrationSchema will return whether it's needed to setup migration schema.

func Query

func Query(ctx context.Context, l *zap.Logger, sqldb *sql.DB, statement string, limit int) ([]interface{}, error)

Query will execute a readonly / SELECT query.

Types

type MigrationExecutor

type MigrationExecutor interface {
	db.Driver
	// CheckOutOfOrderVersion will return versions that are higher than the given version.
	CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (minVersionIfValid *string, err error)
	// FindBaseline retruns true if any baseline is found.
	FindBaseline(ctx context.Context, tx *sql.Tx, namespace string) (hasBaseline bool, err error)
	// FindNextSequence will return the highest sequence number plus one.
	FindNextSequence(ctx context.Context, tx *sql.Tx, namespace string, requireBaseline bool) (int, error)
	// InsertPendingHistory will insert the migration record with pending status and return the inserted ID.
	InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, statement string) (insertedID int64, err error)
	// UpdateHistoryAsDone will update the migration record as done.
	UpdateHistoryAsDone(ctx context.Context, tx *sql.Tx, migrationDurationNs int64, updatedSchema string, insertedID int64) error
	// UpdateHistoryAsFailed will update the migration record as failed.
	UpdateHistoryAsFailed(ctx context.Context, tx *sql.Tx, migrationDurationNs int64, insertedID int64) error
}

MigrationExecutor is an adapter for ExecuteMigration().

Jump to

Keyboard shortcuts

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