gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf80504e1f80504e1Records: day38b repro sentmref80504e1/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

  • 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
  • b011f98eRecords: style form live on day35mre
  • 60d90cb2Records: L1 woken for the restartmre
  • 75ae544fRecords: restart waits for the connection to closemre
  • e0b75951Records: L1 merged and pushed, restart waits for an open connectionmre
  • f2b5db98styles: format styles with nested rules and bare queriesmre
  • f036bab4search: format styles with nested rules and bare queriesmre
  • ef9a9d4asongs: format styles with nested rules and bare queriesmre
  • f22f9aacmain: format styles with nested rules and bare queriesmre
  • f56cd7c7Sync icons from 8176eb1 and verify mixed component sourcesmre
  • d56e5054Sync theme and shared tokens from layouts 17e0f03mre
  • b1362547Re-vendor to Hybriel set day35mre
  • 89e10f08Records: mission 002 rollback wordingmre
  • 9485dee7Records: mission 002 brief (live step)mre