Documentation
¶
Index ¶
- Constants
- func Run(ctx context.Context, m Migrator, l Loader) error
- type DiskLoader
- type EmbedLoader
- type Loader
- type Migration
- type Migrator
- type MigratorClickHouse
- func (ch *MigratorClickHouse) Exec(ctx context.Context, query string, args ...interface{}) error
- func (ch *MigratorClickHouse) Lock(ctx context.Context) error
- func (ch *MigratorClickHouse) SetVersion(ctx context.Context, version int) error
- func (ch *MigratorClickHouse) Unlock(ctx context.Context) error
- func (ch *MigratorClickHouse) Version(ctx context.Context) (version int, err error)
- type MigratorMySQL
- func (my *MigratorMySQL) Exec(ctx context.Context, query string, args ...interface{}) error
- func (my *MigratorMySQL) Lock(ctx context.Context) error
- func (my *MigratorMySQL) SetVersion(ctx context.Context, version int) error
- func (my *MigratorMySQL) Unlock(ctx context.Context) error
- func (my *MigratorMySQL) Version(ctx context.Context) (version int, err error)
- type MigratorPostgres
- func (pg *MigratorPostgres) Exec(ctx context.Context, query string, args ...interface{}) error
- func (pg *MigratorPostgres) Lock(ctx context.Context) error
- func (pg *MigratorPostgres) SetVersion(ctx context.Context, version int) error
- func (pg *MigratorPostgres) Unlock(ctx context.Context) error
- func (pg *MigratorPostgres) Version(ctx context.Context) (version int, err error)
Constants ¶
const MigrationDelimiter = `--- apply above / rollback below ---`
MigrationDelimiter separates apply and rollback queries inside a migration step/file.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DiskLoader ¶
type DiskLoader struct {
// contains filtered or unexported fields
}
DiskLoader can load migrations from disk/OS.
func NewDiskLoader ¶
func NewDiskLoader(path string) *DiskLoader
NewDiskLoader instantiates a new DiskLoader.
func (*DiskLoader) Load ¶
func (fs *DiskLoader) Load() ([]*Migration, error)
Load is a method for Loader interface.
type EmbedLoader ¶
type EmbedLoader struct {
// contains filtered or unexported fields
}
EmbedLoader can load migrations from embed.FS.
func NewEmbedLoader ¶
func NewEmbedLoader(fs embed.FS, path string) *EmbedLoader
NewEmbedLoader instantiates a new EmbedLoader.
func (*EmbedLoader) Load ¶
func (efs *EmbedLoader) Load() ([]*Migration, error)
Load is a method for Loader interface.
type Migration ¶
type Migration struct { ID int // ID of the migration, unique, positive, starts from 1. Name string // Name of the migration Apply string // Apply query Rollback string // Rollback query }
Migration represents migration step that will be runned on DB.
type Migrator ¶
type Migrator interface { Lock(ctx context.Context) error Unlock(ctx context.Context) error Version(ctx context.Context) (version int, err error) SetVersion(ctx context.Context, version int) error Exec(ctx context.Context, query string, args ...interface{}) error }
Migrator represents DB over which we will run migration queries.
type MigratorClickHouse ¶
type MigratorClickHouse struct {
// contains filtered or unexported fields
}
MigratorClickHouse to migrate ClickHouse.
func NewMigratorClickHouse ¶
func NewMigratorClickHouse(db *sql.DB) *MigratorClickHouse
NewMigratorClickHouse instantiates new MigratorClickHouse.
func (*MigratorClickHouse) Exec ¶
func (ch *MigratorClickHouse) Exec(ctx context.Context, query string, args ...interface{}) error
Exec is a method for Migrator interface.
func (*MigratorClickHouse) Lock ¶
func (ch *MigratorClickHouse) Lock(ctx context.Context) error
Lock is a method for Migrator interface.
func (*MigratorClickHouse) SetVersion ¶
func (ch *MigratorClickHouse) SetVersion(ctx context.Context, version int) error
SetVersion is a method for Migrator interface.
type MigratorMySQL ¶
type MigratorMySQL struct {
// contains filtered or unexported fields
}
MigratorMySQL to migrate MySQL.
func NewMigratorMySQL ¶
func NewMigratorMySQL(db *sql.DB) *MigratorMySQL
NewMigratorMySQL instantiates new MigratorMySQL.
func (*MigratorMySQL) Exec ¶
func (my *MigratorMySQL) Exec(ctx context.Context, query string, args ...interface{}) error
Exec is a method for Migrator interface.
func (*MigratorMySQL) Lock ¶
func (my *MigratorMySQL) Lock(ctx context.Context) error
Lock is a method for Migrator interface.
func (*MigratorMySQL) SetVersion ¶
func (my *MigratorMySQL) SetVersion(ctx context.Context, version int) error
SetVersion is a method for Migrator interface.
type MigratorPostgres ¶
type MigratorPostgres struct {
// contains filtered or unexported fields
}
MigratorPostgres to migrate Postgres.
func NewMigratorPostgres ¶
func NewMigratorPostgres(db *sql.DB) *MigratorPostgres
NewMigratorPostgres instantiates new MigratorPostgres.
func (*MigratorPostgres) Exec ¶
func (pg *MigratorPostgres) Exec(ctx context.Context, query string, args ...interface{}) error
Exec is a method for Migrator interface.
func (*MigratorPostgres) Lock ¶
func (pg *MigratorPostgres) Lock(ctx context.Context) error
Lock is a method for Migrator interface.
func (*MigratorPostgres) SetVersion ¶
func (pg *MigratorPostgres) SetVersion(ctx context.Context, version int) error
SetVersion is a method for Migrator interface.