gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchl33-thinecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mrel33-thin/lib/migrate.hl

6.7 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. }
  164. static migrateAtStartup = () => {
  165. for (line of migrateAll()) { console.log('migrated: ' + line) }
  166. }

Branches

Latest commits

  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre
  • 0788e65f|||PR re-vendor Hybriel day72mre
  • e2a6bdcfMerge branch 'records-t35' into mainTickets
  • d8d54df1|||PR records: R35 day72 + #40mre
  • 8a7f475aMerge branch 'records-t33' into mainTickets
  • e685d0c2|||PR records: PROCEDURES merge callmre
  • b42aff2b|||PR records: GO 2026-11-23, workers L33 O34, PROCEDURES.mdmre
  • ed091d44Merge branch 'records' into mainTickets
  • 180c0cdb|||PR records: ticket move live (M32), hybriel#439mre
  • 497cae7bMerge branch 'm32-move' into mainTickets
  • 772e0696|||PR Allow project admins to move tickets between their projectsmre
  • be92a560Merge branch 'records' into mainTickets
  • 0daf2ea8|||PR records: PR-only workflow, #50 donemre
  • 0185d0b6Log PR 1 deploymre
  • f5bf16e2Mission 031: deploy PR 1mre