mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Fix policy membership migration for MariaDB (#3418)
* Fix policy membership migration for MariaDB * Use constraintsForTable to get the proper foreign key names
This commit is contained in:
parent
7f5b3cc15c
commit
93f4577c7d
2 changed files with 17 additions and 0 deletions
1
changes/issue-mariadb-migration
Normal file
1
changes/issue-mariadb-migration
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Fix v4.7.0 migration issue with policy membership history on MariaDB.
|
||||
|
|
@ -2,6 +2,7 @@ package tables
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
|
@ -16,6 +17,21 @@ func Up_20211202092042(tx *sql.Tx) error {
|
|||
return errors.Wrap(err, "drop view policy_membership")
|
||||
}
|
||||
|
||||
table := "policy_membership_history"
|
||||
referencedTables := map[string]struct{}{
|
||||
"policies": {},
|
||||
"hosts": {},
|
||||
}
|
||||
constraints, err := constraintsForTable(tx, table, referencedTables)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting references to policies and hosts table")
|
||||
}
|
||||
for _, ct := range constraints {
|
||||
if _, err := tx.Exec(fmt.Sprintf(`ALTER TABLE policy_membership_history DROP FOREIGN KEY %s;`, ct)); err != nil {
|
||||
return errors.Wrapf(err, "dropping policy_membership_history foreign keys: %s", ct)
|
||||
}
|
||||
}
|
||||
|
||||
policyMembershipTable := `
|
||||
CREATE TABLE IF NOT EXISTS policy_membership (
|
||||
policy_id INT UNSIGNED NOT NULL,
|
||||
|
|
|
|||
Loading…
Reference in a new issue