tickets
All repositories: gitoria
5.0 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).// The one file that writes the tables of other topics (projects, members, tickets, events) directly: a data migration.import { now } from 'hl:time'import { merged, countOf } from './util.hl'import { ensureCreatorUser, userRecord } from './users.hl'import { projectsTable, membersTable, addMember, projectRecord, projectBySlug, projectRecords, adminCount } from './projects.hl'import { stateOf } from './tickets-helpers.hl'import { eventsTable } from './events.hl'import { ticketsTable } from './tickets.hl'static botNames = ['Architect' 'AntColonyScheduler']static migrateProjects = (&log) => {all = projectsTable.find(null, null)if (countOf(all) == 0) { return 0 }let n = 0for (p of all) {if (p.slug == null) {projectsTable.update(p.id, { id = p.id title = p.name slug = p.name description = '' oldSlugs = '' created = p.created })n = n + 1}}if (n > 0) { log.push(n + ' project(s) turned into records') }return n}static createdByOf = (t) => {all = eventsTable.find('ticket', 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 = ticketsTable.find(null, null)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) {let pid = projectsTable.put({ title = t.project slug = t.project description = '' oldSlugs = '' created = now() })p = projectRecord(pid)}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 }ticketsTable.update(t.id, merged(t, { project = p.id path = p.id + '/' + t.number state = s createdBy = createdByOf(t) assignee = 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 = eventsTable.find(null, null)if (countOf(all) == 0) { return 0 }let n = 0for (e of all) {if (e.kind == 'state') {let a = stateOf(e.from)let b = stateOf(e.to)let nf = a != null ? a : e.fromlet nt = b != null ? b : e.toif (nf != e.from || nt != e.to) {eventsTable.update(e.id, merged(e, { from = nf to = 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 (countOf(membersTable.find('project', p.id)) == 0) {// who wrote in the project: users @id → truelet wrote = {}let order = []let tickets = ticketsTable.find('project', p.id)if (countOf(tickets) > 0) {for (t of tickets) {let evs = eventsTable.find('ticket', 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) {let 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
- 18d2df60md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
- f6764bedreports/H1-hydrate.mdmre
- 1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre
- 6f503cfctests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- e17e2855re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- a6ddccd2re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
- 81e036b7docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
- 5d8d2cf6deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- 58e8c02cmission 024: report, LOG, STATUS, e2e fixmre
- 50778073tests/e2e-route-marker.mjs: first paint marker, comments post/edit redrawmre
- c5203298mission 024: MainMenu marks the page from the route (layouts 0bcc629 main-menu.hl); browser-side marker removed; gate: marker in the server HTMLmre
- b1a4c270re-vendor Hybriel master f9614007: bin/ (git-ignored) and plugins wholemre
- 866397a0mission 023: theme from layouts 76f99f6 (current marker, menu count badge), components from 3794c59 (MdEditor keys); Inbox count as badge, current by address; gates and E2E; reportmre
- 7ed2e5e5deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail), as gitoria/layoutsmre
- bf9064a3mission 022: tickets on the layouts theme (step 1): shell, styles, gates, audit, E2E; reportmre
- f3d61711mission 022 WIP: tickets on the layouts theme (dbe3de7): AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst shell, styles reduced to the app's own, check-theme in the gates, 390 audit + real-Chrome walk scriptmre
- 31cabfccmission 021: E2E script, report, LOG, STATUSmre
- 6aea8683editor look: .empty rule only for p.empty, files off where tickets has no upload, state note one line, events test scrolls the editor into view; synced md-editor (components d702d76+6f27ad3); gate 377/0, events 52/0mre
- dce6ffa6Merge branch 'w28-deflake'mre
- 536092a1tickets (mission 019): de-flake the m016 comment clicks (B: unliked) — calmClick waits until the button stops moving; test only, no app changemre