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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user