migrations

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrPathNotFound  = utils.Error("Specified migration path not found")
	ErrInvalidPath   = utils.Error("Specified migration path is not a directory")
	ErrInvalidFile   = utils.Error("Specified migration path is not a file")
	ErrReadMigration = utils.Error("Error reading migration")

	MigrationFileExtension = ".sql"
)
View Source
const (
	ModuleBase = "base"

	MsgSkipMigration = iota + 1
	MsgRunMigration
	MsgFinishedMigration
	MsgError

	ErrMigrationNameHashMismatch = utils.Error("Migration name or hash exists but they mismatch. Migration file was edited or renamed?")
	ErrMigrationExists           = utils.Error("Migration already executed")
	ErrRegisterMigration         = utils.Error("Migration executed successfully, but registration failed. Register manually")
)
View Source
const (
	ErrEmptyFolder = utils.Error("Specified folder is empty")
)
View Source
const (
	ErrFileNotFound = utils.Error("file not found")
)

Variables

This section is empty.

Functions

func DefaultProgressFn

func DefaultProgressFn(msgType int, migrationName string, e error)

Types

type DiskSource

type DiskSource struct {
	Path string
}

func (*DiskSource) List

func (d *DiskSource) List() ([]string, error)

List sql files (migrations)

func (*DiskSource) Read

func (d *DiskSource) Read(name string) (*MigrationRecord, error)

Read a migration from disk

type EmbedSource

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

func (*EmbedSource) List

func (d *EmbedSource) List() ([]string, error)

List sql files (migrations)

func (*EmbedSource) Read

func (d *EmbedSource) Read(name string) (*MigrationRecord, error)

Read a migration from disk

type Manager

type Manager interface {
	List(ctx context.Context) ([]MigrationRecord, error)
	MigrationExists(ctx context.Context, name string, sha2 string) (bool, error)
	RunMigration(ctx context.Context, m *MigrationRecord) error
	RegisterMigration(ctx context.Context, m *MigrationRecord) error
	Run(ctx context.Context, src Source, consoleFn ProgressFn) error
}

type MemorySource added in v0.1.4

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

func NewMemorySource added in v0.1.4

func NewMemorySource() *MemorySource

func (*MemorySource) Add added in v0.1.4

func (d *MemorySource) Add(name string, content string)

Add a migration

func (*MemorySource) List added in v0.1.4

func (d *MemorySource) List() ([]string, error)

List sql files (migrations)

func (*MemorySource) Read added in v0.1.4

func (d *MemorySource) Read(name string) (*MigrationRecord, error)

Read a migration

type MigrationRecord

type MigrationRecord struct {
	Created  time.Time `db:"created" ch:"created"`
	Module   string    `db:"module" ch:"module"`
	Name     string    `db:"name" ch:"name"`
	SHA2     string    `db:"sha2" ch:"sha2"`
	Contents string    `db:"contents" ch:"contents"`
}

func LoadMigration

func LoadMigration(name string, content []byte) (*MigrationRecord, error)

LoadMigration from []byte slice

type ProgressFn

type ProgressFn func(msgType int, migrationName string, e error)

type Source

type Source interface {
	List() ([]string, error)
	Read(name string) (*MigrationRecord, error)
}

func NewDiskSource

func NewDiskSource(path string) (Source, error)

func NewEmbedSource

func NewEmbedSource(fs embed.FS, path string) (Source, error)

Jump to

Keyboard shortcuts

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