mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
Consistently log migrations (#8154)
* Consistently log migrations * Fix name and update goose version
This commit is contained in:
parent
351d2c93c4
commit
28744bf57e
2
go.mod
2
go.mod
@ -25,7 +25,7 @@ require (
|
|||||||
github.com/elazarl/go-bindata-assetfs v1.0.1
|
github.com/elazarl/go-bindata-assetfs v1.0.1
|
||||||
github.com/facebookincubator/nvdtools v0.1.4
|
github.com/facebookincubator/nvdtools v0.1.4
|
||||||
github.com/fatih/color v1.12.0
|
github.com/fatih/color v1.12.0
|
||||||
github.com/fleetdm/goose v0.0.0-20220214194029-91b5e5eb8e77
|
github.com/fleetdm/goose v0.0.0-20221011170007-06aacf8ac547
|
||||||
github.com/getlantern/systray v1.2.2-0.20220329111105-6065fda28be8
|
github.com/getlantern/systray v1.2.2-0.20220329111105-6065fda28be8
|
||||||
github.com/getsentry/sentry-go v0.12.0
|
github.com/getsentry/sentry-go v0.12.0
|
||||||
github.com/ghodss/yaml v1.0.0
|
github.com/ghodss/yaml v1.0.0
|
||||||
|
6
go.sum
6
go.sum
@ -414,8 +414,10 @@ github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
|||||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||||
github.com/felixge/httpsnoop v1.0.2 h1:+nS9g82KMXccJ/wp0zyRW9ZBHFETmMGtkk+2CTTrW4o=
|
github.com/felixge/httpsnoop v1.0.2 h1:+nS9g82KMXccJ/wp0zyRW9ZBHFETmMGtkk+2CTTrW4o=
|
||||||
github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||||
github.com/fleetdm/goose v0.0.0-20220214194029-91b5e5eb8e77 h1:oaRSVdXLGFxX0aQa5UI8GDr6+lRiscSM40B6zl8oUKI=
|
github.com/fleetdm/goose v0.0.0-20221010190138-300add7e71d0 h1:SBtLB3xSrs/1ClsGkdW5oDL3vwJdr5FQODUgPrXTnwY=
|
||||||
github.com/fleetdm/goose v0.0.0-20220214194029-91b5e5eb8e77/go.mod h1:d7Q+0eCENnKQUhkfAUVLfGnD4QcgJMF/uB9WRTN9TDI=
|
github.com/fleetdm/goose v0.0.0-20221010190138-300add7e71d0/go.mod h1:d7Q+0eCENnKQUhkfAUVLfGnD4QcgJMF/uB9WRTN9TDI=
|
||||||
|
github.com/fleetdm/goose v0.0.0-20221011170007-06aacf8ac547 h1:3Vlgx6mJYFlj3GPB3CgoQrR7URgE0GQGnKYNfoXxuUo=
|
||||||
|
github.com/fleetdm/goose v0.0.0-20221011170007-06aacf8ac547/go.mod h1:d7Q+0eCENnKQUhkfAUVLfGnD4QcgJMF/uB9WRTN9TDI=
|
||||||
github.com/fleetdm/nanodep v0.1.1-0.20221005204411-eefd72d47e93 h1:RrbbEIXsD4dteW5FpxzvlZgoCN2Hlw5pP//+RgaZfAs=
|
github.com/fleetdm/nanodep v0.1.1-0.20221005204411-eefd72d47e93 h1:RrbbEIXsD4dteW5FpxzvlZgoCN2Hlw5pP//+RgaZfAs=
|
||||||
github.com/fleetdm/nanodep v0.1.1-0.20221005204411-eefd72d47e93/go.mod h1:QzQrCUTmSr9HotzKZAcfmy+czbEGK8Mq26hA+0DN4ag=
|
github.com/fleetdm/nanodep v0.1.1-0.20221005204411-eefd72d47e93/go.mod h1:QzQrCUTmSr9HotzKZAcfmy+czbEGK8Mq26hA+0DN4ag=
|
||||||
github.com/fleetdm/nanomdm v0.3.1-0.20221005204003-0c868c49ef10 h1:0UqWDMG4mb2ywA1EYa3yfC0JqAMS4LdD6lsmHGVHkZw=
|
github.com/fleetdm/nanomdm v0.3.1-0.20221005204003-0c868c49ef10 h1:0UqWDMG4mb2ywA1EYa3yfC0JqAMS4LdD6lsmHGVHkZw=
|
||||||
|
@ -13,7 +13,6 @@ func init() {
|
|||||||
|
|
||||||
func Up_20220704101843(tx *sql.Tx) error {
|
func Up_20220704101843(tx *sql.Tx) error {
|
||||||
if !columnExists(tx, "software_cve", "software_id") {
|
if !columnExists(tx, "software_cve", "software_id") {
|
||||||
logger.Info.Println("Adding software_id column to software_cve table...")
|
|
||||||
|
|
||||||
_, err := tx.Exec(`
|
_, err := tx.Exec(`
|
||||||
ALTER TABLE software_cve ADD COLUMN software_id bigint(20) UNSIGNED NULL, ALGORITHM=INPLACE, LOCK=NONE;
|
ALTER TABLE software_cve ADD COLUMN software_id bigint(20) UNSIGNED NULL, ALGORITHM=INPLACE, LOCK=NONE;
|
||||||
@ -21,12 +20,9 @@ func Up_20220704101843(tx *sql.Tx) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "adding software_id to software_cve")
|
return errors.Wrapf(err, "adding software_id to software_cve")
|
||||||
}
|
}
|
||||||
logger.Info.Println("Done adding software_id column to software_cve table...")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info.Println("Updating software_id column in software_cve table...")
|
|
||||||
|
|
||||||
var min int
|
var min int
|
||||||
var max int
|
var max int
|
||||||
|
|
||||||
@ -46,9 +42,7 @@ INNER JOIN software_cpe AS cpe ON cve.cpe_id = cpe.id
|
|||||||
SET cve.software_id = cpe.software_id
|
SET cve.software_id = cpe.software_id
|
||||||
WHERE cve.software_id IS NULL AND cve.id >= ? AND cve.id < ?;`
|
WHERE cve.software_id IS NULL AND cve.id >= ? AND cve.id < ?;`
|
||||||
|
|
||||||
if min == 0 && max == 0 {
|
if min != 0 || max != 0 {
|
||||||
logger.Info.Println("Nothing to update ...")
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Updating aprox %d records... \n", max-min)
|
fmt.Printf("Updating aprox %d records... \n", max-min)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,9 +64,6 @@ WHERE cve.software_id IS NULL AND cve.id >= ? AND cve.id < ?;`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info.Println("Done updating 'software_id'...")
|
|
||||||
logger.Info.Println("Adding index to 'software_id'...")
|
|
||||||
|
|
||||||
const indexStmt = `
|
const indexStmt = `
|
||||||
ALTER TABLE software_cve ADD INDEX software_cve_software_id (software_id), ALGORITHM=INPLACE, LOCK=NONE;`
|
ALTER TABLE software_cve ADD INDEX software_cve_software_id (software_id), ALGORITHM=INPLACE, LOCK=NONE;`
|
||||||
_, err := tx.Exec(indexStmt)
|
_, err := tx.Exec(indexStmt)
|
||||||
@ -80,8 +71,6 @@ ALTER TABLE software_cve ADD INDEX software_cve_software_id (software_id), ALGOR
|
|||||||
return errors.Wrapf(err, "adding index to software_id on software_cve table")
|
return errors.Wrapf(err, "adding index to software_id on software_cve table")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info.Println("Done adding index to 'software_id'...")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func removeDups(tx *sql.Tx) error {
|
func removeDups(tx *sql.Tx) error {
|
||||||
logger.Info.Println("Removing duplicates in the software_cve table")
|
|
||||||
|
|
||||||
const deleteStmt = `
|
const deleteStmt = `
|
||||||
delete sc
|
delete sc
|
||||||
from
|
from
|
||||||
@ -43,14 +41,12 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addUniqConstraint(tx *sql.Tx) error {
|
func addUniqConstraint(tx *sql.Tx) error {
|
||||||
logger.Info.Println("Adding unique constraint on (cve, software_id) to software_cve table...")
|
|
||||||
_, err := tx.Exec(`
|
_, err := tx.Exec(`
|
||||||
ALTER TABLE software_cve ADD CONSTRAINT unq_software_id_cve UNIQUE (software_id, cve), ALGORITHM=INPLACE, LOCK=NONE;
|
ALTER TABLE software_cve ADD CONSTRAINT unq_software_id_cve UNIQUE (software_id, cve), ALGORITHM=INPLACE, LOCK=NONE;
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "adding unique constraint to software_id on software_cve")
|
return errors.Wrapf(err, "adding unique constraint to software_id on software_cve")
|
||||||
}
|
}
|
||||||
logger.Info.Println("Done adding unique constraint on (cve, software_id) to software_cve table...")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Up_20220802135510(tx *sql.Tx) error {
|
func Up_20220802135510(tx *sql.Tx) error {
|
||||||
logger.Info.Println("Creating table mobile_device_management_solutions...")
|
|
||||||
|
|
||||||
// An mdm ID identifies a Vendor + Server URL combination (e.g. Jamf + https://company.jamfcloud.com)
|
// An mdm ID identifies a Vendor + Server URL combination (e.g. Jamf + https://company.jamfcloud.com)
|
||||||
// A distinct server URL for the same vendor results in different MDM ID.
|
// A distinct server URL for the same vendor results in different MDM ID.
|
||||||
_, err := tx.Exec(`
|
_, err := tx.Exec(`
|
||||||
@ -28,9 +26,7 @@ CREATE TABLE mobile_device_management_solutions (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "create table")
|
return errors.Wrapf(err, "create table")
|
||||||
}
|
}
|
||||||
logger.Info.Println("Done creating table mobile_device_management_solutions...")
|
|
||||||
|
|
||||||
logger.Info.Println("Adding column mdm_id to table host_mdm...")
|
|
||||||
// adding as NULLable to prevent costly migration for users with many hosts,
|
// adding as NULLable to prevent costly migration for users with many hosts,
|
||||||
// the mdm_id will be lazily populated as MDM query results get returned by
|
// the mdm_id will be lazily populated as MDM query results get returned by
|
||||||
// hosts.
|
// hosts.
|
||||||
@ -38,25 +34,20 @@ CREATE TABLE mobile_device_management_solutions (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "alter table")
|
return errors.Wrapf(err, "alter table")
|
||||||
}
|
}
|
||||||
logger.Info.Println("Done adding column mdm_id to table host_mdm...")
|
|
||||||
|
|
||||||
logger.Info.Println("Adding index on mdm_id of table host_mdm...")
|
|
||||||
_, err = tx.Exec(`CREATE INDEX host_mdm_mdm_id_idx ON host_mdm (mdm_id);`)
|
_, err = tx.Exec(`CREATE INDEX host_mdm_mdm_id_idx ON host_mdm (mdm_id);`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "create mdm id index")
|
return errors.Wrapf(err, "create mdm id index")
|
||||||
}
|
}
|
||||||
logger.Info.Println("Done adding index on mdm_id of table host_mdm...")
|
|
||||||
|
|
||||||
// those are boolean fields, but indexing is still likely to speed things up
|
// those are boolean fields, but indexing is still likely to speed things up
|
||||||
// significantly, because a) we will filter on a combination of both booleans and
|
// significantly, because a) we will filter on a combination of both booleans and
|
||||||
// b) it's unlikely that enrolled/unenrolled ratio will be close to 50%.
|
// b) it's unlikely that enrolled/unenrolled ratio will be close to 50%.
|
||||||
// see https://stackoverflow.com/questions/10524651/is-there-any-performance-gain-in-indexing-a-boolean-field
|
// see https://stackoverflow.com/questions/10524651/is-there-any-performance-gain-in-indexing-a-boolean-field
|
||||||
logger.Info.Println("Adding index on enrolled, installed_from_dep of table host_mdm...")
|
|
||||||
_, err = tx.Exec(`CREATE INDEX host_mdm_enrolled_installed_from_dep_idx ON host_mdm (enrolled, installed_from_dep);`)
|
_, err = tx.Exec(`CREATE INDEX host_mdm_enrolled_installed_from_dep_idx ON host_mdm (enrolled, installed_from_dep);`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "create enrollment status index")
|
return errors.Wrapf(err, "create enrollment status index")
|
||||||
}
|
}
|
||||||
logger.Info.Println("Done adding index on enrolled, installed_from_dep of table host_mdm...")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Up_20220818101352(tx *sql.Tx) error {
|
func Up_20220818101352(tx *sql.Tx) error {
|
||||||
logger.Info.Println("Increasing width of software.vendor...")
|
|
||||||
|
|
||||||
//-----------------
|
//-----------------
|
||||||
// Add temp column.
|
// Add temp column.
|
||||||
//-----------------
|
//-----------------
|
||||||
@ -62,7 +60,6 @@ func Up_20220818101352(tx *sql.Tx) error {
|
|||||||
return errors.Wrapf(err, "renaming new column")
|
return errors.Wrapf(err, "renaming new column")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info.Println("Done increasing width of software.vendor...")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Up_20220822161445(tx *sql.Tx) error {
|
func Up_20220822161445(tx *sql.Tx) error {
|
||||||
logger.Info.Println("Creating table munki_issues...")
|
|
||||||
// name is actually the error/warning message - 255 ought to be enough, based
|
// name is actually the error/warning message - 255 ought to be enough, based
|
||||||
// on the example error messages the longest is only ~80. If we need a larger
|
// on the example error messages the longest is only ~80. If we need a larger
|
||||||
// column, we can always add a column for the hash of the name and set the
|
// column, we can always add a column for the hash of the name and set the
|
||||||
@ -33,9 +32,7 @@ func Up_20220822161445(tx *sql.Tx) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "create munki_issues table")
|
return errors.Wrapf(err, "create munki_issues table")
|
||||||
}
|
}
|
||||||
logger.Info.Println("Done creating table munki_issues...")
|
|
||||||
|
|
||||||
logger.Info.Println("Creating table host_munki_issues...")
|
|
||||||
_, err = tx.Exec(`
|
_, err = tx.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS host_munki_issues (
|
CREATE TABLE IF NOT EXISTS host_munki_issues (
|
||||||
host_id INT(10) UNSIGNED NOT NULL,
|
host_id INT(10) UNSIGNED NOT NULL,
|
||||||
@ -47,7 +44,6 @@ func Up_20220822161445(tx *sql.Tx) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "create host_munki_issues table")
|
return errors.Wrap(err, "create host_munki_issues table")
|
||||||
}
|
}
|
||||||
logger.Info.Println("Done creating table host_munki_issues...")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Up_20220831100036(tx *sql.Tx) error {
|
func Up_20220831100036(tx *sql.Tx) error {
|
||||||
logger.Info.Println("Deleting dummy software_cpe entries...")
|
|
||||||
// Remove in batches
|
// Remove in batches
|
||||||
const deleteStmt = `DELETE FROM software_cpe WHERE cpe LIKE 'none:%' LIMIT 10000`
|
const deleteStmt = `DELETE FROM software_cpe WHERE cpe LIKE 'none:%' LIMIT 10000`
|
||||||
|
|
||||||
@ -32,9 +31,6 @@ func Up_20220831100036(tx *sql.Tx) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.Info.Println("Done deleting dummy cpe_id entries...")
|
|
||||||
|
|
||||||
logger.Info.Println("Removing cpe_id from software_cve...")
|
|
||||||
|
|
||||||
// The name for the FK from software_cve to software_cpe changes depending on whether the user
|
// The name for the FK from software_cve to software_cpe changes depending on whether the user
|
||||||
// is running MySQL or MariaDB.
|
// is running MySQL or MariaDB.
|
||||||
@ -68,8 +64,6 @@ ALTER TABLE software_cve DROP COLUMN cpe_id, ALGORITHM=INPLACE, LOCK=NONE;
|
|||||||
return errors.Wrapf(err, "removing cpe_id column from software_cve")
|
return errors.Wrapf(err, "removing cpe_id column from software_cve")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info.Println("Done removing cpe_id from software_cve...")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user