jukebox
All repositories: gitoria
1.7 KB
// lib/migrate.hl — KEYS FROM AN EARLIER VERSION. Until JB3 an album key held the folder and "CD 1" stayed in the album name, so one album sat in the database twice. `fixKeys` goes// through the songs of a database made before, folds the disc marker out of the album name, gives the song its disc number and rewrites the album key and the two sort keys// (from the stored fields, no file is read). The state is a one-line file `keys-version` in storage/: the work runs once, and is checked again after every change of the rule.import { readFile, writeFile, exists } from 'hl:fs'import { replaceSong, allSongs } from './db.hl'import { storageRoot } from './util.hl'import { splitDisc, albumKeyOf, discFor, sortKeys } from './albums.hl'static version = '3'static marker = storageRoot + '/keys-version'static needsFix = () => {if (!exists(marker)) { return true }return readFile(marker).trim() != version}// answers how many songs changedstatic fixKeys = () => {let changed = 0rows = []for (s of allSongs()) { rows.push(s) }for (s of rows) {parts = splitDisc(s.album)disc = discFor(s.disc == 1 && parts.disc == null ? null : s.disc, parts.disc)key = albumKeyOf(s.albumArtist, parts.name)keys = sortKeys(s.albumArtist, parts.name, disc, s.track == null ? 0 : s.track, s.title)if (key == s.albumKey && parts.name == s.album && disc == s.disc && keys.sortArtist == s.sortArtist && keys.sortAlbum == s.sortAlbum) { continue }rec = {}for (k in s) {if (k != 'id') { rec[k] = s[k] }}rec.album = parts.namerec.albumKey = keyrec.disc = discrec.sortArtist = keys.sortArtistrec.sortAlbum = keys.sortAlbumreplaceSong(s.id, rec)changed = changed + 1}writeFile(marker, version, 420)return changed}
Branches
Latest commits
- c1b153c4Merge branch 'records-1124c' into mainJukebox
- d7b5e780|||PR Records 2026-11-24 (2): live day72, PR #19 merge, #10 newsmre
- 43b564dbMerge branch 'records-1124b' into mainJukebox
- fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
- 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
- 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
- 170d3735Merge branch 'code-order-2' into mainJukebox
- 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
- 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
- 0ba85799Merge branch 'reset-classes' into mainJukebox
- 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
- 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
- dcca21abjukebox#8 Move copies and queue logic into their topicsmre
- 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
- bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
- a3796dc5Records: live step waits for idlemre
- 3b158e16Records: merges of #9 and #11mre
- 27204167Merge main into records-1123mre
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox