From 0907bfd06e1a91654afa5b8446d7a24b6c5e4012 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 11 Nov 2022 16:14:20 +0000 Subject: [PATCH] Drop old indices from PostgreSQL too --- .../deltas/2022110411000000_server_names.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/userapi/storage/postgres/deltas/2022110411000000_server_names.go b/userapi/storage/postgres/deltas/2022110411000000_server_names.go index 194679c00..279e1e5f1 100644 --- a/userapi/storage/postgres/deltas/2022110411000000_server_names.go +++ b/userapi/storage/postgres/deltas/2022110411000000_server_names.go @@ -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 }