gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8ed6da458ed6da45|||PR README: media-player pin df9e7dfmre8ed6da45/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

  • 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
  • d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmre
  • 5fa19e89Merge branch 'day39' into mainJukebox
  • cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
  • f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
  • 9f5c6532Merge branch 'status-22-pr' into mainJukebox
  • 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
  • 29d2029cRecords: PR-only rule (Kunibert)mre
  • adacb0abRecords: neutral ticket rule, #22 decision recordedmre
  • b2d6f121Records: #308 hold liftedmre
  • 7ab67533Records: day39 on hold (hybriel#308)mre
  • 22f21739Records: note rebase before mergemre
  • f7368ea3Records: mission 011 day39, waits for lisbethmre
  • 9515d2cdRecords: jb20 livemre
  • 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
  • 277a2722README: provenance linemre
  • 4169ca6aREADME: sync pinmre