2021-03-22 18:38:04 +01:00
|
|
|
package migrations
|
2020-10-13 03:21:28 +02:00
|
|
|
|
|
|
|
import (
|
2023-11-27 20:46:44 +01:00
|
|
|
"context"
|
2020-10-13 03:21:28 +02:00
|
|
|
"database/sql"
|
|
|
|
|
2023-04-04 15:57:00 +02:00
|
|
|
"github.com/pressly/goose/v3"
|
2020-10-13 03:21:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2023-11-27 20:46:44 +01:00
|
|
|
goose.AddMigrationContext(Up20201012210022, Down20201012210022)
|
2020-10-13 03:21:28 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 20:46:44 +01:00
|
|
|
func Up20201012210022(_ context.Context, tx *sql.Tx) error {
|
2020-10-13 03:21:28 +02:00
|
|
|
_, err := tx.Exec(`
|
|
|
|
alter table artist
|
|
|
|
add size integer default 0 not null;
|
|
|
|
create index if not exists artist_size
|
|
|
|
on artist(size);
|
|
|
|
|
2020-11-16 01:26:16 +01:00
|
|
|
update artist set size = ifnull((
|
|
|
|
select sum(f.size)
|
|
|
|
from album f
|
|
|
|
where f.album_artist_id = artist.id
|
|
|
|
), 0)
|
|
|
|
where id not null;
|
|
|
|
|
2020-10-13 03:21:28 +02:00
|
|
|
alter table playlist
|
|
|
|
add size integer default 0 not null;
|
|
|
|
create index if not exists playlist_size
|
|
|
|
on playlist(size);
|
|
|
|
|
|
|
|
update playlist set size = ifnull((
|
|
|
|
select sum(size)
|
|
|
|
from media_file f
|
|
|
|
left join playlist_tracks pt on f.id = pt.media_file_id
|
|
|
|
where pt.playlist_id = playlist.id
|
|
|
|
), 0);`)
|
|
|
|
|
2020-11-16 01:26:16 +01:00
|
|
|
return err
|
2020-10-13 03:21:28 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 20:46:44 +01:00
|
|
|
func Down20201012210022(_ context.Context, tx *sql.Tx) error {
|
2020-10-13 03:21:28 +02:00
|
|
|
return nil
|
|
|
|
}
|