From 8a0ae4ad9baf413958bb59e9559c78e489225020 Mon Sep 17 00:00:00 2001 From: Zachary Wasserman Date: Wed, 1 Mar 2017 12:49:02 -0800 Subject: [PATCH] Add migration to ensure 'All Hosts' is complete (#1330) Due to recreating the 'All Hosts' label in #1282, we get inconsistent counts for hosts that have not checked in since that migration. This seems acceptable for other labels, but it is important that 'All Hosts' really includes all the hosts. This migration adds all the hosts into that label. Fixes #1329 --- CHANGELOG.md | 2 + ...170301093653_AddAllHostsToAllHostsLabel.go | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 server/datastore/mysql/migrations/data/20170301093653_AddAllHostsToAllHostsLabel.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 64a56f4f9c..8ca53d9a30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ * Fix issue with Distributed Query Pack results full screen feature that broke the browser scrolling abilities +* Fix bug in which host counts in the sidebar did not match up with displayed hosts. + ## Kolide 1.0.1 (February 27, 2017) ## * Fix an issue that prevented users from replacing deleted labels with a new label of the same name. diff --git a/server/datastore/mysql/migrations/data/20170301093653_AddAllHostsToAllHostsLabel.go b/server/datastore/mysql/migrations/data/20170301093653_AddAllHostsToAllHostsLabel.go new file mode 100644 index 0000000000..8e22166877 --- /dev/null +++ b/server/datastore/mysql/migrations/data/20170301093653_AddAllHostsToAllHostsLabel.go @@ -0,0 +1,38 @@ +package data + +import ( + "database/sql" + + "github.com/kolide/kolide/server/kolide" + "github.com/pkg/errors" +) + +func init() { + MigrationClient.AddMigration(Up_20170301093653, Down_20170301093653) +} + +func Up_20170301093653(tx *sql.Tx) error { + // Insert any host not currently in 'All Hosts' label into the label + _, err := tx.Exec(` + INSERT IGNORE INTO label_query_executions ( + host_id, + label_id, + matches + ) SELECT + id as host_id, + (SELECT id as label_id FROM labels WHERE name = 'All Hosts' AND label_type = ?), + true as matches + FROM hosts +`, + kolide.LabelTypeBuiltIn) + if err != nil { + return errors.Wrap(err, "adding hosts to 'All Hosts'") + } + + return nil +} + +func Down_20170301093653(tx *sql.Tx) error { + // This operation not reversible + return nil +}