🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Remove unnecessary annotation table primary key
Deluan47378c688288
diff --git a/db/migrations/20240629152843_remove_annotation_id.go b/db/migrations/20240629152843_remove_annotation_id.gonew file mode 100644index 000000000..b450b26d4--- /dev/null+++ b/db/migrations/20240629152843_remove_annotation_id.go@@ -0,0 +1,66 @@+package migrations++import (+ "context"+ "database/sql"++ "github.com/pressly/goose/v3"+)++func init() {+ goose.AddMigrationContext(upRemoveAnnotationId, downRemoveAnnotationId)+}++func upRemoveAnnotationId(ctx context.Context, tx *sql.Tx) error {+ _, err := tx.ExecContext(ctx, `+create table annotation_dg_tmp+(+ user_id varchar(255) default '' not null,+ item_id varchar(255) default '' not null,+ item_type varchar(255) default '' not null,+ play_count integer default 0,+ play_date datetime,+ rating integer default 0,+ starred bool default FALSE not null,+ starred_at datetime,+ unique (user_id, item_id, item_type)+);++insert into annotation_dg_tmp(user_id, item_id, item_type, play_count, play_date, rating, starred, starred_at)+select user_id,+ item_id,+ item_type,+ play_count,+ play_date,+ rating,+ starred,+ starred_at+from annotation;++drop table annotation;++alter table annotation_dg_tmp+ rename to annotation;++create index annotation_play_count+ on annotation (play_count);++create index annotation_play_date+ on annotation (play_date);++create index annotation_rating+ on annotation (rating);++create index annotation_starred+ on annotation (starred);++create index annotation_starred_at+ on annotation (starred_at);++`)+ return err+}++func downRemoveAnnotationId(ctx context.Context, tx *sql.Tx) error {+ return nil+}diff --git a/persistence/sql_annotations.go b/persistence/sql_annotations.goindex 77dc816c2..8ce1bdd69 100644--- a/persistence/sql_annotations.go+++ b/persistence/sql_annotations.go@@ -6,7 +6,6 @@ import ("time". "github.com/Masterminds/squirrel"- "github.com/google/uuid""github.com/navidrome/navidrome/conf""github.com/navidrome/navidrome/consts""github.com/navidrome/navidrome/log"@@ -52,7 +51,6 @@ func (r sqlRepository) annUpsert(values map[string]interface{}, itemIDs ...strinc, err := r.executeSQL(upd)if c == 0 || errors.Is(err, sql.ErrNoRows) {for _, itemID := range itemIDs {- values["ann_id"] = uuid.NewString()values["user_id"] = userId(r.ctx)values["item_type"] = r.tableNamevalues["item_id"] = itemID@@ -83,7 +81,6 @@ func (r sqlRepository) IncPlayCount(itemID string, ts time.Time) error {if c == 0 || errors.Is(err, sql.ErrNoRows) {values := map[string]interface{}{}- values["ann_id"] = uuid.NewString()values["user_id"] = userId(r.ctx)values["item_type"] = r.tableNamevalues["item_id"] = itemID