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
- 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
- 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
- c69cd5f3Merge branch 'pr-flow' into mainTickets
- cc56798cLog gitoria PR-only requestmre
- d876d0b2|||PR README: changes land as PRsmre
- fd83ac1fconductor: caramboleyo is the user, not owner/creatorApollo