Drop old indices from PostgreSQL too

This commit is contained in:
Neil Alexander 2022-11-11 16:14:20 +00:00
parent 2970bfd8ff
commit 0907bfd06e
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -30,6 +30,13 @@ var serverNamesDropPK = map[string]string{
"userapi_profiles": "account_profiles",
}
// These indices are out of date so let's drop them. They will get recreated
// automatically.
var serverNamesDropIndex = []string{
"userapi_pusher_localpart_idx",
"userapi_pusher_app_id_pushkey_localpart_idx",
}
// I know what you're thinking: you're wondering "why doesn't this use $1
// and pass variadic parameters to ExecContext?" — the answer is because
// PostgreSQL doesn't expect the table name to be specified as a substituted
@ -61,5 +68,14 @@ func UpServerNames(ctx context.Context, tx *sql.Tx, serverName gomatrixserverlib
return fmt.Errorf("drop old PK from %q error: %w", newTable, err)
}
}
for _, index := range serverNamesDropIndex {
q := fmt.Sprintf(
"DROP INDEX IF EXISTS %s;",
pq.QuoteIdentifier(index),
)
if _, err := tx.ExecContext(ctx, q); err != nil {
return fmt.Errorf("drop index %q error: %w", index, err)
}
}
return nil
}