gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitdeb8cef5deb8cef5Records: mission 006 startedmredeb8cef5/lib/migrate.hl

1.7 KB

  1. // 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
  2. // 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
  3. // (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.
  4. import { readFile, writeFile, exists } from 'hl:fs'
  5. import { songsTable, replaceSong } from './db.hl'
  6. import { storageRoot } from './util.hl'
  7. import { splitDisc, albumKeyOf, discFor, sortKeys } from './albums.hl'
  8. static version = '3'
  9. static marker = storageRoot + '/keys-version'
  10. static needsFix = () => {
  11. if (!exists(marker)) { return true }
  12. return readFile(marker).trim() != version
  13. }
  14. // answers how many songs changed
  15. static fixKeys = () => {
  16. let changed = 0
  17. rows = []
  18. for (s of songsTable.iterate(null, null)) { rows.push(s) }
  19. for (s of rows) {
  20. parts = splitDisc(s.album)
  21. disc = discFor(s.disc == 1 && parts.disc == null ? null : s.disc, parts.disc)
  22. key = albumKeyOf(s.albumArtist, parts.name)
  23. keys = sortKeys(s.albumArtist, parts.name, disc, s.track == null ? 0 : s.track, s.title)
  24. if (key == s.albumKey && parts.name == s.album && disc == s.disc && keys.sortArtist == s.sortArtist && keys.sortAlbum == s.sortAlbum) { continue }
  25. rec = {}
  26. for (k in s) {
  27. if (k != 'id') { rec[k] = s[k] }
  28. }
  29. rec.album = parts.name
  30. rec.albumKey = key
  31. rec.disc = disc
  32. rec.sortArtist = keys.sortArtist
  33. rec.sortAlbum = keys.sortAlbum
  34. replaceSong(s.id, rec)
  35. changed = changed + 1
  36. }
  37. writeFile(marker, version, 420)
  38. return changed
  39. }

Branches

Latest commits

  • deb8cef5Records: mission 006 startedmre
  • 4f0ad42fMission 006: jukebox#20mre
  • 800cae06Records: #21 planmre
  • 64bc7823Records: #21 causemre
  • 76639655Records: B1 questionmre
  • d7906b36Records: mission 005 startedmre
  • d3df773cMission 005: doc linemre
  • 6a5d840aMission 005: jukebox#22mre
  • 13e5e748Records: mission 004 startedmre
  • a8098271Mission 004: jukebox#21mre
  • df8f5205Records: jukebox#19-21, #11 closedmre
  • b7a4e692Records: hybriel#298mre
  • 9bcbb017Records: day38b waits for day39 fixmre
  • f80504e1Records: day38b repro sentmre
  • 8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre
  • 68aace7fRecords: mission 003 day38bmre
  • d105d8a9Records: mpackdb integrity check cleanmre
  • 6e980c53Records: mpackdb rule refinementmre
  • 6d335ac4Records: storage copy rulingmre
  • 7eb2898dRecords: mpackdb second-opener rule until day38mre