diff --git a/server/datastore/mysql/migrations/tables/20210927143116_AddBundleIdentifierColumn.go b/server/datastore/mysql/migrations/tables/20210927143116_AddBundleIdentifierColumn.go index f4019655d0..34d30a0da3 100644 --- a/server/datastore/mysql/migrations/tables/20210927143116_AddBundleIdentifierColumn.go +++ b/server/datastore/mysql/migrations/tables/20210927143116_AddBundleIdentifierColumn.go @@ -10,19 +10,6 @@ func init() { MigrationClient.AddMigration(Up_20210927143116, Down_20210927143116) } -func columnExists(tx *sql.Tx, table, column string) bool { - var count int - err := tx.QueryRow( - `SELECT count(*) FROM information_schema.columns WHERE COLUMN_NAME = ? AND table_name = ? LIMIT 1;`, - column, table, - ).Scan(&count) - if err != nil { - return false - } - - return count == 1 -} - func Up_20210927143116(tx *sql.Tx) error { if columnExists(tx, "software", "bundle_identifier") { return nil diff --git a/server/datastore/mysql/migrations/tables/migration.go b/server/datastore/mysql/migrations/tables/migration.go index ccd315f353..cbcf1a99bb 100644 --- a/server/datastore/mysql/migrations/tables/migration.go +++ b/server/datastore/mysql/migrations/tables/migration.go @@ -1,7 +1,33 @@ package tables -import "github.com/fleetdm/goose" +import ( + "database/sql" + + "github.com/fleetdm/goose" +) var ( MigrationClient = goose.New("migration_status_tables", goose.MySqlDialect{}) ) + +func columnExists(tx *sql.Tx, table, column string) bool { + var count int + err := tx.QueryRow( + ` +SELECT + count(*) +FROM + information_schema.columns +WHERE + TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = ? + AND COLUMN_NAME = ? +`, + table, column, + ).Scan(&count) + if err != nil { + return false + } + + return count > 0 +}