krab

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InfoName     = "krab"
	InfoFullName = "Oh Krab!"
	InfoWWW      = "https://ohkrab.dev"
)
View Source
const DefaultSchemaMigrationTableName = "schema_migrations"

Variables

View Source
var (
	InfoVersion   = "<generated>"
	InfoCommit    = "<generated>"
	InfoBuildDate = "<generated>"
)

Functions

func EmptyArgs added in v0.4.0

func EmptyArgs() map[string]interface{}

func ErrorCoalesce

func ErrorCoalesce(errs ...error) error

ErrorCoalesce returns first non empty error.

func ValidateRefName

func ValidateRefName(refName string) error

ValidateRefName checks if reference name matches allowed format.

func ValidateStringNonEmpty

func ValidateStringNonEmpty(what, s string) error

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) Addr added in v0.4.0

func (a *Action) Addr() krabhcl.Addr

func (*Action) DecodeHCL added in v0.5.0

func (a *Action) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error

DecodeHCL parses HCL into struct.

func (*Action) ToSQL added in v0.4.0

func (m *Action) ToSQL(w io.StringWriter)

func (*Action) Validate added in v0.4.0

func (a *Action) Validate() error

type ActionCustom added in v0.4.0

type ActionCustom struct {
	Ui  cli.UI
	Cmd *CmdAction
}

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) Run

func (a *ActionMigrateDown) Run(args []string) int

Run in CLI.

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) Run

func (a *ActionMigrateUp) Run(args []string) int

Run in CLI.

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) Run

func (a *ActionVersion) Run(args []string) int

Run in CLI.

func (*ActionVersion) Synopsis

func (a *ActionVersion) Synopsis() string

type Argument added in v0.4.0

type Argument struct {
	Name        string
	Type        string
	Description string
}

func (*Argument) DecodeHCL added in v0.5.0

func (a *Argument) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error

DecodeHCL parses HCL into struct.

func (*Argument) Validate added in v0.4.0

func (a *Argument) Validate(value interface{}) error

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) DecodeHCL added in v0.5.0

func (a *Arguments) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error

DecodeHCL parses HCL into struct.

func (*Arguments) Help added in v0.4.0

func (a *Arguments) Help() string

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) Addr added in v0.5.0

func (c *CmdAction) Addr() krabhcl.Addr

func (*CmdAction) Do added in v0.5.0

func (c *CmdAction) Do(ctx context.Context, o CmdOpts) (interface{}, error)

func (*CmdAction) HttpMethod added in v0.5.0

func (c *CmdAction) HttpMethod() string

func (*CmdAction) Name added in v0.5.0

func (c *CmdAction) Name() []string

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.

func NewConfig

func NewConfig(files []*File) (*Config, error)

NewConfig returns new configuration that was read from Parser. Transient attributes are updated with parsed data.

type DDLCheck added in v0.4.0

type DDLCheck struct {
	krabhcl.Source

	Name       string
	Expression string
}

DDLCheck constraint DSL for table DDL.

func (*DDLCheck) DecodeHCL added in v0.5.0

func (d *DDLCheck) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error

DecodeHCL parses HCL into struct.

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) DecodeHCL added in v0.5.0

func (d *DDLColumn) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error

DecodeHCL parses HCL into struct.

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

type DDLDropIndex struct {
	krabhcl.Source

	Name         string
	Cascade      bool
	Concurrently bool
}

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

type DDLDropTable struct {
	krabhcl.Source

	Name string
}

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

type DDLGeneratedColumn struct {
	krabhcl.Source

	As string
}

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

type DDLIdentity struct {
	krabhcl.Source
}

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

type DDLPrimaryKey struct {
	krabhcl.Source

	Columns []string
	Include []string
}

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

type DDLUnique struct {
	krabhcl.Source

	Columns []string
	Include []string
}

DDLUnique constraint DSL for table DDL.

func (*DDLUnique) DecodeHCL added in v0.5.0

func (d *DDLUnique) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error

DecodeHCL parses HCL into struct.

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.

func (*Do) Validate added in v0.5.0

func (d *Do) Validate() error

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
}

func (*DoMigrate) Validate added in v0.5.0

func (d *DoMigrate) Validate() error

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.

func (*File) Decode added in v0.5.0

func (f *File) Decode(ctx *hcl.EvalContext) error

Decode parses HCL into struct.

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 Hooks added in v0.4.0

type Hooks struct {
	Before string `hcl:"before"`
}

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) DecodeHCL added in v0.5.0

func (m *Migration) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error

DecodeHCL parses HCL into struct.

func (*Migration) ToKCL added in v0.6.1

func (m *Migration) ToKCL(w io.StringWriter)

func (*Migration) Validate

func (m *Migration) Validate() error

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 Parser

type Parser struct {
	FS afero.Afero
	// contains filtered or unexported fields
}

Parser represents HCL simple parser.

func NewParser

func NewParser() *Parser

NewParser initializes HCL parser and default file system.

func (*Parser) LoadConfigDir

func (p *Parser) LoadConfigDir(path string) (*Config, error)

LoadConfigDir parses files in a dir and returns Config.

type PositionalInputs added in v0.6.1

type PositionalInputs []string

Inputs are params passed to command.

type ResponseAction added in v0.5.0

type ResponseAction struct{}

ResponseAction json

type ResponseGenMigration added in v0.6.0

type ResponseGenMigration struct {
	Path string `json:"path"`
	Ref  string `json:"ref"`
}

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 ResponseTestRun added in v0.5.0

type ResponseTestRun struct {
}

ResponseTestRun json

type ResponseVersion added in v0.5.0

type ResponseVersion struct {
	Name  string `json:"name"`
	Build string `json:"build"`
}

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

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

Delete removes migration from a database.

func (SchemaMigrationTable) Exists added in v0.4.0

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

Init creates a migrations table.

func (SchemaMigrationTable) Insert added in v0.4.0

Insert saves migration to a database.

func (SchemaMigrationTable) SelectAll added in v0.4.0

SelectAll fetches all migrations from a database.

func (SchemaMigrationTable) SelectLastN added in v0.4.0

SelectLastN fetches last N migrations in Z-A order.

func (SchemaMigrationTable) Truncate added in v0.4.0

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 Templates added in v0.4.0

type Templates struct {
}

func (Templates) ProcessArguments added in v0.4.0

func (t Templates) ProcessArguments(tpl string, args map[string]interface{}) (string, error)

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

type TestExampleIt struct {
	krabhcl.Source

	Name    string
	Queries []*TestQuery
}

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
}

func (*TestQuery) DecodeHCL added in v0.8.0

func (q *TestQuery) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error

type TestQueryCol added in v0.8.0

type TestQueryCol struct {
	krabhcl.Source

	Message string
	Assert  string
}

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.

func (*TestSuite) Addr added in v0.5.0

func (t *TestSuite) Addr() krabhcl.Addr

func (*TestSuite) Validate added in v0.5.0

func (t *TestSuite) Validate() error

type TimestampVersionGenerator added in v0.6.0

type TimestampVersionGenerator struct{}

func (*TimestampVersionGenerator) Next added in v0.6.0

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 Validator

type Validator interface {
	Validate() error
}

type VersionGenerator added in v0.6.0

type VersionGenerator interface {
	Next() string
}

Jump to

Keyboard shortcuts

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