tickets
All repositories: gitoria
6.6 KB
// lib/migrate.hl — THE MIGRATION OF TICKET #20 (projects as own data, members, new states). Statics only.// Idempotent: it looks at the SHAPE of the data, so a second run (and every start of the app, project.hl// calls migrateAll) changes nothing. What it does to a store from before:// 1. a project record `{ name, created }` becomes `{ title = name, slug = name, description = '', oldSlugs = '' }`// 2. every ticket points at its project by the project's id (`project`, `path` = '<id>/<number>'), not by name;// `createdBy` = the user of its 'created' event; the state gets its new name (awaiting creator → review,// a "Question…" ticket → pending; confirmed → done, rejected → reopened, in progress → progress, on hold →// pending, anything unknown → open); a ticket in review / pending is ASSIGNED to the creator's user// 3. the state events of the history get the new names too// 4. a project without members gets: the creator (TICKETS_CREATOR_IDENTITY, users.hl) as admin; the users// named Architect and AntColonyScheduler that wrote in it as edit; everybody else who wrote in it as use.// A project with no admin at all gets the creator as admin as soon as the creator is known.// TICKETS_CREATOR_IDENTITY is read ONLY here (the creator-only workflow is gone).// Writes no table itself (tickets#47): each topic file exposes the write as a function (projects.hl rewriteSlug / addProjectNamed /// addMember, tickets.hl moveToProject, events.hl renameStates) and this file calls those.import { countOf } from './util.hl'import { ensureCreatorUser, userRecord } from './users.hl'import { rewriteSlug, addProjectNamed, hasMembers, addMember, projectRecord, projectBySlug, projectRecords, adminCount, setNumberFloor } from './projects.hl'import { stateOf } from './tickets-helpers.hl'import { eventRecords, eventRecordsOf, renameStates, eventIdsOf, linkEventsNaming, removeEvent, compactEvents } from './events.hl'import { ticketRecords, ticketRecordsOf, moveToProject, ticketAt, removeLinksOf, forgetEventOf, removeTicket, compactTickets } from './tickets.hl'import { blankRowsOf, compactStream } from './stream.hl'import { dropRowsOf } from './comments.hl'import { purgeRowsOf } from './attachments.hl'static botNames = ['Architect' 'AntColonyScheduler']static migrateProjects = (&log) => {all = projectRecords()if (countOf(all) == 0) { return 0 }let n = 0for (p of all) {if (p.slug == null) {rewriteSlug(p)n = n + 1}}if (n > 0) { log.push(n + ' project(s) turned into records') }return n}static createdByOf = (t) => {all = eventRecordsOf(t.id)if (countOf(all) == 0) { return '' }for (e of all) { if (e.kind == 'created' && e.user != null) { return e.user } }return ''}static migrateTickets = (&log, creator) => {all = ticketRecords()if (countOf(all) == 0) { return 0 }let n = 0for (t of all) {if (projectRecord(t.project) == null) {let p = projectBySlug(t.project)if (p == null) {p = addProjectNamed(t.project)}let s = stateOf(t.state)if (t.state == 'awaiting creator' && t.subject != null && t.subject.startsWith('Question')) { s = 'pending' }if (s == null) { s = 'open' }let who = ''if ((s == 'review' || s == 'pending') && creator != null) { who = creator.id }moveToProject(t, p, s, createdByOf(t), who)n = n + 1}}if (n > 0) { log.push(n + ' ticket(s) linked to their project by id, states renamed') }return n}static migrateEvents = (&log) => {all = eventRecords()if (countOf(all) == 0) { return 0 }let n = 0for (e of all) {if (e.kind == 'state') {a = stateOf(e.from)b = stateOf(e.to)nf = a != null ? a : e.fromnt = b != null ? b : e.toif (nf != e.from || nt != e.to) {renameStates(e, nf, nt)n = n + 1}}}if (n > 0) { log.push(n + ' state event(s) renamed') }return n}static migrateMembers = (&log, creator) => {let n = 0for (p of projectRecords()) {if (!hasMembers(p.id)) {// who wrote in the project: users @id → truewrote = {}order = []tickets = ticketRecordsOf(p.id)if (countOf(tickets) > 0) {for (t of tickets) {evs = eventRecordsOf(t.id)if (countOf(evs) > 0) {for (e of evs) {if (e.user != null && e.user != '' && wrote[e.user] != true) {wrote[e.user] = trueorder.push(e.user)}}}}}for (uid of order) {u = userRecord(uid)if (u != null) { addMember(p.id, uid, botNames.includes(u.name) ? 'edit' : 'use') }}n = n + 1}if (creator != null && adminCount(p.id) == 0) {addMember(p.id, creator.id, 'admin')n = n + 1}}if (n > 0) { log.push('members set up in ' + n + ' project(s)') }return n}// ---- 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:// its record, history events, stream rows (emptied under their numbers: the counter stays whole), comment edits / deletions / likes,// attachment rows and files, the relation rows to and from it, and the link events other tickets hold about it. The project never// numbers 94 again (numberFloor). Idempotent: with no such ticket it reads and writes NOTHING. The ticket record goes LAST, so a start that// died half way finishes the job at the next start. The tables it changed are compacted, so no old bytes stay in the files.static purgeSlug = 'miserit-anthar'static purgeNumber = 94static purgeTicket94 = (&log) => {t = ticketAt(purgeSlug, purgeNumber)if (t == null) { return 0 }setNumberFloor(t.project, purgeNumber)ids = eventIdsOf(t.id)linked = linkEventsNaming(t.id)seen = {}for (id of ids) { seen[id] = true }for (l of linked) { seen[l.id] = true }blank = blankRowsOf(seen, t.id)for (l of linked) {removeEvent(l.id)forgetEventOf(l.owner)}files = purgeRowsOf(seen, t.id)rows = dropRowsOf(seen, t.id)for (id of ids) { removeEvent(id) }links = removeLinksOf(t.id)removeTicket(t.id)compactEvents()compactStream()compactTickets()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)')return 1}// answers the lines describing what changed (an empty list = nothing to do)static migrateAll = () => {log = []creator = ensureCreatorUser()migrateProjects(&log)migrateTickets(&log, creator)migrateEvents(&log)migrateMembers(&log, creator)purgeTicket94(&log)return log}
Branches
Latest commits
- 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
- 9df09aacmission 029: day38b re-vendor + deploymre
- d2834f65records: #94 backup planmre
- 4467d8cbrecords: #94 purge readymre
- aa2d124eREADME: the #94 purge gatemre
- e843ff7cOne-time purge of miserit-anthar#94 (#94, identity rule): idempotent step in lib/migrate.hl, fixture gate tests/purge94.mjsmre
- 506a4efdmission 028: #94, identity rulemre
- 78c7f48eRefine mpackdb holdmre
- 3d7d89c8Record mpackdb hold until day38mre
- f1bf7195#51 done; my subscription idmre
- 9870b945status: #51 proof greenmre