@openinc/parse-server-opendash 4.6.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/features/schema/helper/migrationMode.js +2 -0
- package/dist/hooks/Service_Schedule.js +7 -0
- package/dist/hooks/Service_Schedule_Template.js +5 -0
- package/dist/scripts/migration/lib/articleMeta.d.ts +34 -10
- package/dist/scripts/migration/lib/articleMeta.js +58 -11
- package/dist/scripts/migration/lib/cadence.d.ts +75 -0
- package/dist/scripts/migration/lib/cadence.js +246 -0
- package/dist/scripts/migration/lib/env.d.ts +5 -0
- package/dist/scripts/migration/lib/env.js +23 -0
- package/dist/scripts/migration/lib/equipmentMeta.d.ts +65 -0
- package/dist/scripts/migration/lib/equipmentMeta.js +155 -0
- package/dist/scripts/migration/lib/schedule.d.ts +306 -0
- package/dist/scripts/migration/lib/schedule.js +613 -0
- package/dist/scripts/migration/passes/03-equipment.js +181 -4
- package/dist/scripts/migration/passes/05-articles.d.ts +12 -15
- package/dist/scripts/migration/passes/05-articles.js +83 -33
- package/dist/scripts/migration/passes/13-schedule-templates.d.ts +15 -0
- package/dist/scripts/migration/passes/13-schedule-templates.js +163 -0
- package/dist/scripts/migration/passes/14-schedules.d.ts +30 -0
- package/dist/scripts/migration/passes/14-schedules.js +239 -0
- package/dist/scripts/migration/passes/15-executions.d.ts +34 -0
- package/dist/scripts/migration/passes/15-executions.js +244 -0
- package/dist/scripts/migration/passes/16-schedule-meta.d.ts +23 -0
- package/dist/scripts/migration/passes/16-schedule-meta.js +308 -0
- package/dist/scripts/migration/passes/17-schedule-assets.d.ts +30 -0
- package/dist/scripts/migration/passes/17-schedule-assets.js +240 -0
- package/dist/scripts/migration/passes/18-calendar-links.d.ts +25 -0
- package/dist/scripts/migration/passes/18-calendar-links.js +132 -0
- package/dist/scripts/migration/passes/19-schedule-history.d.ts +18 -0
- package/dist/scripts/migration/passes/19-schedule-history.js +186 -0
- package/dist/scripts/migration/run.js +20 -9
- package/dist/scripts/migration/verify.js +450 -12
- package/dist/scripts/seed-v1-testdata.d.ts +2 -0
- package/dist/scripts/seed-v1-testdata.js +449 -10
- package/dist/types/Service_Schedule.d.ts +3 -0
- package/dist/types/Service_Schedule.js +6 -0
- package/dist/types/Service_Schedule_Execution.d.ts +1 -1
- package/package.json +1 -1
- package/schema/Service_Schedule.json +4 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Pass } from "../lib/pass.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pass 14 — `OD3_Maintenance_Schedule` → `OD3_Service_Schedule`.
|
|
4
|
+
*
|
|
5
|
+
* A v1 plan is only half of itself: its interval is laid over its
|
|
6
|
+
* template's, and its steps are the template's when it has none of its own.
|
|
7
|
+
* v2 has no inheritance — a template is copied, then forgotten — so each plan
|
|
8
|
+
* is written as the **effective** plan v1 actually ran:
|
|
9
|
+
*
|
|
10
|
+
* - **cadence**: the plan's `cron` merged over the template's
|
|
11
|
+
* (`mergeScheduleInterval`, as v1's frontend and scheduler did), then
|
|
12
|
+
* translated to an RRULE (`lib/cadence.ts`).
|
|
13
|
+
* - **steps**: the plan's own, else the template's, each with a step id of its
|
|
14
|
+
* own to this plan (`planStepId`).
|
|
15
|
+
* - **notifications**: the plan's `notifyBeforeDue`, else the template's.
|
|
16
|
+
*
|
|
17
|
+
* Visibility carries over exactly. v1 plans were already private — the
|
|
18
|
+
* afterSave gave the creator read+write and denied tenant users — and v2
|
|
19
|
+
* plans are private the same way. What v1 granted beyond that becomes an
|
|
20
|
+
* assignment, because v2 derives the ACL from the assignments on every save.
|
|
21
|
+
*
|
|
22
|
+
* `enabled: false` becomes `active: false`: v1 kept a disabled plan
|
|
23
|
+
* reachable (the detail page toggles it back), it just stopped scheduling —
|
|
24
|
+
* which is what an inactive v2 plan is. Not archived.
|
|
25
|
+
*
|
|
26
|
+
* `description` copies across. `lastExecution` is not carried — v1 only
|
|
27
|
+
* maintained it on one code path, and v2 derives it from the executions
|
|
28
|
+
* (pass 15).
|
|
29
|
+
*/
|
|
30
|
+
export declare const pass14: Pass;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pass14 = void 0;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../../../types/index.js");
|
|
9
|
+
const acl_js_1 = require("../lib/acl.js");
|
|
10
|
+
const cadence_js_1 = require("../lib/cadence.js");
|
|
11
|
+
const latest_js_1 = require("../lib/latest.js");
|
|
12
|
+
const map_js_1 = require("../lib/map.js");
|
|
13
|
+
const pass_js_1 = require("../lib/pass.js");
|
|
14
|
+
const ptr_js_1 = require("../lib/ptr.js");
|
|
15
|
+
const schedule_js_1 = require("../lib/schedule.js");
|
|
16
|
+
const ticket_js_1 = require("../lib/ticket.js");
|
|
17
|
+
const _08_tickets_js_1 = require("./08-tickets.js");
|
|
18
|
+
/** v2 accepts a colour override only as `#rrggbb`. */
|
|
19
|
+
const HEX_COLOR = /^#[0-9a-f]{6}$/i;
|
|
20
|
+
/**
|
|
21
|
+
* Pass 14 — `OD3_Maintenance_Schedule` → `OD3_Service_Schedule`.
|
|
22
|
+
*
|
|
23
|
+
* A v1 plan is only half of itself: its interval is laid over its
|
|
24
|
+
* template's, and its steps are the template's when it has none of its own.
|
|
25
|
+
* v2 has no inheritance — a template is copied, then forgotten — so each plan
|
|
26
|
+
* is written as the **effective** plan v1 actually ran:
|
|
27
|
+
*
|
|
28
|
+
* - **cadence**: the plan's `cron` merged over the template's
|
|
29
|
+
* (`mergeScheduleInterval`, as v1's frontend and scheduler did), then
|
|
30
|
+
* translated to an RRULE (`lib/cadence.ts`).
|
|
31
|
+
* - **steps**: the plan's own, else the template's, each with a step id of its
|
|
32
|
+
* own to this plan (`planStepId`).
|
|
33
|
+
* - **notifications**: the plan's `notifyBeforeDue`, else the template's.
|
|
34
|
+
*
|
|
35
|
+
* Visibility carries over exactly. v1 plans were already private — the
|
|
36
|
+
* afterSave gave the creator read+write and denied tenant users — and v2
|
|
37
|
+
* plans are private the same way. What v1 granted beyond that becomes an
|
|
38
|
+
* assignment, because v2 derives the ACL from the assignments on every save.
|
|
39
|
+
*
|
|
40
|
+
* `enabled: false` becomes `active: false`: v1 kept a disabled plan
|
|
41
|
+
* reachable (the detail page toggles it back), it just stopped scheduling —
|
|
42
|
+
* which is what an inactive v2 plan is. Not archived.
|
|
43
|
+
*
|
|
44
|
+
* `description` copies across. `lastExecution` is not carried — v1 only
|
|
45
|
+
* maintained it on one code path, and v2 derives it from the executions
|
|
46
|
+
* (pass 15).
|
|
47
|
+
*/
|
|
48
|
+
exports.pass14 = {
|
|
49
|
+
id: "14",
|
|
50
|
+
title: "schedules",
|
|
51
|
+
needs: ["03"],
|
|
52
|
+
async run({ config, map, report, entry }) {
|
|
53
|
+
const roleIdByName = new Map([...(await (0, ticket_js_1.loadRoleNames)(config))].map(([id, name]) => [name, id]));
|
|
54
|
+
const steps = new schedule_js_1.StepSource(config.batchSize);
|
|
55
|
+
let manual = 0;
|
|
56
|
+
let oneOff = 0;
|
|
57
|
+
let monthEnd = 0;
|
|
58
|
+
let inheritedSteps = 0;
|
|
59
|
+
let inactive = 0;
|
|
60
|
+
let unrestricted = 0;
|
|
61
|
+
let withProviders = 0;
|
|
62
|
+
for await (const page of (0, pass_js_1.pages)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule), config.tenantId)
|
|
63
|
+
.include("template")
|
|
64
|
+
.include("source"), config.batchSize)) {
|
|
65
|
+
for (const plan of page) {
|
|
66
|
+
const sourceId = plan.id;
|
|
67
|
+
if (!sourceId)
|
|
68
|
+
continue;
|
|
69
|
+
const template = plan.get("template");
|
|
70
|
+
const source = plan.get("source");
|
|
71
|
+
const label = `plan ${sourceId} ("${plan.get("title") ?? ""}")`;
|
|
72
|
+
// `tenant` is optional on the v1 plan but required on v2; the template
|
|
73
|
+
// and the machine name the same tenant when the plan does not.
|
|
74
|
+
const tenantId = (0, pass_js_1.refId)(plan.get("tenant")) ??
|
|
75
|
+
(0, pass_js_1.refId)(template?.get("tenant")) ??
|
|
76
|
+
(0, pass_js_1.refId)(source?.get("tenant"));
|
|
77
|
+
if (!tenantId) {
|
|
78
|
+
report.error(entry, `${label} has no tenant; Schedule.tenant is required — skipped`);
|
|
79
|
+
entry.skipped++;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const existingId = map.get(index_js_1.Maintenance_Schedule.className, sourceId);
|
|
83
|
+
const target = existingId
|
|
84
|
+
? new index_js_1.Service_Schedule({ objectId: existingId })
|
|
85
|
+
: new index_js_1.Service_Schedule();
|
|
86
|
+
// ── timing ─────────────────────────────────────────────────────────
|
|
87
|
+
const interval = (0, cadence_js_1.mergeScheduleInterval)(template?.get("cron"), plan.get("cron"));
|
|
88
|
+
const { cadence, warnings, notes } = (0, cadence_js_1.toCadence)(interval, {
|
|
89
|
+
timezone: config.timezone,
|
|
90
|
+
fallbackStart: plan.createdAt,
|
|
91
|
+
});
|
|
92
|
+
for (const warning of warnings)
|
|
93
|
+
report.warn(entry, `${label}: ${warning}`);
|
|
94
|
+
if (cadence.kind === "manual")
|
|
95
|
+
manual += 1;
|
|
96
|
+
if (notes.includes("one-off"))
|
|
97
|
+
oneOff += 1;
|
|
98
|
+
if (notes.includes("month-end"))
|
|
99
|
+
monthEnd += 1;
|
|
100
|
+
// ── steps ──────────────────────────────────────────────────────────
|
|
101
|
+
const { rows, inherited } = await steps.ofPlan(plan);
|
|
102
|
+
if (inherited)
|
|
103
|
+
inheritedSteps += 1;
|
|
104
|
+
// ── who ────────────────────────────────────────────────────────────
|
|
105
|
+
const access = (0, schedule_js_1.readV1Access)(plan, tenantId);
|
|
106
|
+
const explicitRoles = (0, schedule_js_1.resolveRoles)(access.readerRoleNames, roleIdByName);
|
|
107
|
+
const roles = (0, schedule_js_1.resolveRoles)((0, schedule_js_1.assignedRoleNames)(access, tenantId), roleIdByName);
|
|
108
|
+
if (access.unrestricted)
|
|
109
|
+
unrestricted += 1;
|
|
110
|
+
if (roles.unknown.length) {
|
|
111
|
+
report.warn(entry, `${label}: ACL names role(s) ${roles.unknown.join(", ")} that no ` +
|
|
112
|
+
`longer exist — not carried over`);
|
|
113
|
+
}
|
|
114
|
+
if (access.demotedWriterIds.length) {
|
|
115
|
+
report.warn(entry, `${label}: ${access.demotedWriterIds.length} user(s) besides the ` +
|
|
116
|
+
`creator could edit it in v1 — they are assigned in v2, which ` +
|
|
117
|
+
`lets them read it only`);
|
|
118
|
+
}
|
|
119
|
+
const rules = (0, schedule_js_1.notificationRules)(`${index_js_1.Maintenance_Schedule.className}:${sourceId}`, (0, schedule_js_1.effectiveNotifyBeforeDue)(plan, template), (0, schedule_js_1.v1Recipients)(access, explicitRoles.ids));
|
|
120
|
+
if (rules.deviation)
|
|
121
|
+
report.warn(entry, `${label}: ${rules.deviation}`);
|
|
122
|
+
const contactIds = await (0, latest_js_1.relationIds)(plan, "contacts", config.batchSize);
|
|
123
|
+
if (contactIds.length)
|
|
124
|
+
withProviders += 1;
|
|
125
|
+
// ── machine ────────────────────────────────────────────────────────
|
|
126
|
+
const v1SourceId = (0, pass_js_1.refId)(plan.get("source"));
|
|
127
|
+
const equipmentId = v1SourceId
|
|
128
|
+
? map.get(index_js_1.Source.className, v1SourceId)
|
|
129
|
+
: undefined;
|
|
130
|
+
const equipmentPtr = (0, ptr_js_1.maybePtr)(index_js_1.Service_Equipment.className, equipmentId);
|
|
131
|
+
if (equipmentPtr)
|
|
132
|
+
target.set("equipment", equipmentPtr);
|
|
133
|
+
else if (v1SourceId) {
|
|
134
|
+
report.warn(entry, `${label}: source ${v1SourceId} has no Equipment — the plan has no ` +
|
|
135
|
+
`machine and will not appear in the machine book (run pass 03 first)`);
|
|
136
|
+
}
|
|
137
|
+
// ── the rest ───────────────────────────────────────────────────────
|
|
138
|
+
const title = String(plan.get("title") ?? "").trim() ||
|
|
139
|
+
[source?.get("name"), template?.get("title")]
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.join(" - ") ||
|
|
142
|
+
`Wartungsplan ${sourceId}`;
|
|
143
|
+
target.set("title", title);
|
|
144
|
+
target.set("tenant", (0, ptr_js_1.tenantPtr)(tenantId));
|
|
145
|
+
target.set("active", plan.get("enabled") === true);
|
|
146
|
+
if (plan.get("enabled") !== true)
|
|
147
|
+
inactive += 1;
|
|
148
|
+
target.set("cadence", cadence);
|
|
149
|
+
target.set("steps", rows.map((row, index) => (0, schedule_js_1.toV2Step)(row, (0, schedule_js_1.planStepId)(sourceId, row.id), index, true)));
|
|
150
|
+
target.set("serviceProviders", (0, schedule_js_1.serviceProviders)(contactIds));
|
|
151
|
+
target.set("notifications", rules.rules);
|
|
152
|
+
target.set("coversTasks", []);
|
|
153
|
+
// v1's overdue rule: "due more than a day ago"
|
|
154
|
+
// (`isScheduleOverdue`). One day of grace is the same line in v2.
|
|
155
|
+
target.set("graceDays", 1);
|
|
156
|
+
target.set("origin", (0, _08_tickets_js_1.legacyOrigin)(sourceId));
|
|
157
|
+
if (access.creatorId)
|
|
158
|
+
target.set("user", (0, ptr_js_1.userPtr)(access.creatorId));
|
|
159
|
+
const color = plan.get("color");
|
|
160
|
+
if (typeof color === "string" && HEX_COLOR.test(color)) {
|
|
161
|
+
target.set("color", color);
|
|
162
|
+
}
|
|
163
|
+
else if (color) {
|
|
164
|
+
report.warn(entry, `${label}: colour "${color}" is not #rrggbb — dropped`);
|
|
165
|
+
}
|
|
166
|
+
const description = String(plan.get("description") ?? "").trim();
|
|
167
|
+
if (description)
|
|
168
|
+
target.set("description", description);
|
|
169
|
+
if (!existingId) {
|
|
170
|
+
target.setACL((0, schedule_js_1.privateAcl)({
|
|
171
|
+
tenantId,
|
|
172
|
+
creatorId: access.creatorId,
|
|
173
|
+
roleNames: roles.names,
|
|
174
|
+
userIds: access.readerUserIds,
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
if (config.dryRun) {
|
|
178
|
+
existingId ? entry.updated++ : entry.created++;
|
|
179
|
+
if (!existingId) {
|
|
180
|
+
await map.record(index_js_1.Maintenance_Schedule.className, sourceId, index_js_1.Service_Schedule.className, map_js_1.MigrationMap.dryId(sourceId));
|
|
181
|
+
}
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const newId = await (0, acl_js_1.saveMigrated)(config, target, {
|
|
186
|
+
className: index_js_1.Service_Schedule.className,
|
|
187
|
+
isNew: !existingId,
|
|
188
|
+
createdAt: plan.createdAt,
|
|
189
|
+
updatedAt: plan.updatedAt,
|
|
190
|
+
});
|
|
191
|
+
await (0, schedule_js_1.addAssignments)(index_js_1.Service_Schedule.className, newId, {
|
|
192
|
+
roleIds: roles.ids,
|
|
193
|
+
userIds: access.readerUserIds,
|
|
194
|
+
});
|
|
195
|
+
if (existingId) {
|
|
196
|
+
entry.updated++;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
entry.created++;
|
|
200
|
+
await map.record(index_js_1.Maintenance_Schedule.className, sourceId, index_js_1.Service_Schedule.className, newId);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
report.error(entry, `${label} failed: ${error.message}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (manual > 0) {
|
|
209
|
+
report.info(entry, `${manual} plan(s) without a usable interval → manual (v1 never ` +
|
|
210
|
+
`scheduled them either; warnings above name the odd ones)`);
|
|
211
|
+
}
|
|
212
|
+
if (oneOff > 0) {
|
|
213
|
+
report.info(entry, `${oneOff} plan(s) with interval number 0 → a single appointment on the ` +
|
|
214
|
+
`start date, as v1's editor promised (v1's own iterator repeated them)`);
|
|
215
|
+
}
|
|
216
|
+
if (monthEnd > 0) {
|
|
217
|
+
report.info(entry, `${monthEnd} plan(s) start on a month end — their rule uses BYSETPOS to ` +
|
|
218
|
+
`keep v1's "last day of shorter months"; the series editor simplifies ` +
|
|
219
|
+
`it when re-edited`);
|
|
220
|
+
}
|
|
221
|
+
if (inheritedSteps > 0) {
|
|
222
|
+
report.info(entry, `${inheritedSteps} plan(s) had no steps of their own — they carry their ` +
|
|
223
|
+
`template's, as v1 used them`);
|
|
224
|
+
}
|
|
225
|
+
if (inactive > 0) {
|
|
226
|
+
report.info(entry, `${inactive} disabled plan(s) → active: false`);
|
|
227
|
+
}
|
|
228
|
+
if (unrestricted > 0) {
|
|
229
|
+
report.info(entry, `${unrestricted} plan(s) had no ACL (master-key writes, e.g. the v1 ` +
|
|
230
|
+
`Outlook import) or public read — assigned to the tenant's user ` +
|
|
231
|
+
`role, so its users still see them; their rules do not notify that ` +
|
|
232
|
+
`role, as v1 notified nobody`);
|
|
233
|
+
}
|
|
234
|
+
if (withProviders > 0) {
|
|
235
|
+
report.info(entry, `${withProviders} plan(s) list contacts → service providers with ` +
|
|
236
|
+
`notify: false (v1 never mailed them)`);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Pass } from "../lib/pass.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pass 15 — `OD3_Maintenance_Schedule_Execution` (+ its `_Execution_Step`
|
|
4
|
+
* rows) → `OD3_Service_Schedule_Execution`.
|
|
5
|
+
*
|
|
6
|
+
* Each v1 execution step row becomes two things on the v2 execution: an entry
|
|
7
|
+
* in `steps` — the frozen snapshot a protocol shows, which is exactly what the
|
|
8
|
+
* v1 row is, since v1 copied title and description onto it at start — and a
|
|
9
|
+
* `stepResults` entry with its `done` flag. The ids of both come from
|
|
10
|
+
* `executionStepIds`, which pass 16 uses for the captured values too.
|
|
11
|
+
*
|
|
12
|
+
* Three kinds of v1 run:
|
|
13
|
+
*
|
|
14
|
+
* - **completed** → `completedAt` = `finishedAt`, `performedBy` = the v1
|
|
15
|
+
* `user`, the only person v1 recorded. A step left undone on a completed
|
|
16
|
+
* run was skipped (v1's direct maintenance allowed it) and says so.
|
|
17
|
+
* - **open** (no `finishedAt`) → migrated open, and resumable in v2 exactly
|
|
18
|
+
* as it was in v1.
|
|
19
|
+
* - **abandoned** (`terminated`, or a plan run finished with open steps) →
|
|
20
|
+
* **not migrated**, counted and sampled. See `classifyExecution`.
|
|
21
|
+
*
|
|
22
|
+
* An execution without a plan is v1's "Direkte Wartung". v2 has the same
|
|
23
|
+
* thing since 2026-09-25: no `schedule`, the machine in `equipment`, its own
|
|
24
|
+
* title, description and steps.
|
|
25
|
+
*
|
|
26
|
+
* v1 recorded material per *execution*, v2 per *step*. It goes onto one
|
|
27
|
+
* synthetic, completed step at the end ("Verbrauchtes Material"), because
|
|
28
|
+
* attaching it to a real step would claim that step consumed it. The
|
|
29
|
+
* protocol's "Material insgesamt" adds it up either way.
|
|
30
|
+
*
|
|
31
|
+
* `occurrence` is left unset: v1 never recorded which due date a run
|
|
32
|
+
* settled, and v2 pairs such executions with the nearest occurrence itself.
|
|
33
|
+
*/
|
|
34
|
+
export declare const pass15: Pass;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pass15 = void 0;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../../../types/index.js");
|
|
9
|
+
const acl_js_1 = require("../lib/acl.js");
|
|
10
|
+
const map_js_1 = require("../lib/map.js");
|
|
11
|
+
const material_js_1 = require("../lib/material.js");
|
|
12
|
+
const pass_js_1 = require("../lib/pass.js");
|
|
13
|
+
const ptr_js_1 = require("../lib/ptr.js");
|
|
14
|
+
const schedule_js_1 = require("../lib/schedule.js");
|
|
15
|
+
/** Title of the step that carries a v1 execution's material. */
|
|
16
|
+
const MATERIAL_STEP_TITLE = "Verbrauchtes Material";
|
|
17
|
+
/** What the v2 frontend calls a direct maintenance without a title. */
|
|
18
|
+
const DIRECT_TITLE = "Direkte Wartung";
|
|
19
|
+
/**
|
|
20
|
+
* Pass 15 — `OD3_Maintenance_Schedule_Execution` (+ its `_Execution_Step`
|
|
21
|
+
* rows) → `OD3_Service_Schedule_Execution`.
|
|
22
|
+
*
|
|
23
|
+
* Each v1 execution step row becomes two things on the v2 execution: an entry
|
|
24
|
+
* in `steps` — the frozen snapshot a protocol shows, which is exactly what the
|
|
25
|
+
* v1 row is, since v1 copied title and description onto it at start — and a
|
|
26
|
+
* `stepResults` entry with its `done` flag. The ids of both come from
|
|
27
|
+
* `executionStepIds`, which pass 16 uses for the captured values too.
|
|
28
|
+
*
|
|
29
|
+
* Three kinds of v1 run:
|
|
30
|
+
*
|
|
31
|
+
* - **completed** → `completedAt` = `finishedAt`, `performedBy` = the v1
|
|
32
|
+
* `user`, the only person v1 recorded. A step left undone on a completed
|
|
33
|
+
* run was skipped (v1's direct maintenance allowed it) and says so.
|
|
34
|
+
* - **open** (no `finishedAt`) → migrated open, and resumable in v2 exactly
|
|
35
|
+
* as it was in v1.
|
|
36
|
+
* - **abandoned** (`terminated`, or a plan run finished with open steps) →
|
|
37
|
+
* **not migrated**, counted and sampled. See `classifyExecution`.
|
|
38
|
+
*
|
|
39
|
+
* An execution without a plan is v1's "Direkte Wartung". v2 has the same
|
|
40
|
+
* thing since 2026-09-25: no `schedule`, the machine in `equipment`, its own
|
|
41
|
+
* title, description and steps.
|
|
42
|
+
*
|
|
43
|
+
* v1 recorded material per *execution*, v2 per *step*. It goes onto one
|
|
44
|
+
* synthetic, completed step at the end ("Verbrauchtes Material"), because
|
|
45
|
+
* attaching it to a real step would claim that step consumed it. The
|
|
46
|
+
* protocol's "Material insgesamt" adds it up either way.
|
|
47
|
+
*
|
|
48
|
+
* `occurrence` is left unset: v1 never recorded which due date a run
|
|
49
|
+
* settled, and v2 pairs such executions with the nearest occurrence itself.
|
|
50
|
+
*/
|
|
51
|
+
exports.pass15 = {
|
|
52
|
+
id: "15",
|
|
53
|
+
title: "executions",
|
|
54
|
+
needs: ["03", "05", "14"],
|
|
55
|
+
async run({ config, map, report, entry }) {
|
|
56
|
+
const plans = await schedule_js_1.PlanIndex.load(config);
|
|
57
|
+
const stepsByExecution = await (0, schedule_js_1.executionStepsByExecution)(config);
|
|
58
|
+
let completed = 0;
|
|
59
|
+
let open = 0;
|
|
60
|
+
let direct = 0;
|
|
61
|
+
let viaTemplate = 0;
|
|
62
|
+
let withMaterial = 0;
|
|
63
|
+
const abandoned = new Map();
|
|
64
|
+
let legacySteps = 0;
|
|
65
|
+
for await (const page of (0, pass_js_1.pages)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule_Execution), config.tenantId), config.batchSize)) {
|
|
66
|
+
for (const execution of page) {
|
|
67
|
+
const sourceId = execution.id;
|
|
68
|
+
if (!sourceId)
|
|
69
|
+
continue;
|
|
70
|
+
const label = `execution ${sourceId}`;
|
|
71
|
+
const rows = stepsByExecution.get(sourceId) ?? [];
|
|
72
|
+
const v1PlanId = plans.resolve(execution);
|
|
73
|
+
const fate = (0, schedule_js_1.classifyExecution)(execution, rows, !!v1PlanId);
|
|
74
|
+
if (fate.fate === "abandoned") {
|
|
75
|
+
abandoned.set(fate.reason, (abandoned.get(fate.reason) ?? 0) + 1);
|
|
76
|
+
report.warn(entry, `${label} not migrated: abandoned run — ${fate.reason}`);
|
|
77
|
+
entry.skipped++;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
// ── where it belongs: a plan, or a machine ─────────────────────────
|
|
81
|
+
const v1Plan = v1PlanId ? plans.plan(v1PlanId) : undefined;
|
|
82
|
+
let placement;
|
|
83
|
+
if (v1PlanId) {
|
|
84
|
+
const planId = map.get(index_js_1.Maintenance_Schedule.className, v1PlanId);
|
|
85
|
+
if (!planId) {
|
|
86
|
+
report.error(entry, `${label} belongs to plan ${v1PlanId}, which has no migrated ` +
|
|
87
|
+
`counterpart — run pass 14 first`);
|
|
88
|
+
entry.skipped++;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!(0, pass_js_1.refId)(execution.get("schedule")))
|
|
92
|
+
viaTemplate += 1;
|
|
93
|
+
placement = {
|
|
94
|
+
field: "schedule",
|
|
95
|
+
pointer: (0, ptr_js_1.ptr)(index_js_1.Service_Schedule.className, planId),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const v1SourceId = (0, pass_js_1.refId)(execution.get("source"));
|
|
100
|
+
const equipmentId = v1SourceId
|
|
101
|
+
? map.get(index_js_1.Source.className, v1SourceId)
|
|
102
|
+
: undefined;
|
|
103
|
+
if (!equipmentId) {
|
|
104
|
+
// v2 refuses an execution about nothing: without a plan it needs
|
|
105
|
+
// the machine, or no view can place it.
|
|
106
|
+
report.error(entry, `${label} has no plan and ` +
|
|
107
|
+
(v1SourceId
|
|
108
|
+
? `its source ${v1SourceId} has no Equipment (run pass 03 first)`
|
|
109
|
+
: `no source`) +
|
|
110
|
+
` — v2 needs one of the two, skipped`);
|
|
111
|
+
entry.skipped++;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
direct += 1;
|
|
115
|
+
placement = {
|
|
116
|
+
field: "equipment",
|
|
117
|
+
pointer: (0, ptr_js_1.ptr)(index_js_1.Service_Equipment.className, equipmentId),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const tenantId = (0, pass_js_1.refId)(execution.get("tenant")) ??
|
|
121
|
+
(0, pass_js_1.refId)(v1Plan?.get("tenant")) ??
|
|
122
|
+
(0, pass_js_1.refId)(rows[0]?.get("tenant"));
|
|
123
|
+
if (!tenantId) {
|
|
124
|
+
report.error(entry, `${label} has no tenant; Schedule_Execution.tenant is required — skipped`);
|
|
125
|
+
entry.skipped++;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (rows.length === 0 &&
|
|
129
|
+
Array.isArray(execution.get("steps"))) {
|
|
130
|
+
// 2024-10-30 … 2024-11-20 kept steps inline on the execution.
|
|
131
|
+
legacySteps += 1;
|
|
132
|
+
report.warn(entry, `${label} carries its steps inline (late-2024 shape) — migrated ` +
|
|
133
|
+
`without step results`);
|
|
134
|
+
}
|
|
135
|
+
const existingId = map.get(index_js_1.Maintenance_Schedule_Execution.className, sourceId);
|
|
136
|
+
const target = existingId
|
|
137
|
+
? new index_js_1.Service_Schedule_Execution({ objectId: existingId })
|
|
138
|
+
: new index_js_1.Service_Schedule_Execution();
|
|
139
|
+
// ── steps and results ──────────────────────────────────────────────
|
|
140
|
+
const ids = (0, schedule_js_1.executionStepIds)(rows, v1PlanId);
|
|
141
|
+
const steps = [];
|
|
142
|
+
const results = [];
|
|
143
|
+
for (const row of rows) {
|
|
144
|
+
const stepId = row.id ? ids.get(row.id) : undefined;
|
|
145
|
+
if (!stepId)
|
|
146
|
+
continue;
|
|
147
|
+
steps.push((0, schedule_js_1.toV2Step)(row, stepId, steps.length, !!v1PlanId));
|
|
148
|
+
const done = row.get("done") === true;
|
|
149
|
+
results.push({
|
|
150
|
+
stepId,
|
|
151
|
+
done,
|
|
152
|
+
...(fate.fate === "completed" && !done ? { skipped: true } : {}),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
const { entries, unresolved } = (0, material_js_1.toMaterial)(execution.get("material"), map);
|
|
156
|
+
if (entries.length) {
|
|
157
|
+
withMaterial += 1;
|
|
158
|
+
const stepId = (0, schedule_js_1.materialStepId)(sourceId);
|
|
159
|
+
steps.push({
|
|
160
|
+
id: stepId,
|
|
161
|
+
order: steps.length,
|
|
162
|
+
title: MATERIAL_STEP_TITLE,
|
|
163
|
+
required: false,
|
|
164
|
+
});
|
|
165
|
+
results.push({ stepId, done: true, material: entries });
|
|
166
|
+
}
|
|
167
|
+
if (unresolved.length) {
|
|
168
|
+
report.warn(entry, `${label} material references item(s) ${unresolved.join(", ")} with ` +
|
|
169
|
+
`no migrated Article — kept as free-text line(s)`);
|
|
170
|
+
}
|
|
171
|
+
// ── the record ─────────────────────────────────────────────────────
|
|
172
|
+
const userId = (0, pass_js_1.refId)(execution.get("user"));
|
|
173
|
+
target.set(placement.field, placement.pointer);
|
|
174
|
+
const title = String(execution.get("title") ?? "").trim() ||
|
|
175
|
+
(v1PlanId ? "" : DIRECT_TITLE);
|
|
176
|
+
if (title)
|
|
177
|
+
target.set("title", title);
|
|
178
|
+
if (execution.get("description")) {
|
|
179
|
+
target.set("description", execution.get("description"));
|
|
180
|
+
}
|
|
181
|
+
target.set("tenant", (0, ptr_js_1.tenantPtr)(tenantId));
|
|
182
|
+
target.set("steps", steps);
|
|
183
|
+
target.set("stepResults", results);
|
|
184
|
+
if (userId)
|
|
185
|
+
target.set("user", (0, ptr_js_1.userPtr)(userId));
|
|
186
|
+
if (fate.fate === "completed") {
|
|
187
|
+
completed += 1;
|
|
188
|
+
target.set("completedAt", fate.completedAt);
|
|
189
|
+
if (userId)
|
|
190
|
+
target.set("performedBy", (0, ptr_js_1.userPtr)(userId));
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
open += 1;
|
|
194
|
+
}
|
|
195
|
+
if (!existingId) {
|
|
196
|
+
// What the execution hook's `defaultAclHandler` grants: the whole
|
|
197
|
+
// tenant reads a protocol, its recorder writes it.
|
|
198
|
+
target.setACL((0, acl_js_1.migrationAcl)({ tenantId, userId }));
|
|
199
|
+
}
|
|
200
|
+
if (config.dryRun) {
|
|
201
|
+
existingId ? entry.updated++ : entry.created++;
|
|
202
|
+
if (!existingId) {
|
|
203
|
+
await map.record(index_js_1.Maintenance_Schedule_Execution.className, sourceId, index_js_1.Service_Schedule_Execution.className, map_js_1.MigrationMap.dryId(sourceId));
|
|
204
|
+
}
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
const newId = await (0, acl_js_1.saveMigrated)(config, target, {
|
|
209
|
+
className: index_js_1.Service_Schedule_Execution.className,
|
|
210
|
+
isNew: !existingId,
|
|
211
|
+
createdAt: execution.createdAt,
|
|
212
|
+
updatedAt: execution.updatedAt,
|
|
213
|
+
});
|
|
214
|
+
if (existingId) {
|
|
215
|
+
entry.updated++;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
entry.created++;
|
|
219
|
+
await map.record(index_js_1.Maintenance_Schedule_Execution.className, sourceId, index_js_1.Service_Schedule_Execution.className, newId);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
report.error(entry, `${label} failed: ${error.message}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
report.info(entry, `${completed} protocol(s), ${open} open run(s), of them ${direct} direct ` +
|
|
228
|
+
`maintenance(s) without a plan`);
|
|
229
|
+
for (const [reason, count] of abandoned) {
|
|
230
|
+
report.info(entry, `${count} abandoned run(s) not migrated — ${reason}`);
|
|
231
|
+
}
|
|
232
|
+
if (viaTemplate > 0) {
|
|
233
|
+
report.info(entry, `${viaTemplate} pre-2025-08 execution(s) had no plan pointer — placed on ` +
|
|
234
|
+
`the plan with their template and source, as v1 does at every boot`);
|
|
235
|
+
}
|
|
236
|
+
if (withMaterial > 0) {
|
|
237
|
+
report.info(entry, `${withMaterial} execution(s) with material — carried on a final ` +
|
|
238
|
+
`"${MATERIAL_STEP_TITLE}" step`);
|
|
239
|
+
}
|
|
240
|
+
if (legacySteps > 0) {
|
|
241
|
+
report.info(entry, `${legacySteps} execution(s) in the late-2024 shape`);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Pass } from "../lib/pass.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pass 16 — step capture fields → `OD3_Meta_Config`, captured values →
|
|
4
|
+
* `OD3_Meta_Entry`.
|
|
5
|
+
*
|
|
6
|
+
* v2 keys both by step id: the config under `stepMetaContext(stepId)`, one
|
|
7
|
+
* entry per execution under the same context with `entryClassName` =
|
|
8
|
+
* `OD3_Service_Schedule_Execution`. v1 went through three shapes, and all of
|
|
9
|
+
* them end up there:
|
|
10
|
+
*
|
|
11
|
+
* | v1 era | fields (config) | values |
|
|
12
|
+
* | ------------------- | ----------------------------------- | --------------------------------- |
|
|
13
|
+
* | A (… 2025-08) | static admin values — pass 13/14 put them into the step description | none captured |
|
|
14
|
+
* | B (2025-08 … 02-26) | `Schedule_Step.fields` configs | `Execution_Step.meta` `[{…, value}]` |
|
|
15
|
+
* | C (2026-02 …) | `Meta_Config` `["schedule","step","meta",id]` | `Meta_Entry` on the execution step |
|
|
16
|
+
*
|
|
17
|
+
* Plus v1's step comment, see {@link COMMENT_FIELD}.
|
|
18
|
+
*
|
|
19
|
+
* The step ids come from `lib/schedule.ts` — the same functions passes 13–15
|
|
20
|
+
* used, which is what makes an entry written here land on the step the
|
|
21
|
+
* protocol shows.
|
|
22
|
+
*/
|
|
23
|
+
export declare const pass16: Pass;
|