From 04396c4a37492f4aca378ba2a6981fa65c2a976b Mon Sep 17 00:00:00 2001 From: Mike Arpaia Date: Fri, 27 Oct 2017 17:52:24 -0400 Subject: [PATCH] Set decorator names for default decorators (#1590) --- .../20171027173700_AddTitlesToDecorators.go | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 server/datastore/mysql/migrations/data/20171027173700_AddTitlesToDecorators.go diff --git a/server/datastore/mysql/migrations/data/20171027173700_AddTitlesToDecorators.go b/server/datastore/mysql/migrations/data/20171027173700_AddTitlesToDecorators.go new file mode 100644 index 000000000..e330aa1cb --- /dev/null +++ b/server/datastore/mysql/migrations/data/20171027173700_AddTitlesToDecorators.go @@ -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 +}