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

Actions

-
+
for _, action := range actions { @ActionListItem(action) } @@ -25,20 +25,6 @@ templ ActionListItem(action *dto.ActionListItem) {

{ action.Description }

-
-
- for _, arg := range action.Arguments { -
- - { arg.Name } : { arg.Type } - -

- { arg.Description } -

-
- } -
-
diff --git a/views/action_new.templ b/views/action_new.templ index c66f8b3..879b21b 100644 --- a/views/action_new.templ +++ b/views/action_new.templ @@ -4,9 +4,11 @@ import "github.com/ohkrab/krab/web/dto" import "fmt" templ ActionForm(form *dto.ActionForm) { -

Run action

+

Run { form.Namespace }/{ form.Name } action

-
{ form.Namespace } / { form.Name }
+
+ { form.Description } +
diff --git a/web/dto/actions.go b/web/dto/actions.go index 8759b88..34538de 100644 --- a/web/dto/actions.go +++ b/web/dto/actions.go @@ -15,6 +15,7 @@ type ActionListItemArgument struct { } type ActionForm struct { + Description string ExecutionID string Namespace string Name string diff --git a/web/server.go b/web/server.go index f2db59d..7f44282 100644 --- a/web/server.go +++ b/web/server.go @@ -255,7 +255,7 @@ func (s *Server) Run(args []string) int { data = append(data, &dto.ActionListItem{ Namespace: action.Namespace, Name: action.RefName, - Description: "", + Description: action.Description, Transaction: action.Transaction, Arguments: args, }) @@ -280,6 +280,7 @@ func (s *Server) Run(args []string) int { } data := dto.ActionForm{ ExecutionID: uuid.New().String(), + Description: action.Description, Namespace: action.Namespace, Name: action.RefName, Arguments: args,