mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-04 09:31:09 +03:00
Remove unnecessary annotation table primary key
This commit is contained in:
parent
81459cc421
commit
47378c6882
66
db/migrations/20240629152843_remove_annotation_id.go
Normal file
66
db/migrations/20240629152843_remove_annotation_id.go
Normal file
@ -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
|
||||||
|
}
|
@ -6,7 +6,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/Masterminds/squirrel"
|
. "github.com/Masterminds/squirrel"
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/navidrome/navidrome/conf"
|
"github.com/navidrome/navidrome/conf"
|
||||||
"github.com/navidrome/navidrome/consts"
|
"github.com/navidrome/navidrome/consts"
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
@ -52,7 +51,6 @@ func (r sqlRepository) annUpsert(values map[string]interface{}, itemIDs ...strin
|
|||||||
c, err := r.executeSQL(upd)
|
c, err := r.executeSQL(upd)
|
||||||
if c == 0 || errors.Is(err, sql.ErrNoRows) {
|
if c == 0 || errors.Is(err, sql.ErrNoRows) {
|
||||||
for _, itemID := range itemIDs {
|
for _, itemID := range itemIDs {
|
||||||
values["ann_id"] = uuid.NewString()
|
|
||||||
values["user_id"] = userId(r.ctx)
|
values["user_id"] = userId(r.ctx)
|
||||||
values["item_type"] = r.tableName
|
values["item_type"] = r.tableName
|
||||||
values["item_id"] = itemID
|
values["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) {
|
if c == 0 || errors.Is(err, sql.ErrNoRows) {
|
||||||
values := map[string]interface{}{}
|
values := map[string]interface{}{}
|
||||||
values["ann_id"] = uuid.NewString()
|
|
||||||
values["user_id"] = userId(r.ctx)
|
values["user_id"] = userId(r.ctx)
|
||||||
values["item_type"] = r.tableName
|
values["item_type"] = r.tableName
|
||||||
values["item_id"] = itemID
|
values["item_id"] = itemID
|
||||||
|
Loading…
x
Reference in New Issue
Block a user