Documentation
¶
Index ¶
- Constants
- Variables
- func ErrorCoalesce(errs ...error) error
- func SchemaMigrationDelete(ctx context.Context, db sqlx.ExecerContext, version string) error
- func SchemaMigrationInit(ctx context.Context, db sqlx.ExecerContext) error
- func SchemaMigrationInsert(ctx context.Context, db sqlx.ExecerContext, version string) error
- func SchemaMigrationTruncate(ctx context.Context, db sqlx.ExecerContext) error
- func ValidateRefName(refName string) error
- func ValidateStringNonEmpty(what, s string) error
- type ActionMigrateDown
- type ActionMigrateUp
- type ActionVersion
- type Addr
- type Config
- type File
- type Migration
- type MigrationDown
- type MigrationSet
- type MigrationUp
- type Parser
- type SchemaMigration
- type Validator
Constants ¶
const ( InfoName = "krab" InfoFullName = "Oh Krab!" InfoWWW = "https://ohkrab.dev" )
Variables ¶
var ( InfoVersion = "<generated>" InfoCommit = "<generated>" InfoBuildDate = "<generated>" )
Functions ¶
func ErrorCoalesce ¶
ErrorCoalesce returns first non empty error.
func SchemaMigrationDelete ¶
SchemaMigrationDelete removes migration from a database.
func SchemaMigrationInit ¶
func SchemaMigrationInit(ctx context.Context, db sqlx.ExecerContext) error
SchemaMigrationInit creates a migrations table.
func SchemaMigrationInsert ¶
SchemaMigrationInsert saves migration to a database.
func SchemaMigrationTruncate ¶
func SchemaMigrationTruncate(ctx context.Context, db sqlx.ExecerContext) error
SchemaMigrationTruncate truncates migrations table.
func ValidateRefName ¶
ValidateRefName checks if reference name matches allowed format.
func ValidateStringNonEmpty ¶
ValidateStringNonEmpty checks if string is not empty.
Types ¶
type ActionMigrateDown ¶
type ActionMigrateDown struct {
Set *MigrationSet
DownMigration SchemaMigration
}
ActionMigrateDown keeps data needed to perform this action.
func (*ActionMigrateDown) Do ¶
Do performs the action. Schema migration must exist before running it.
func (*ActionMigrateDown) Help ¶
func (a *ActionMigrateDown) Help() string
func (*ActionMigrateDown) Synopsis ¶
func (a *ActionMigrateDown) Synopsis() string
type ActionMigrateUp ¶
type ActionMigrateUp struct {
Set *MigrationSet
}
ActionMigrateUp keeps data needed to perform this action.
func (*ActionMigrateUp) Do ¶
Run performs the action. All pending migrations will be executed. Migration schema is created if does not exist.
func (*ActionMigrateUp) Help ¶
func (a *ActionMigrateUp) Help() string
func (*ActionMigrateUp) Synopsis ¶
func (a *ActionMigrateUp) Synopsis() string
type ActionVersion ¶
type ActionVersion struct{}
ActionVersion prints full version.
func (*ActionVersion) Help ¶
func (a *ActionVersion) Help() string
func (*ActionVersion) Synopsis ¶
func (a *ActionVersion) Synopsis() string
type Addr ¶
Addr represents resource reference.
func (*Addr) OnlyRefNames ¶
OnlyRefNames returns reference name without the keyword.
type Config ¶
type Config struct {
MigrationSets map[string]*MigrationSet
Migrations map[string]*Migration
}
Config represents all configuration loaded from directory.
type File ¶
type File struct {
Migrations []*Migration `hcl:"migration,block"`
MigrationSets []*MigrationSet `hcl:"migration_set,block"`
}
File represents all resource definication within a single file.
type Migration ¶
type Migration struct {
RefName string `hcl:"ref_name,label"`
Version string `hcl:"version"`
Up MigrationUp `hcl:"up,block"`
Down MigrationDown `hcl:"down,block"`
Transaction *bool `hcl:"transaction,optional"` // wrap operaiton in transaction
}
Migration represents single up/down migration pair.
func SchemaMigrationFilterPending ¶
func SchemaMigrationFilterPending(all []*Migration, refsInDb []SchemaMigration) []*Migration
SchemaMigrationFilterPending removes `refsInDb` migrations from `all` and return new slice with pending ones only.
func (*Migration) ShouldRunInTransaction ¶ added in v0.3.0
ShouldRunInTransaction returns whether migration should be wrapped into transaction or not.
type MigrationDown ¶
type MigrationDown struct {
SQL string `hcl:"sql,optional"`
}
MigrationDown contains info how to migrate down.
type MigrationSet ¶
type MigrationSet struct {
RefName string `hcl:"ref_name,label"`
// SchemaMigrationsTable string `hcl:"schema_migrations_table"`
MigrationsExpr hcl.Expression `hcl:"migrations"`
Migrations []*Migration // populated from refs in expression
}
MigrationSet represents collection of migrations.
func (*MigrationSet) FindMigrationByVersion ¶
func (ms *MigrationSet) FindMigrationByVersion(version string) *Migration
FindMigrationByVersion looks up for the migration in current set.
func (*MigrationSet) Validate ¶
func (ms *MigrationSet) Validate() error
type MigrationUp ¶
type MigrationUp struct {
SQL string `hcl:"sql,optional"`
}
MigrationUp contains info how to migrate up.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents HCL simple parser.
type SchemaMigration ¶
type SchemaMigration struct {
Version string `db:"version"`
}
SchemaMigration represents a single row from migrations table.
func SchemaMigrationSelectAll ¶
func SchemaMigrationSelectAll(ctx context.Context, db sqlx.QueryerContext) ([]SchemaMigration, error)
SchemaMigrationSelectAll fetches all migrations from a database.