mirror of
https://github.com/fleetdm/fleet
synced 2026-05-22 08:28:52 +00:00
Optimize policy_updated_at migration (#2362)
- Use `TRUNCATE TABLE` rather than `DELETE FROM` for improved performance. - Move DDL statement after truncate to avoid issues with retries (due to column already being created). #2360
This commit is contained in:
parent
53f82b8e28
commit
a2e9b539a1
2 changed files with 7 additions and 6 deletions
1
changes/2360-updated-at
Normal file
1
changes/2360-updated-at
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Improve performance and reliability of Policy database migrations.
|
||||
|
|
@ -11,16 +11,16 @@ func init() {
|
|||
}
|
||||
|
||||
func Up_20210927143115(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE hosts ADD COLUMN policy_updated_at timestamp NOT NULL DEFAULT '2000-01-01 00:00:00'")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "adding policy_updated_at column")
|
||||
}
|
||||
|
||||
_, err = tx.Exec("delete from policy_membership_history")
|
||||
_, err := tx.Exec("TRUNCATE TABLE policy_membership_history")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "clearing policy_membership_history")
|
||||
}
|
||||
|
||||
_, err = tx.Exec("ALTER TABLE hosts ADD COLUMN policy_updated_at timestamp NOT NULL DEFAULT '2000-01-01 00:00:00'")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "adding policy_updated_at column")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue