Files
navidrome-meilisearch/db/migrations/20250701010103_add_library_stats.go
Dongho Kim c251f174ed
Some checks failed
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v5) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v6) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v7) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to GHCR (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Has been cancelled
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
POEditor import / update-translations (push) Has been cancelled
update
2025-12-08 16:16:23 +01:00

49 lines
1.8 KiB
Go

package migrations
import (
"context"
"database/sql"
"github.com/pressly/goose/v3"
)
func init() {
goose.AddMigrationContext(upAddLibraryStats, downAddLibraryStats)
}
func upAddLibraryStats(ctx context.Context, tx *sql.Tx) error {
_, err := tx.ExecContext(ctx, `
alter table library add column total_songs integer default 0 not null;
alter table library add column total_albums integer default 0 not null;
alter table library add column total_artists integer default 0 not null;
alter table library add column total_folders integer default 0 not null;
alter table library add column total_files integer default 0 not null;
alter table library add column total_missing_files integer default 0 not null;
alter table library add column total_size integer default 0 not null;
update library set
total_songs = (
select count(*) from media_file where library_id = library.id and missing = 0
),
total_albums = (select count(*) from album where library_id = library.id and missing = 0),
total_artists = (
select count(*) from library_artist la
join artist a on la.artist_id = a.id
where la.library_id = library.id and a.missing = 0
),
total_folders = (select count(*) from folder where library_id = library.id and missing = 0 and num_audio_files > 0),
total_files = (
select ifnull(sum(num_audio_files + num_playlists + json_array_length(image_files)),0)
from folder where library_id = library.id and missing = 0
),
total_missing_files = (
select count(*) from media_file where library_id = library.id and missing = 1
),
total_size = (select ifnull(sum(size),0) from album where library_id = library.id and missing = 0);
`)
return err
}
func downAddLibraryStats(ctx context.Context, tx *sql.Tx) error {
return nil
}