Action
Action resource is a custom SQL operation that will be executed.
1action "<namespace>" "<name>" {
2 description = "..."
3
4 arguments {
5 ...
6 }
7 transaction = true
8
9 sql = "..."
10}
<namespace>
- is a action namespace<name>
- is a migration reference name to use when connecting to other resourcesarguments
block (optional) - define arguments that can be used insql
as a variable, see Resource arguments for more detailssql
- code to be executeddescription
- description of the actiontransaction (optional)
- specifies whether to run action in a transaction (default:true
)
Arguments
These attributes can be used with arguments:
sql
Example
1action "view" "refresh" {
2 description = "Refresh materialized view"
3 arguments {
4 arg "name" {
5 description = "Materialized view to be refreshed"
6 }
7 }
8
9 sql = "REFRESH MATERIALIZED VIEW {{ .Args.name | quote_ident }}"
10}
Fakes
You can generate fake data with fake
function template.
1action "seed" "all" {
2 description = "Seed database with fake data"
3
4 sql = <<-SQL
5 INSERT INTO companies (name) VALUES ({{ fake "Company.Name" | quote }})
6 SQL
7}