diff --git a/krab/action.go b/krab/action.go index 6e12e22..ab4c1c5 100644 --- a/krab/action.go +++ b/krab/action.go @@ -17,6 +17,7 @@ type Action struct { Arguments *Arguments + Description string SQL string Transaction bool // wrap operation in transaction } @@ -41,6 +42,10 @@ var schemaAction = &hcl.BodySchema{ Name: "transaction", Required: false, }, + { + Name: "description", + Required: true, + }, }, } @@ -81,6 +86,14 @@ func (a *Action) DecodeHCL(ctx *hcl.EvalContext, block *hcl.Block) error { } a.SQL = val + case "description": + expr := krabhcl.Expression{Expr: v.Expr, EvalContext: ctx} + val, err := expr.String() + if err != nil { + return err + } + a.Description = val + case "transaction": expr := krabhcl.Expression{Expr: v.Expr, EvalContext: ctx} val, err := expr.Bool() @@ -101,6 +114,7 @@ func (a *Action) Validate() error { return ErrorCoalesce( ValidateRefName(a.Namespace), ValidateRefName(a.RefName), + ValidateStringNonEmpty("description", a.Description), ) } diff --git a/test/fixtures/actions/actions.krab.hcl b/test/fixtures/actions/actions.krab.hcl new file mode 100644 index 0000000..a181255 --- /dev/null +++ b/test/fixtures/actions/actions.krab.hcl @@ -0,0 +1,32 @@ +action "db" "create" { + transaction = false + description = "Create a database and assign database owner" + + arguments { + arg "name" { + description = "Database name" + } + + arg "user" { + description = "Database user" + } + } + + sql = "CREATE DATABASE {{`{{ .Args.name | quote_ident }}`}} OWNER {{`{{ .Args.user | quote_ident }}`}}" +} + +action "user" "create" { + description = "Create a database user with password" + + arguments { + arg "user" { + description = "Database user" + } + + arg "password" { + description = "Database password" + } + } + + sql = "CREATE USER {{`{{ .Args.user | quote_ident }}`}} WITH PASSWORD {{`{{ .Args.password | quote }}`}}" +} diff --git a/test/fixtures/args/migrations.krab.hcl b/test/fixtures/args/migrations.krab.hcl index 09c2fec..aed4221 100644 --- a/test/fixtures/args/migrations.krab.hcl +++ b/test/fixtures/args/migrations.krab.hcl @@ -34,6 +34,8 @@ migration_set "animals" { } action "view" "refresh" { + description = "Refresh a materialized view" + arguments { arg "name" { description = "Materialized view to be refreshed" diff --git a/views/action_list.templ b/views/action_list.templ index 543f2d2..a32d44d 100644 --- a/views/action_list.templ +++ b/views/action_list.templ @@ -5,7 +5,7 @@ import "fmt" templ ActionList(actions []*dto.ActionListItem) {
{ action.Description }
- { arg.Description } -
-