From c1cc2a52178c27959cc51cfc3131f382c9f0be25 Mon Sep 17 00:00:00 2001 From: Vyr Cossont Date: Mon, 20 Jan 2025 21:44:29 -0800 Subject: [PATCH] Remove redundant index on unique column Also removes redundant unique and notnull tags on ID column since these are implied by pk --- ...241124012636_add_web_push_subscriptions.go | 21 +++++++------------ internal/gtsmodel/webpushsubscription.go | 4 ++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/internal/db/bundb/migrations/20241124012636_add_web_push_subscriptions.go b/internal/db/bundb/migrations/20241124012636_add_web_push_subscriptions.go index 269470ee9..87d966903 100644 --- a/internal/db/bundb/migrations/20241124012636_add_web_push_subscriptions.go +++ b/internal/db/bundb/migrations/20241124012636_add_web_push_subscriptions.go @@ -35,19 +35,14 @@ func init() { return err } - for index, columns := range map[string][]string{ - "web_push_subscriptions_account_id_idx": {"account_id"}, - "web_push_subscriptions_token_id_idx": {"token_id"}, - } { - if _, err := tx. - NewCreateIndex(). - Model(>smodel.WebPushSubscription{}). - Index(index). - Column(columns...). - IfNotExists(). - Exec(ctx); err != nil { - return err - } + if _, err := tx. + NewCreateIndex(). + Model(>smodel.WebPushSubscription{}). + Index("web_push_subscriptions_account_id_idx"). + Column("account_id"). + IfNotExists(). + Exec(ctx); err != nil { + return err } return nil diff --git a/internal/gtsmodel/webpushsubscription.go b/internal/gtsmodel/webpushsubscription.go index 7f2a4a0cd..4aeef654a 100644 --- a/internal/gtsmodel/webpushsubscription.go +++ b/internal/gtsmodel/webpushsubscription.go @@ -21,10 +21,10 @@ package gtsmodel // There can be at most one per access token. type WebPushSubscription struct { // ID of this subscription in the database. - ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"` + ID string `bun:"type:CHAR(26),pk,nullzero"` // AccountID of the local account that created this subscription. - AccountID string `bun:"type:CHAR(26),notnull,nullzero"` + AccountID string `bun:"type:CHAR(26),nullzero,notnull"` // TokenID is the ID of the associated access token. // There can be at most one subscription for any given access token,