tickets
All repositories: gitoria
4.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 } from './projects.hl'import { stateOf } from './tickets-helpers.hl'import { eventRecords, eventRecordsOf, renameStates } from './events.hl'import { ticketRecords, ticketRecordsOf, moveToProject } from './tickets.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}// 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)return log}
Branches
Latest commits
- 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
- 07c6daeeTickets conductor: push allowlist URLsmre
- 8517d14cTickets conductor: Hermes push endpointmre
- aa4e192cTickets conductor: brief 027 push protocol changemre
- 54bc5fe1Harden delta relevance, overflow caps and retry verificationmre
- 8d8e2053Document subscription contract and exercise delta deliverymre
- fd23726aAdd subscription delta API and signed wake bridgemre
- c5d28fb5Tickets conductor: S51 startedmre
- fd6ca1e6Tickets conductor: brief 027 waker design, push-test projectmre
- e448e656Tickets conductor: STATUS #51mre