gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit95f5faae95f5faae|||PR jukebox#7 Drop needless let declarationsmre95f5faae/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

  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre
  • 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
  • 6422a020Sync media-player at 51c3818mre
  • b582ba1cVendor complete Hybriel day72 plugin setmre
  • 02dccbc9Merge branch 'records-1119' into mainJukebox
  • a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
  • fc7db075Merge branch 'reconnect-retry' into mainJukebox
  • ac6f4c6fL2: plain declaration for a in pickedNextmre
  • 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
  • 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
  • 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
  • 1f0cd77bMerge branch 'records-day41' into mainJukebox
  • 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
  • 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
  • 04f5d9d5Merge branch 'day41' into mainJukebox
  • 8ed6da45|||PR README: media-player pin df9e7dfmre
  • d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre
  • 89cdabb1Vendor Hybriel day41 (57054d9e): plugin dirs, set .somre
  • 1fecd6a7Merge branch 'records-day39' into mainJukebox