Set decorator names for default decorators (#1590)

This commit is contained in:
Mike Arpaia 2017-10-27 17:52:24 -04:00 committed by GitHub
parent 71db872725
commit 04396c4a37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,33 @@
package data
import (
"database/sql"
)
func init() {
MigrationClient.AddMigration(Up_20171027173700, Down_20171027173700)
}
func Up_20171027173700(tx *sql.Tx) error {
sql := "UPDATE decorators SET name=? where query=?"
rows := []struct {
name string
query string
}{
{"Host UUID", "SELECT uuid AS host_uuid FROM system_info;"},
{"Hostname", "SELECT hostname AS hostname FROM system_info;"},
}
for _, row := range rows {
_, err := tx.Exec(sql, row.name, row.query)
if err != nil {
return err
}
}
return nil
}
func Down_20171027173700(tx *sql.Tx) error {
_, err := tx.Exec("UPDATE decorators SET name='' WHERE built_in = TRUE")
return err
}