Documentation ¶
Index ¶
- Constants
- Variables
- func EmptyArgs() map[string]interface{}
- func ErrorCoalesce(errs ...error) error
- func ValidateRefName(refName string) error
- func ValidateStringNonEmpty(what, s string) error
- type Action
- type ActionCustom
- type ActionGenMigration
- type ActionMigrateDown
- type ActionMigrateStatus
- type ActionMigrateUp
- type ActionTestRun
- type ActionVersion
- type Argument
- type Arguments
- type Cmd
- type CmdAction
- type CmdGenMigration
- type CmdMigrateDown
- type CmdMigrateStatus
- type CmdMigrateUp
- type CmdOpts
- type CmdRegistry
- type CmdTestRun
- type CmdVersion
- type Config
- type DDLCheck
- type DDLColumn
- type DDLCreateIndex
- type DDLCreateTable
- type DDLDropIndex
- type DDLDropTable
- type DDLForeignKey
- type DDLGeneratedColumn
- type DDLIdentity
- type DDLPrimaryKey
- type DDLReferences
- type DDLUnique
- type Do
- type DoMigrate
- type File
- type HookRunner
- type Hooks
- type Migration
- type MigrationSet
- type MigrationUpOrDown
- type NamedInputs
- type Parser
- type PositionalInputs
- type ResponseAction
- type ResponseGenMigration
- type ResponseMigrateDown
- type ResponseMigrateStatus
- type ResponseMigrateUp
- type ResponseTestRun
- type ResponseVersion
- type SQLStatement
- type SQLStatements
- type SQLStatementsSorter
- type SchemaMigration
- type SchemaMigrationTable
- func (s SchemaMigrationTable) Delete(ctx context.Context, db krabdb.ExecerContext, version string) error
- func (s SchemaMigrationTable) Exists(ctx context.Context, db krabdb.QueryerContext, migration SchemaMigration) (bool, error)
- func (s SchemaMigrationTable) FilterPending(all []*Migration, refsInDb []SchemaMigration) []*Migration
- func (s SchemaMigrationTable) Init(ctx context.Context, db krabdb.ExecerContext) error
- func (s SchemaMigrationTable) Insert(ctx context.Context, db krabdb.ExecerContext, version string) error
- func (s SchemaMigrationTable) SelectAll(ctx context.Context, db krabdb.QueryerContext) ([]SchemaMigration, error)
- func (s SchemaMigrationTable) SelectLastN(ctx context.Context, db krabdb.QueryerContext, limit int) ([]SchemaMigration, error)
- func (s SchemaMigrationTable) Truncate(ctx context.Context, db krabdb.ExecerContext) error
- type SetRuntimeParameters
- type Templates
- type TestExample
- type TestExampleIt
- type TestQuery
- type TestQueryCol
- type TestQueryRow
- type TestSuite
- type TimestampVersionGenerator
- type ToKCL
- type ToSQL
- type Validator
- type VersionGenerator
Constants ¶
const ( InfoName = "krab" InfoFullName = "Oh Krab!" InfoWWW = "https://ohkrab.dev" )
const DefaultSchemaMigrationTableName = "schema_migrations"
Variables ¶
var ( InfoVersion = "<generated>" InfoCommit = "<generated>" InfoBuildDate = "<generated>" )
Functions ¶
func ErrorCoalesce ¶
ErrorCoalesce returns first non empty error.
func ValidateRefName ¶
ValidateRefName checks if reference name matches allowed format.
func ValidateStringNonEmpty ¶
ValidateStringNonEmpty checks if string is not empty.
Types ¶
type Action ¶ added in v0.4.0
type Action struct { krabhcl.Source Namespace string RefName string Arguments *Arguments Description string SQL string Transaction bool // wrap operation in transaction }
Action represents custom action to execute.
func (*Action) ToSQL ¶ added in v0.4.0
func (m *Action) ToSQL(w io.StringWriter)
type ActionCustom ¶ added in v0.4.0
ActionCustom keeps data needed to perform this action.
func (*ActionCustom) Help ¶ added in v0.4.0
func (a *ActionCustom) Help() string
func (*ActionCustom) Run ¶ added in v0.4.0
func (a *ActionCustom) Run(args []string) int
Run in CLI.
func (*ActionCustom) Synopsis ¶ added in v0.4.0
func (a *ActionCustom) Synopsis() string
type ActionGenMigration ¶ added in v0.6.0
type ActionGenMigration struct { Ui cli.UI Cmd *CmdGenMigration }
ActionGenMigration generates migration file.
func (*ActionGenMigration) Help ¶ added in v0.6.0
func (a *ActionGenMigration) Help() string
func (*ActionGenMigration) Run ¶ added in v0.6.0
func (a *ActionGenMigration) Run(args []string) int
Run in CLI.
func (*ActionGenMigration) Synopsis ¶ added in v0.6.0
func (a *ActionGenMigration) Synopsis() string
type ActionMigrateDown ¶
type ActionMigrateDown struct { Ui cli.UI Cmd *CmdMigrateDown }
ActionMigrateDown keeps data needed to perform this action.
func (*ActionMigrateDown) Help ¶
func (a *ActionMigrateDown) Help() string
func (*ActionMigrateDown) Synopsis ¶
func (a *ActionMigrateDown) Synopsis() string
type ActionMigrateStatus ¶ added in v0.4.1
type ActionMigrateStatus struct { Ui cli.UI Cmd *CmdMigrateStatus }
ActionMigrateStatus keeps data needed to perform this action.
func (*ActionMigrateStatus) Help ¶ added in v0.4.1
func (a *ActionMigrateStatus) Help() string
func (*ActionMigrateStatus) Run ¶ added in v0.4.1
func (a *ActionMigrateStatus) Run(args []string) int
Run in CLI.
func (*ActionMigrateStatus) Synopsis ¶ added in v0.4.1
func (a *ActionMigrateStatus) Synopsis() string
type ActionMigrateUp ¶
type ActionMigrateUp struct { Ui cli.UI Cmd *CmdMigrateUp }
ActionMigrateUp keeps data needed to perform this action.
func (*ActionMigrateUp) Help ¶
func (a *ActionMigrateUp) Help() string
func (*ActionMigrateUp) Synopsis ¶
func (a *ActionMigrateUp) Synopsis() string
type ActionTestRun ¶ added in v0.5.0
type ActionTestRun struct { Ui cli.UI Cmd *CmdTestRun }
ActionTestRun outputs test runner.
func (*ActionTestRun) Help ¶ added in v0.5.0
func (a *ActionTestRun) Help() string
func (*ActionTestRun) Run ¶ added in v0.5.0
func (a *ActionTestRun) Run(args []string) int
Run in CLI.
func (*ActionTestRun) Synopsis ¶ added in v0.5.0
func (a *ActionTestRun) Synopsis() string
type ActionVersion ¶
type ActionVersion struct { Ui cli.UI Cmd *CmdVersion }
ActionVersion prints full version.
func (*ActionVersion) Help ¶
func (a *ActionVersion) Help() string
func (*ActionVersion) Synopsis ¶
func (a *ActionVersion) Synopsis() string
type Argument ¶ added in v0.4.0
type Arguments ¶ added in v0.4.0
type Arguments struct {
Args []*Argument
}
Arguments represents command line arguments or params that you can pass to action.
func (*Arguments) Validate ¶ added in v0.4.0
func (a *Arguments) Validate(values NamedInputs) error
type Cmd ¶ added in v0.5.0
type Cmd interface { // Addr associated with name Addr() krabhcl.Addr // Name that is mounted at API path or CLI. Name() []string // HttpMethod that is used for API call. HttpMethod() string // Do executes the action. Do(ctx context.Context, opts CmdOpts) (interface{}, error) }
Cmd is a command that app can execute.
type CmdAction ¶ added in v0.5.0
type CmdAction struct { Action *Action Connection krabdb.Connection }
CmdAction returns migration status information.
func (*CmdAction) HttpMethod ¶ added in v0.5.0
type CmdGenMigration ¶ added in v0.6.0
type CmdGenMigration struct { FS afero.Afero VersionGenerator }
CmdGenMigration generates migation file.
func (*CmdGenMigration) Addr ¶ added in v0.6.0
func (c *CmdGenMigration) Addr() krabhcl.Addr
func (*CmdGenMigration) Arguments ¶ added in v0.6.0
func (c *CmdGenMigration) Arguments() *Arguments
func (*CmdGenMigration) Do ¶ added in v0.6.0
func (c *CmdGenMigration) Do(ctx context.Context, o CmdOpts) (interface{}, error)
func (*CmdGenMigration) HttpMethod ¶ added in v0.6.0
func (c *CmdGenMigration) HttpMethod() string
func (*CmdGenMigration) Name ¶ added in v0.6.0
func (c *CmdGenMigration) Name() []string
type CmdMigrateDown ¶ added in v0.5.0
type CmdMigrateDown struct { Set *MigrationSet Connection krabdb.Connection }
CmdMigrateDown returns migration status information.
func (*CmdMigrateDown) Addr ¶ added in v0.5.0
func (c *CmdMigrateDown) Addr() krabhcl.Addr
func (*CmdMigrateDown) Arguments ¶ added in v0.5.0
func (c *CmdMigrateDown) Arguments() *Arguments
func (*CmdMigrateDown) Do ¶ added in v0.5.0
func (c *CmdMigrateDown) Do(ctx context.Context, o CmdOpts) (interface{}, error)
func (*CmdMigrateDown) HttpMethod ¶ added in v0.5.0
func (c *CmdMigrateDown) HttpMethod() string
func (*CmdMigrateDown) Name ¶ added in v0.5.0
func (c *CmdMigrateDown) Name() []string
type CmdMigrateStatus ¶ added in v0.5.0
type CmdMigrateStatus struct { Set *MigrationSet Connection krabdb.Connection }
CmdMigrateStatus returns migration status information.
func (*CmdMigrateStatus) Addr ¶ added in v0.5.0
func (c *CmdMigrateStatus) Addr() krabhcl.Addr
func (*CmdMigrateStatus) Do ¶ added in v0.5.0
func (c *CmdMigrateStatus) Do(ctx context.Context, o CmdOpts) (interface{}, error)
func (*CmdMigrateStatus) HttpMethod ¶ added in v0.5.0
func (c *CmdMigrateStatus) HttpMethod() string
func (*CmdMigrateStatus) Name ¶ added in v0.5.0
func (c *CmdMigrateStatus) Name() []string
type CmdMigrateUp ¶ added in v0.5.0
type CmdMigrateUp struct { Set *MigrationSet Connection krabdb.Connection }
CmdMigrateUp returns migration status information.
func (*CmdMigrateUp) Addr ¶ added in v0.5.0
func (c *CmdMigrateUp) Addr() krabhcl.Addr
func (*CmdMigrateUp) Do ¶ added in v0.5.0
func (c *CmdMigrateUp) Do(ctx context.Context, o CmdOpts) (interface{}, error)
func (*CmdMigrateUp) HttpMethod ¶ added in v0.5.0
func (c *CmdMigrateUp) HttpMethod() string
func (*CmdMigrateUp) Name ¶ added in v0.5.0
func (c *CmdMigrateUp) Name() []string
type CmdOpts ¶ added in v0.5.0
type CmdOpts struct { NamedInputs PositionalInputs }
CmdOpts are options passed to command.
type CmdRegistry ¶ added in v0.5.0
type CmdRegistry struct { Commands []Cmd FS afero.Afero VersionGenerator }
CmdRegistry is a list of registred commands.
func (*CmdRegistry) Register ¶ added in v0.5.0
func (r *CmdRegistry) Register(c Cmd)
Register appends new command to registry.
func (*CmdRegistry) RegisterAll ¶ added in v0.5.0
func (r *CmdRegistry) RegisterAll(config *Config, conn krabdb.Connection)
RegisterAll registers all commands in the registry.
type CmdTestRun ¶ added in v0.5.0
type CmdTestRun struct { Connection krabdb.Connection Suite *TestSuite }
CmdTestRun returns migration status information.
func (*CmdTestRun) Addr ¶ added in v0.5.0
func (c *CmdTestRun) Addr() krabhcl.Addr
func (*CmdTestRun) Do ¶ added in v0.5.0
func (c *CmdTestRun) Do(ctx context.Context, o CmdOpts) (interface{}, error)
func (*CmdTestRun) HttpMethod ¶ added in v0.5.0
func (c *CmdTestRun) HttpMethod() string
func (*CmdTestRun) Name ¶ added in v0.5.0
func (c *CmdTestRun) Name() []string
type CmdVersion ¶ added in v0.5.0
type CmdVersion struct{}
CmdVersion returns version information.
func (*CmdVersion) Addr ¶ added in v0.5.0
func (c *CmdVersion) Addr() krabhcl.Addr
func (*CmdVersion) Do ¶ added in v0.5.0
func (c *CmdVersion) Do(ctx context.Context, o CmdOpts) (interface{}, error)
func (*CmdVersion) HttpMethod ¶ added in v0.5.0
func (c *CmdVersion) HttpMethod() string
func (*CmdVersion) Name ¶ added in v0.5.0
func (c *CmdVersion) Name() []string
type Config ¶
type Config struct { MigrationSets map[string]*MigrationSet Migrations map[string]*Migration Actions map[string]*Action TestSuite *TestSuite TestExamples map[string]*TestExample }
Config represents all configuration loaded from directory.
type DDLCheck ¶ added in v0.4.0
DDLCheck constraint DSL for table DDL.
func (*DDLCheck) ToSQL ¶ added in v0.4.0
func (d *DDLCheck) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLColumn ¶ added in v0.4.0
type DDLColumn struct { krabhcl.Source Name string Type string Null bool Default string Identity *DDLIdentity Generated *DDLGeneratedColumn }
DDLColumn DSL for table DDL.
func (*DDLColumn) ToKCL ¶ added in v0.6.1
func (d *DDLColumn) ToKCL(w io.StringWriter)
ToKCL converts migration definition to KCL.
func (*DDLColumn) ToSQL ¶ added in v0.4.0
func (d *DDLColumn) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLCreateIndex ¶ added in v0.4.0
type DDLCreateIndex struct { krabhcl.Source Table string Name string Unique bool Concurrently bool Columns []string Include []string Using string Where string }
DDLCreateIndex contains DSL for creating indicies.
func (*DDLCreateIndex) DecodeHCL ¶ added in v0.5.0
func (d *DDLCreateIndex) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*DDLCreateIndex) ToSQL ¶ added in v0.4.0
func (d *DDLCreateIndex) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLCreateTable ¶ added in v0.4.0
type DDLCreateTable struct { krabhcl.Source Name string Unlogged bool Columns []*DDLColumn PrimaryKeys []*DDLPrimaryKey ForeignKeys []*DDLForeignKey Uniques []*DDLUnique Checks []*DDLCheck }
DDLCreateTable contains DSL for creating tables.
func (*DDLCreateTable) DecodeHCL ¶ added in v0.5.0
func (d *DDLCreateTable) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*DDLCreateTable) ToKCL ¶ added in v0.6.1
func (d *DDLCreateTable) ToKCL(w io.StringWriter)
ToKCL converts migration definition to KCL.
func (*DDLCreateTable) ToSQL ¶ added in v0.4.0
func (d *DDLCreateTable) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLDropIndex ¶ added in v0.4.0
DDLDropIndex contains DSL for dropping indicies.
func (*DDLDropIndex) DecodeHCL ¶ added in v0.5.0
func (d *DDLDropIndex) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*DDLDropIndex) ToSQL ¶ added in v0.4.0
func (d *DDLDropIndex) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLDropTable ¶ added in v0.4.0
DDLDropTable contains DSL for dropping tables.
func (*DDLDropTable) DecodeHCL ¶ added in v0.5.0
func (d *DDLDropTable) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*DDLDropTable) ToKCL ¶ added in v0.6.1
func (d *DDLDropTable) ToKCL(w io.StringWriter)
func (*DDLDropTable) ToSQL ¶ added in v0.4.0
func (d *DDLDropTable) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLForeignKey ¶ added in v0.4.0
type DDLForeignKey struct { krabhcl.Source Columns []string References DDLReferences }
DDLForeignKey constraint DSL for table DDL.
func (*DDLForeignKey) DecodeHCL ¶ added in v0.5.0
func (d *DDLForeignKey) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*DDLForeignKey) ToSQL ¶ added in v0.4.0
func (d *DDLForeignKey) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLGeneratedColumn ¶ added in v0.4.0
DDLGeneratedColumn DSL.
func (*DDLGeneratedColumn) DecodeHCL ¶ added in v0.5.0
func (d *DDLGeneratedColumn) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*DDLGeneratedColumn) ToSQL ¶ added in v0.4.0
func (d *DDLGeneratedColumn) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLIdentity ¶ added in v0.4.0
DDLIdentity DSL.
func (*DDLIdentity) DecodeHCL ¶ added in v0.5.0
func (d *DDLIdentity) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*DDLIdentity) ToKCL ¶ added in v0.6.1
func (d *DDLIdentity) ToKCL(w io.StringWriter)
ToKCL converts migration definition to KCL.
func (*DDLIdentity) ToSQL ¶ added in v0.4.0
func (d *DDLIdentity) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLPrimaryKey ¶ added in v0.4.0
DDLPrimaryKey constraint DSL for table DDL.
func (*DDLPrimaryKey) DecodeHCL ¶ added in v0.5.0
func (d *DDLPrimaryKey) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*DDLPrimaryKey) ToKCL ¶ added in v0.6.1
func (d *DDLPrimaryKey) ToKCL(w io.StringWriter)
ToKCL converts migration definition to KCL.
func (*DDLPrimaryKey) ToSQL ¶ added in v0.4.0
func (d *DDLPrimaryKey) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLReferences ¶ added in v0.4.0
type DDLReferences struct { krabhcl.Source Table string Columns []string OnDelete string OnUpdate string }
DDLReferences DSL for ForeignKey.
func (*DDLReferences) DecodeHCL ¶ added in v0.5.0
func (d *DDLReferences) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*DDLReferences) ToSQL ¶ added in v0.4.0
func (d *DDLReferences) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type DDLUnique ¶ added in v0.4.0
DDLUnique constraint DSL for table DDL.
func (*DDLUnique) ToSQL ¶ added in v0.4.0
func (d *DDLUnique) ToSQL(w io.StringWriter)
ToSQL converts migration definition to SQL.
type Do ¶ added in v0.5.0
type Do struct { Migrate []*DoMigrate `hcl:"migrate,block"` CtyInputs map[string]cty.Value `hcl:"inputs,optional"` SQL string `hcl:"sql,optional"` }
Do subtype for other types.
type DoMigrate ¶ added in v0.5.0
type DoMigrate struct { Type string `hcl:"type,label"` SetExpr hcl.Expression `hcl:"migration_set"` CtyInputs map[string]cty.Value `hcl:"inputs,optional"` Set *MigrationSet }
type File ¶
type File struct { File *hcl.File Migrations []*Migration MigrationSets []*MigrationSet Actions []*Action TestSuite *TestSuite TestExamples []*TestExample }
File represents all resource definitions within a single file.
type HookRunner ¶ added in v0.4.0
type HookRunner struct {
Hooks *Hooks
}
func (HookRunner) SetSearchPath ¶ added in v0.4.0
func (h HookRunner) SetSearchPath(ctx context.Context, db sqlx.ExecerContext, schema string) error
SetSearchPath sets Postgres search_path.
type Migration ¶
type Migration struct { krabhcl.Source RefName string Version string Up MigrationUpOrDown Down MigrationUpOrDown Transaction bool // wrap operation in transaction }
Migration represents single up/down migration pair.
func (*Migration) ToKCL ¶ added in v0.6.1
func (m *Migration) ToKCL(w io.StringWriter)
type MigrationSet ¶
type MigrationSet struct { krabhcl.Source RefName string Schema string Arguments *Arguments Hooks *Hooks MigrationAddrs []*krabhcl.Addr Migrations []*Migration // populated from refs in expression }
MigrationSet represents collection of migrations.
func (*MigrationSet) Addr ¶ added in v0.5.0
func (ms *MigrationSet) Addr() krabhcl.Addr
func (*MigrationSet) DecodeHCL ¶ added in v0.5.0
func (ms *MigrationSet) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
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 MigrationUpOrDown ¶ added in v0.4.0
type MigrationUpOrDown struct { krabhcl.Source SQL string CreateTables []*DDLCreateTable CreateIndices []*DDLCreateIndex DropTables []*DDLDropTable DropIndices []*DDLDropIndex AttrDefRanges map[string]hcl.Range }
Migration contains info how to migrate up or down.
func (*MigrationUpOrDown) DecodeHCL ¶ added in v0.5.0
func (m *MigrationUpOrDown) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
DecodeHCL parses HCL into struct.
func (*MigrationUpOrDown) ToKCL ¶ added in v0.6.1
func (m *MigrationUpOrDown) ToKCL(w io.StringWriter)
func (*MigrationUpOrDown) ToSQL ¶ added in v0.4.0
func (m *MigrationUpOrDown) ToSQL(w io.StringWriter)
func (*MigrationUpOrDown) ToSQLStatements ¶ added in v0.4.0
func (m *MigrationUpOrDown) ToSQLStatements() SQLStatements
ToSQLStatements returns list of SQL statements to executre during the migration.
func (*MigrationUpOrDown) Validate ¶ added in v0.4.0
func (m *MigrationUpOrDown) Validate() error
type NamedInputs ¶ added in v0.6.1
type NamedInputs map[string]interface{}
NamedInputs are params passed to command.
func InputsFromCtyInputs ¶ added in v0.5.0
func InputsFromCtyInputs(vals map[string]cty.Value) NamedInputs
func (NamedInputs) Merge ¶ added in v0.6.1
func (i NamedInputs) Merge(other NamedInputs)
type PositionalInputs ¶ added in v0.6.1
type PositionalInputs []string
Inputs are params passed to command.
type ResponseGenMigration ¶ added in v0.6.0
ResponseGenMigration json
type ResponseMigrateDown ¶ added in v0.5.0
type ResponseMigrateDown struct { Name string `json:"name"` Version string `json:"version"` Success bool `json:"success"` }
ResponseMigrateDown json
type ResponseMigrateStatus ¶ added in v0.5.0
type ResponseMigrateStatus struct { Name string `json:"name"` Version string `json:"version"` Pending bool `json:"pending"` }
ResponseMigrateStatus json
type ResponseMigrateUp ¶ added in v0.5.0
type ResponseMigrateUp struct { Name string `json:"name"` Version string `json:"version"` Success bool `json:"success"` }
ResponseMigrateUp json
type ResponseVersion ¶ added in v0.5.0
ResponseVersion json
type SQLStatement ¶ added in v0.4.0
type SQLStatement string
SQLStatement represents raw SQL statement.
type SQLStatements ¶ added in v0.4.0
type SQLStatements []SQLStatement
SQLStatements represents list of raw SQL statements.
func (*SQLStatements) Append ¶ added in v0.4.0
func (s *SQLStatements) Append(sql ToSQL)
Append adds new SQL statement to the list from object that satisfies ToSQL interface.
type SQLStatementsSorter ¶ added in v0.4.0
type SQLStatementsSorter struct { Statements SQLStatements Bytes []int }
SQLStatementsSorter sorts SQLStatement by the order how they are defined in a file.
func (*SQLStatementsSorter) Insert ¶ added in v0.4.0
func (s *SQLStatementsSorter) Insert(r hcl.Range, sql ToSQL)
Insert ToSQL at given range.
func (*SQLStatementsSorter) Len ¶ added in v0.4.0
func (s *SQLStatementsSorter) Len() int
Len is the number of elements in the collection.
func (*SQLStatementsSorter) Less ¶ added in v0.4.0
func (s *SQLStatementsSorter) Less(i int, j int) bool
Less reports whether the element with index i must sort before the element with index j.
If both Less(i, j) and Less(j, i) are false, then the elements at index i and j are considered equal. Sort may place equal elements in any order in the final result, while Stable preserves the original input order of equal elements.
Less must describe a transitive ordering:
- if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
- if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
Note that floating-point comparison (the < operator on float32 or float64 values) is not a transitive ordering when not-a-number (NaN) values are involved. See Float64Slice.Less for a correct implementation for floating-point values.
func (*SQLStatementsSorter) Sort ¶ added in v0.4.0
func (s *SQLStatementsSorter) Sort() SQLStatements
Sort sorts statements by byte range.
func (*SQLStatementsSorter) Swap ¶ added in v0.4.0
func (s *SQLStatementsSorter) Swap(i int, j int)
Swap swaps the elements with indexes i and j.
type SchemaMigration ¶
type SchemaMigration struct {
Version string `db:"version"`
}
SchemaMigration represents a single row from migrations table.
type SchemaMigrationTable ¶ added in v0.4.0
type SchemaMigrationTable struct {
Name string
}
func NewSchemaMigrationTable ¶ added in v0.4.0
func NewSchemaMigrationTable(schema string) SchemaMigrationTable
NewSchemaMigrationTable creates SchemaMigrationTable with default table name and specified schema.
func (SchemaMigrationTable) Delete ¶ added in v0.4.0
func (s SchemaMigrationTable) Delete(ctx context.Context, db krabdb.ExecerContext, version string) error
Delete removes migration from a database.
func (SchemaMigrationTable) Exists ¶ added in v0.4.0
func (s SchemaMigrationTable) Exists(ctx context.Context, db krabdb.QueryerContext, migration SchemaMigration) (bool, error)
Exists checks if migration exists in database.
func (SchemaMigrationTable) FilterPending ¶ added in v0.4.0
func (s SchemaMigrationTable) FilterPending(all []*Migration, refsInDb []SchemaMigration) []*Migration
FilterPending removes `refsInDb` migrations from `all` and return new slice with pending ones only.
func (SchemaMigrationTable) Init ¶ added in v0.4.0
func (s SchemaMigrationTable) Init(ctx context.Context, db krabdb.ExecerContext) error
Init creates a migrations table.
func (SchemaMigrationTable) Insert ¶ added in v0.4.0
func (s SchemaMigrationTable) Insert(ctx context.Context, db krabdb.ExecerContext, version string) error
Insert saves migration to a database.
func (SchemaMigrationTable) SelectAll ¶ added in v0.4.0
func (s SchemaMigrationTable) SelectAll(ctx context.Context, db krabdb.QueryerContext) ([]SchemaMigration, error)
SelectAll fetches all migrations from a database.
func (SchemaMigrationTable) SelectLastN ¶ added in v0.4.0
func (s SchemaMigrationTable) SelectLastN(ctx context.Context, db krabdb.QueryerContext, limit int) ([]SchemaMigration, error)
SelectLastN fetches last N migrations in Z-A order.
func (SchemaMigrationTable) Truncate ¶ added in v0.4.0
func (s SchemaMigrationTable) Truncate(ctx context.Context, db krabdb.ExecerContext) error
Truncate truncates migrations table.
type SetRuntimeParameters ¶ added in v0.5.0
type SetRuntimeParameters struct {
SearchPath *string `hcl:"search_path"`
}
SetRuntimeParameters https://www.postgresql.org/docs/current/sql-set.html
func (*SetRuntimeParameters) ToSQL ¶ added in v0.5.0
func (d *SetRuntimeParameters) ToSQL(w io.StringWriter)
ToSQL converts set parameters to SQL.
type TestExample ¶ added in v0.5.0
type TestExample struct { krabhcl.Source // Set *SetRuntimeParameters `hcl:"set,block"` Name string Its []*TestExampleIt Xits []*TestExampleIt }
TestExample represents test runner configuration.
func (*TestExample) Addr ¶ added in v0.5.0
func (t *TestExample) Addr() krabhcl.Addr
func (*TestExample) DecodeHCL ¶ added in v0.8.0
func (t *TestExample) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
func (*TestExample) Validate ¶ added in v0.5.0
func (t *TestExample) Validate() error
type TestExampleIt ¶ added in v0.5.0
TestExampleIt represents one use case for test example that contain queries and assertions.
func (*TestExampleIt) DecodeHCL ¶ added in v0.8.0
func (it *TestExampleIt) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
type TestQuery ¶ added in v0.8.0
type TestQuery struct { krabhcl.Source Query string Rows []*TestQueryRow }
type TestQueryCol ¶ added in v0.8.0
func (*TestQueryCol) DecodeHCL ¶ added in v0.8.0
func (col *TestQueryCol) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
type TestQueryRow ¶ added in v0.8.0
type TestQueryRow struct { krabhcl.Source Scope string Cols []*TestQueryCol }
func (*TestQueryRow) DecodeHCL ¶ added in v0.8.0
func (row *TestQueryRow) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error
type TestSuite ¶ added in v0.5.0
type TestSuite struct {
Tests []*TestExample
}
TestSuite represents test runner configuration.
type TimestampVersionGenerator ¶ added in v0.6.0
type TimestampVersionGenerator struct{}
func (*TimestampVersionGenerator) Next ¶ added in v0.6.0
func (g *TimestampVersionGenerator) Next() string
type ToKCL ¶ added in v0.6.1
type ToKCL interface {
ToKCL(w io.StringWriter)
}
ToKCL converts DSL struct to Krab HCL.
type ToSQL ¶ added in v0.4.0
type ToSQL interface {
ToSQL(w io.StringWriter)
}
ToSQL converts DSL struct to SQL.
type VersionGenerator ¶ added in v0.6.0
type VersionGenerator interface {
Next() string
}
Source Files ¶
- action.go
- action_custom.go
- action_gen_migration.go
- action_migrate_down.go
- action_migrate_status.go
- action_migrate_up.go
- action_test_run.go
- action_version.go
- arguments.go
- cmd.go
- cmd_action.go
- cmd_gen_migration.go
- cmd_migrate_down.go
- cmd_migrate_status.go
- cmd_migrate_up.go
- cmd_registry.go
- cmd_test_run.go
- cmd_version.go
- config.go
- file.go
- hook_runner.go
- inputs.go
- kcl_statement.go
- parser.go
- schema_migration_table.go
- sql_statement.go
- subtype_do.go
- templates.go
- type_ddl_check.go
- type_ddl_column.go
- type_ddl_create_index.go
- type_ddl_create_table.go
- type_ddl_drop_index.go
- type_ddl_drop_table.go
- type_ddl_foreign_key.go
- type_ddl_generated_column.go
- type_ddl_identity.go
- type_ddl_primary_key.go
- type_ddl_references.go
- type_ddl_unique.go
- type_hooks.go
- type_migration.go
- type_migration_set.go
- type_set_runtime_parameters.go
- type_test_example.go
- type_test_example_it.go
- type_test_query.go
- type_test_query_col.go
- type_test_query_row.go
- type_test_suite.go
- validator.go
- version.go
- version_generator.go