gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit4467d8cb4467d8cbrecords: #94 purge readymre4467d8cb/lib/migrate.hl

4.6 KB

  1. // lib/migrate.hl — THE MIGRATION OF TICKET #20 (projects as own data, members, new states). Statics only.
  2. // Idempotent: it looks at the SHAPE of the data, so a second run (and every start of the app, project.hl
  3. // calls migrateAll) changes nothing. What it does to a store from before:
  4. // 1. a project record `{ name, created }` becomes `{ title = name, slug = name, description = '', oldSlugs = '' }`
  5. // 2. every ticket points at its project by the project's id (`project`, `path` = '<id>/<number>'), not by name;
  6. // `createdBy` = the user of its 'created' event; the state gets its new name (awaiting creator → review,
  7. // a "Question…" ticket → pending; confirmed → done, rejected → reopened, in progress → progress, on hold →
  8. // pending, anything unknown → open); a ticket in review / pending is ASSIGNED to the creator's user
  9. // 3. the state events of the history get the new names too
  10. // 4. a project without members gets: the creator (TICKETS_CREATOR_IDENTITY, users.hl) as admin; the users
  11. // named Architect and AntColonyScheduler that wrote in it as edit; everybody else who wrote in it as use.
  12. // A project with no admin at all gets the creator as admin as soon as the creator is known.
  13. // TICKETS_CREATOR_IDENTITY is read ONLY here (the creator-only workflow is gone).
  14. // Writes no table itself (tickets#47): each topic file exposes the write as a function (projects.hl rewriteSlug / addProjectNamed /
  15. // addMember, tickets.hl moveToProject, events.hl renameStates) and this file calls those.
  16. import { countOf } from './util.hl'
  17. import { ensureCreatorUser, userRecord } from './users.hl'
  18. import { rewriteSlug, addProjectNamed, hasMembers, addMember, projectRecord, projectBySlug, projectRecords, adminCount } from './projects.hl'
  19. import { stateOf } from './tickets-helpers.hl'
  20. import { eventRecords, eventRecordsOf, renameStates } from './events.hl'
  21. import { ticketRecords, ticketRecordsOf, moveToProject } from './tickets.hl'
  22. static botNames = ['Architect' 'AntColonyScheduler']
  23. static migrateProjects = (&log) => {
  24. all = projectRecords()
  25. if (countOf(all) == 0) { return 0 }
  26. let n = 0
  27. for (p of all) {
  28. if (p.slug == null) {
  29. rewriteSlug(p)
  30. n = n + 1
  31. }
  32. }
  33. if (n > 0) { log.push(n + ' project(s) turned into records') }
  34. return n
  35. }
  36. static createdByOf = (t) => {
  37. all = eventRecordsOf(t.id)
  38. if (countOf(all) == 0) { return '' }
  39. for (e of all) { if (e.kind == 'created' && e.user != null) { return e.user } }
  40. return ''
  41. }
  42. static migrateTickets = (&log, creator) => {
  43. all = ticketRecords()
  44. if (countOf(all) == 0) { return 0 }
  45. let n = 0
  46. for (t of all) {
  47. if (projectRecord(t.project) == null) {
  48. let p = projectBySlug(t.project)
  49. if (p == null) {
  50. p = addProjectNamed(t.project)
  51. }
  52. let s = stateOf(t.state)
  53. if (t.state == 'awaiting creator' && t.subject != null && t.subject.startsWith('Question')) { s = 'pending' }
  54. if (s == null) { s = 'open' }
  55. let who = ''
  56. if ((s == 'review' || s == 'pending') && creator != null) { who = creator.id }
  57. moveToProject(t, p, s, createdByOf(t), who)
  58. n = n + 1
  59. }
  60. }
  61. if (n > 0) { log.push(n + ' ticket(s) linked to their project by id, states renamed') }
  62. return n
  63. }
  64. static migrateEvents = (&log) => {
  65. all = eventRecords()
  66. if (countOf(all) == 0) { return 0 }
  67. let n = 0
  68. for (e of all) {
  69. if (e.kind == 'state') {
  70. a = stateOf(e.from)
  71. b = stateOf(e.to)
  72. nf = a != null ? a : e.from
  73. nt = b != null ? b : e.to
  74. if (nf != e.from || nt != e.to) {
  75. renameStates(e, nf, nt)
  76. n = n + 1
  77. }
  78. }
  79. }
  80. if (n > 0) { log.push(n + ' state event(s) renamed') }
  81. return n
  82. }
  83. static migrateMembers = (&log, creator) => {
  84. let n = 0
  85. for (p of projectRecords()) {
  86. if (!hasMembers(p.id)) {
  87. // who wrote in the project: users @id → true
  88. wrote = {}
  89. order = []
  90. tickets = ticketRecordsOf(p.id)
  91. if (countOf(tickets) > 0) {
  92. for (t of tickets) {
  93. evs = eventRecordsOf(t.id)
  94. if (countOf(evs) > 0) {
  95. for (e of evs) {
  96. if (e.user != null && e.user != '' && wrote[e.user] != true) {
  97. wrote[e.user] = true
  98. order.push(e.user)
  99. }
  100. }
  101. }
  102. }
  103. }
  104. for (uid of order) {
  105. u = userRecord(uid)
  106. if (u != null) { addMember(p.id, uid, botNames.includes(u.name) ? 'edit' : 'use') }
  107. }
  108. n = n + 1
  109. }
  110. if (creator != null && adminCount(p.id) == 0) {
  111. addMember(p.id, creator.id, 'admin')
  112. n = n + 1
  113. }
  114. }
  115. if (n > 0) { log.push('members set up in ' + n + ' project(s)') }
  116. return n
  117. }
  118. // answers the lines describing what changed (an empty list = nothing to do)
  119. static migrateAll = () => {
  120. log = []
  121. creator = ensureCreatorUser()
  122. migrateProjects(&log)
  123. migrateTickets(&log, creator)
  124. migrateEvents(&log)
  125. migrateMembers(&log, creator)
  126. return log
  127. }

Branches

Latest commits

  • 4467d8cbrecords: #94 purge readymre
  • 506a4efdmission 028: #94, identity rulemre
  • 78c7f48eRefine mpackdb holdmre
  • 3d7d89c8Record mpackdb hold until day38mre
  • f1bf7195#51 done; my subscription idmre
  • 9870b945status: #51 proof greenmre
  • e92173c6log: #51 live push proofmre
  • 72d87041log: Hermes push livemre
  • 1d69bf7dTickets conductor: park until Hermes pushmre
  • 80d8cfd1Tickets conductor: #51 livemre
  • 61641dd9Complete subscriptions deployment evidencemre
  • c980856cRecord successful subscriptions deployment and live checksmre
  • 4b4710adMerge branch 's51-subscriptions'mre
  • a731ef7eTickets conductor: S51 reviewed, deploy stepmre
  • b487b05aRecord verified direct push protocol handoffmre
  • 74e34cc3Verify encrypted push secrets and direct push retry semanticsmre
  • a1ac5cd0Push subscription notices directly to signed HyperConductor chat endpointsmre
  • d662ad27Remove superseded waker service for direct chat push protocolmre
  • c0ac927aTickets conductor: S51 redo for push protocolmre
  • ff2e8701Finalize subscription build verification and handoff reportmre