mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Reorder migrations for pre-4.0 upgrades (#1114)
Reorder migrations from the long-running `teams` branch to ensure that they can run successfully for deployments upgrading from a pre-4.0 release. All migrations from the `teams` branch are reordered to take place _after_ all migrations from the `main` branch, using `20210601` as the new date, after the latest released `main` branch migration on `20210526`. Fixes #1058
This commit is contained in:
parent
774bc4ef93
commit
6249beb465
8 changed files with 25 additions and 24 deletions
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MigrationClient.AddMigration(Up_20210315111056, Down_20210315111056)
|
MigrationClient.AddMigration(Up_20210601000001, Down_20210601000001)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Up_20210315111056(tx *sql.Tx) error {
|
func Up_20210601000001(tx *sql.Tx) error {
|
||||||
if _, err := tx.Exec(`CREATE TABLE IF NOT EXISTS teams (
|
if _, err := tx.Exec(`CREATE TABLE IF NOT EXISTS teams (
|
||||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
@ -49,6 +49,6 @@ func Up_20210315111056(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down_20210315111056(tx *sql.Tx) error {
|
func Down_20210601000001(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MigrationClient.AddMigration(Up_20210401164226, Down_20210401164226)
|
MigrationClient.AddMigration(Up_20210601000002, Down_20210601000002)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Up_20210401164226(tx *sql.Tx) error {
|
func Up_20210601000002(tx *sql.Tx) error {
|
||||||
// Invites <> Teams mapping
|
// Invites <> Teams mapping
|
||||||
if _, err := tx.Exec(`CREATE TABLE IF NOT EXISTS invite_teams (
|
if _, err := tx.Exec(`CREATE TABLE IF NOT EXISTS invite_teams (
|
||||||
invite_id INT UNSIGNED NOT NULL,
|
invite_id INT UNSIGNED NOT NULL,
|
||||||
|
|
@ -32,6 +32,6 @@ func Up_20210401164226(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down_20210401164226(tx *sql.Tx) error {
|
func Down_20210601000002(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MigrationClient.AddMigration(Up_20210406113434, Down_20210406113434)
|
MigrationClient.AddMigration(Up_20210601000003, Down_20210601000003)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Up_20210406113434(tx *sql.Tx) error {
|
func Up_20210601000003(tx *sql.Tx) error {
|
||||||
// Old admins become global admins
|
// Old admins become global admins
|
||||||
query := `
|
query := `
|
||||||
UPDATE users
|
UPDATE users
|
||||||
|
|
@ -69,6 +69,6 @@ func Up_20210406113434(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down_20210406113434(tx *sql.Tx) error {
|
func Down_20210601000003(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MigrationClient.AddMigration(Up_20210408153510, Down_20210408153510)
|
MigrationClient.AddMigration(Up_20210601000004, Down_20210601000004)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Up_20210408153510(tx *sql.Tx) error {
|
func Up_20210601000004(tx *sql.Tx) error {
|
||||||
query := "DELETE FROM users WHERE NOT enabled"
|
query := "DELETE FROM users WHERE NOT enabled"
|
||||||
if _, err := tx.Exec(query); err != nil {
|
if _, err := tx.Exec(query); err != nil {
|
||||||
return errors.Wrap(err, "delete disabled users")
|
return errors.Wrap(err, "delete disabled users")
|
||||||
|
|
@ -23,6 +23,6 @@ func Up_20210408153510(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down_20210408153510(tx *sql.Tx) error {
|
func Down_20210601000004(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MigrationClient.AddMigration(Up_20210428163822, Down_20210428163822)
|
MigrationClient.AddMigration(Up_20210601000005, Down_20210601000005)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Up_20210428163822(tx *sql.Tx) error {
|
func Up_20210601000005(tx *sql.Tx) error {
|
||||||
sql := `
|
sql := `
|
||||||
ALTER TABLE teams
|
ALTER TABLE teams
|
||||||
ADD COLUMN agent_options JSON
|
ADD COLUMN agent_options JSON
|
||||||
|
|
@ -18,9 +18,10 @@ func Up_20210428163822(tx *sql.Tx) error {
|
||||||
if _, err := tx.Exec(sql); err != nil {
|
if _, err := tx.Exec(sql); err != nil {
|
||||||
return errors.Wrap(err, "add column agent_options")
|
return errors.Wrap(err, "add column agent_options")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down_20210428163822(tx *sql.Tx) error {
|
func Down_20210601000005(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -11,10 +11,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MigrationClient.AddMigration(Up_20210510111225, Down_20210510111225)
|
MigrationClient.AddMigration(Up_20210601000006, Down_20210601000006)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Up_20210510111225(tx *sql.Tx) error {
|
func Up_20210601000006(tx *sql.Tx) error {
|
||||||
existingOptions, err := copyOptions(tx)
|
existingOptions, err := copyOptions(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "get existing options")
|
return errors.Wrap(err, "get existing options")
|
||||||
|
|
@ -80,6 +80,6 @@ type optionsRow struct {
|
||||||
Options string `db:"options"`
|
Options string `db:"options"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down_20210510111225(tx *sql.Tx) error {
|
func Down_20210601000006(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MigrationClient.AddMigration(Up_20210517112751, Down_20210517112751)
|
MigrationClient.AddMigration(Up_20210601000007, Down_20210601000007)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Up_20210517112751(tx *sql.Tx) error {
|
func Up_20210601000007(tx *sql.Tx) error {
|
||||||
sql := `
|
sql := `
|
||||||
ALTER TABLE queries
|
ALTER TABLE queries
|
||||||
ADD COLUMN observer_can_run TINYINT(1) NOT NULL DEFAULT FALSE
|
ADD COLUMN observer_can_run TINYINT(1) NOT NULL DEFAULT FALSE
|
||||||
|
|
@ -21,6 +21,6 @@ func Up_20210517112751(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down_20210517112751(tx *sql.Tx) error {
|
func Down_20210601000007(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MigrationClient.AddMigration(Up_20210527151852, Down_20210527151852)
|
MigrationClient.AddMigration(Up_20210601000008, Down_20210601000008)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Up_20210527151852(tx *sql.Tx) error {
|
func Up_20210601000008(tx *sql.Tx) error {
|
||||||
// Add team_id
|
// Add team_id
|
||||||
sql := `
|
sql := `
|
||||||
ALTER TABLE enroll_secrets
|
ALTER TABLE enroll_secrets
|
||||||
|
|
@ -51,6 +51,6 @@ func Up_20210527151852(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down_20210527151852(tx *sql.Tx) error {
|
func Down_20210601000008(tx *sql.Tx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue