gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfd83ac1ffd83ac1fconductor: caramboleyo is the user, not owner/creatorApollofd83ac1f/lib/migrate.hl

6.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, setNumberFloor } from './projects.hl'
  19. import { stateOf } from './tickets-helpers.hl'
  20. import { eventRecords, eventRecordsOf, renameStates, eventIdsOf, linkEventsNaming, removeEvent, compactEvents } from './events.hl'
  21. import { ticketRecords, ticketRecordsOf, moveToProject, ticketAt, removeLinksOf, forgetEventOf, removeTicket, compactTickets } from './tickets.hl'
  22. import { blankRowsOf, compactStream } from './stream.hl'
  23. import { dropRowsOf } from './comments.hl'
  24. import { purgeRowsOf } from './attachments.hl'
  25. static botNames = ['Architect' 'AntColonyScheduler']
  26. static migrateProjects = (&log) => {
  27. all = projectRecords()
  28. if (countOf(all) == 0) { return 0 }
  29. let n = 0
  30. for (p of all) {
  31. if (p.slug == null) {
  32. rewriteSlug(p)
  33. n = n + 1
  34. }
  35. }
  36. if (n > 0) { log.push(n + ' project(s) turned into records') }
  37. return n
  38. }
  39. static createdByOf = (t) => {
  40. all = eventRecordsOf(t.id)
  41. if (countOf(all) == 0) { return '' }
  42. for (e of all) { if (e.kind == 'created' && e.user != null) { return e.user } }
  43. return ''
  44. }
  45. static migrateTickets = (&log, creator) => {
  46. all = ticketRecords()
  47. if (countOf(all) == 0) { return 0 }
  48. let n = 0
  49. for (t of all) {
  50. if (projectRecord(t.project) == null) {
  51. let p = projectBySlug(t.project)
  52. if (p == null) {
  53. p = addProjectNamed(t.project)
  54. }
  55. let s = stateOf(t.state)
  56. if (t.state == 'awaiting creator' && t.subject != null && t.subject.startsWith('Question')) { s = 'pending' }
  57. if (s == null) { s = 'open' }
  58. let who = ''
  59. if ((s == 'review' || s == 'pending') && creator != null) { who = creator.id }
  60. moveToProject(t, p, s, createdByOf(t), who)
  61. n = n + 1
  62. }
  63. }
  64. if (n > 0) { log.push(n + ' ticket(s) linked to their project by id, states renamed') }
  65. return n
  66. }
  67. static migrateEvents = (&log) => {
  68. all = eventRecords()
  69. if (countOf(all) == 0) { return 0 }
  70. let n = 0
  71. for (e of all) {
  72. if (e.kind == 'state') {
  73. a = stateOf(e.from)
  74. b = stateOf(e.to)
  75. nf = a != null ? a : e.from
  76. nt = b != null ? b : e.to
  77. if (nf != e.from || nt != e.to) {
  78. renameStates(e, nf, nt)
  79. n = n + 1
  80. }
  81. }
  82. }
  83. if (n > 0) { log.push(n + ' state event(s) renamed') }
  84. return n
  85. }
  86. static migrateMembers = (&log, creator) => {
  87. let n = 0
  88. for (p of projectRecords()) {
  89. if (!hasMembers(p.id)) {
  90. // who wrote in the project: users @id → true
  91. wrote = {}
  92. order = []
  93. tickets = ticketRecordsOf(p.id)
  94. if (countOf(tickets) > 0) {
  95. for (t of tickets) {
  96. evs = eventRecordsOf(t.id)
  97. if (countOf(evs) > 0) {
  98. for (e of evs) {
  99. if (e.user != null && e.user != '' && wrote[e.user] != true) {
  100. wrote[e.user] = true
  101. order.push(e.user)
  102. }
  103. }
  104. }
  105. }
  106. }
  107. for (uid of order) {
  108. u = userRecord(uid)
  109. if (u != null) { addMember(p.id, uid, botNames.includes(u.name) ? 'edit' : 'use') }
  110. }
  111. n = n + 1
  112. }
  113. if (creator != null && adminCount(p.id) == 0) {
  114. addMember(p.id, creator.id, 'admin')
  115. n = n + 1
  116. }
  117. }
  118. if (n > 0) { log.push('members set up in ' + n + ' project(s)') }
  119. return n
  120. }
  121. // ---- the one-time purge of miserit-anthar#94 (identity rule, mission 028; the creator's order, through Apollo). Names in code: "#94, identity rule". It removes everything of that one ticket and nothing else:
  122. // its record, history events, stream rows (emptied under their numbers: the counter stays whole), comment edits / deletions / likes,
  123. // attachment rows and files, the relation rows to and from it, and the link events other tickets hold about it. The project never
  124. // numbers 94 again (numberFloor). Idempotent: with no such ticket it reads and writes NOTHING. The ticket record goes LAST, so a start that
  125. // died half way finishes the job at the next start. The tables it changed are compacted, so no old bytes stay in the files.
  126. static purgeSlug = 'miserit-anthar'
  127. static purgeNumber = 94
  128. static purgeTicket94 = (&log) => {
  129. t = ticketAt(purgeSlug, purgeNumber)
  130. if (t == null) { return 0 }
  131. setNumberFloor(t.project, purgeNumber)
  132. ids = eventIdsOf(t.id)
  133. linked = linkEventsNaming(t.id)
  134. seen = {}
  135. for (id of ids) { seen[id] = true }
  136. for (l of linked) { seen[l.id] = true }
  137. blank = blankRowsOf(seen, t.id)
  138. for (l of linked) {
  139. removeEvent(l.id)
  140. forgetEventOf(l.owner)
  141. }
  142. files = purgeRowsOf(seen, t.id)
  143. rows = dropRowsOf(seen, t.id)
  144. for (id of ids) { removeEvent(id) }
  145. links = removeLinksOf(t.id)
  146. removeTicket(t.id)
  147. compactEvents()
  148. compactStream()
  149. compactTickets()
  150. log.push('#94, identity rule: purged (' + ids.length + ' history events, ' + blank + ' stream rows emptied, ' + files.rows + ' attachments, ' + files.files + ' files, ' + rows + ' comment rows, ' + links + ' relations, ' + linked.length + ' link events of other tickets)')
  151. return 1
  152. }
  153. // answers the lines describing what changed (an empty list = nothing to do)
  154. static migrateAll = () => {
  155. log = []
  156. creator = ensureCreatorUser()
  157. migrateProjects(&log)
  158. migrateTickets(&log, creator)
  159. migrateEvents(&log)
  160. migrateMembers(&log, creator)
  161. purgeTicket94(&log)
  162. return log
  163. }

Branches

Latest commits

  • fd83ac1fconductor: caramboleyo is the user, not owner/creatorApollo
  • 3b858c91Log backup hard-link fixmre
  • 7f6b37a0deploy.sh backup: tar --hard-dereference (hard links broke mpackdb sidecars on restore)mre
  • e93711d9Log E30 livemre
  • 59c02e4dMerge e30: preserve edited state note labels in Markdownmre
  • 30970796Log E30 deploy GOmre
  • 7c8e6d83Limit edited state note fix to Markdown renderingmre
  • 910536d0Log E30 reviewmre
  • 36984386Preserve state transitions when their notes are editedmre
  • d75cb946Log E30 startmre
  • 0bf3fefaMission 030: edited state note labelmre
  • 691565c6Log neutral-ticket rule checkmre
  • bc3bdecerecords: day38b live, #94 purgedmre
  • f6c5aa0dMerge main (records)mre
  • e23d42acconnect gate: wait for hydration before clicking Disconnectmre
  • a5d45d00records: D38 cause, GOmre
  • 19eeb938records: D38 gates, two day38b failuresmre
  • f8e42a85Re-vendor tickets to Hybriel set day38b (1e554d7)mre
  • 51645016Merge purge-94 (#94, identity rule)mre
  • 94d6ca2arecords: D38 startedmre