@openinc/parse-server-opendash 4.7.0 → 4.8.1
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_Execution.js +10 -4
- package/dist/hooks/Service_Schedule_Template.js +5 -0
- 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/schedule.d.ts +306 -0
- package/dist/scripts/migration/lib/schedule.js +613 -0
- package/dist/scripts/migration/passes/03-equipment.js +11 -4
- 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 +294 -11
- package/dist/scripts/seed-v1-testdata.d.ts +2 -0
- package/dist/scripts/seed-v1-testdata.js +392 -6
- 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,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;
|
|
@@ -0,0 +1,308 @@
|
|
|
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.pass16 = 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 pass_js_1 = require("../lib/pass.js");
|
|
11
|
+
const ptr_js_1 = require("../lib/ptr.js");
|
|
12
|
+
const schedule_js_1 = require("../lib/schedule.js");
|
|
13
|
+
const _07_meta_configs_js_1 = require("./07-meta-configs.js");
|
|
14
|
+
/**
|
|
15
|
+
* The field v1's per-step comment lands in.
|
|
16
|
+
*
|
|
17
|
+
* v1 had a comment box on every execution step; v2 has none. A comment is
|
|
18
|
+
* part of what a technician recorded, so it becomes a captured value like any
|
|
19
|
+
* other — and a capture field on the plan step it belongs to, so the protocol
|
|
20
|
+
* renders it without a config-drift warning and the next run can fill it in.
|
|
21
|
+
* The name is deliberately unlike anything a customer would define.
|
|
22
|
+
*/
|
|
23
|
+
const COMMENT_FIELD = {
|
|
24
|
+
name: "legacyComment",
|
|
25
|
+
label: "Kommentar",
|
|
26
|
+
type: "string",
|
|
27
|
+
multiline: true,
|
|
28
|
+
};
|
|
29
|
+
/** Fields by name, first definition wins. */
|
|
30
|
+
function unionFields(...lists) {
|
|
31
|
+
const byName = new Map();
|
|
32
|
+
for (const list of lists) {
|
|
33
|
+
for (const field of list) {
|
|
34
|
+
if (field?.name && !byName.has(field.name))
|
|
35
|
+
byName.set(field.name, field);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return [...byName.values()];
|
|
39
|
+
}
|
|
40
|
+
/** Era-B field configs (`{ name, type, … }`) in a v1 `fields` / `meta` array. */
|
|
41
|
+
function typedFields(raw) {
|
|
42
|
+
if (!Array.isArray(raw))
|
|
43
|
+
return [];
|
|
44
|
+
return raw
|
|
45
|
+
.filter((field) => field && !(0, schedule_js_1.isStaticField)(field) && field.type)
|
|
46
|
+
.map((field) => (0, _07_meta_configs_js_1.toMetaFieldConfig)(field))
|
|
47
|
+
.filter((field) => !!field);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Pass 16 — step capture fields → `OD3_Meta_Config`, captured values →
|
|
51
|
+
* `OD3_Meta_Entry`.
|
|
52
|
+
*
|
|
53
|
+
* v2 keys both by step id: the config under `stepMetaContext(stepId)`, one
|
|
54
|
+
* entry per execution under the same context with `entryClassName` =
|
|
55
|
+
* `OD3_Service_Schedule_Execution`. v1 went through three shapes, and all of
|
|
56
|
+
* them end up there:
|
|
57
|
+
*
|
|
58
|
+
* | v1 era | fields (config) | values |
|
|
59
|
+
* | ------------------- | ----------------------------------- | --------------------------------- |
|
|
60
|
+
* | A (… 2025-08) | static admin values — pass 13/14 put them into the step description | none captured |
|
|
61
|
+
* | B (2025-08 … 02-26) | `Schedule_Step.fields` configs | `Execution_Step.meta` `[{…, value}]` |
|
|
62
|
+
* | C (2026-02 …) | `Meta_Config` `["schedule","step","meta",id]` | `Meta_Entry` on the execution step |
|
|
63
|
+
*
|
|
64
|
+
* Plus v1's step comment, see {@link COMMENT_FIELD}.
|
|
65
|
+
*
|
|
66
|
+
* The step ids come from `lib/schedule.ts` — the same functions passes 13–15
|
|
67
|
+
* used, which is what makes an entry written here land on the step the
|
|
68
|
+
* protocol shows.
|
|
69
|
+
*/
|
|
70
|
+
exports.pass16 = {
|
|
71
|
+
id: "16",
|
|
72
|
+
title: "schedule-meta",
|
|
73
|
+
needs: ["13", "14", "15"],
|
|
74
|
+
async run({ config, map, report, entry }) {
|
|
75
|
+
const { batchSize } = config;
|
|
76
|
+
// ── v1 era C: configs and entries, keyed by v1 ids ────────────────────
|
|
77
|
+
const legacyConfigs = new Map();
|
|
78
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Meta_Config).startsWith("context", schedule_js_1.LEGACY_STEP_META_PREFIX), batchSize)) {
|
|
79
|
+
for (const row of page) {
|
|
80
|
+
const stepId = (0, schedule_js_1.stepIdOfContext)(row.get("context") ?? "");
|
|
81
|
+
const fields = row.get("config")?.fields;
|
|
82
|
+
if (stepId && fields?.length)
|
|
83
|
+
legacyConfigs.set(stepId, fields);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const legacyEntries = new Map();
|
|
87
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Meta_Entry)
|
|
88
|
+
.startsWith("context", schedule_js_1.LEGACY_STEP_META_PREFIX)
|
|
89
|
+
.equalTo("entryClassName", index_js_1.Maintenance_Schedule_Execution_Step.className), batchSize)) {
|
|
90
|
+
for (const row of page) {
|
|
91
|
+
const objectId = row.get("entryObjectId");
|
|
92
|
+
if (objectId)
|
|
93
|
+
legacyEntries.set(objectId, row);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// ── what already exists in v2, so a re-run updates ────────────────────
|
|
97
|
+
const existingConfigs = new Map();
|
|
98
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Meta_Config).startsWith("context", schedule_js_1.STEP_META_PREFIX), batchSize)) {
|
|
99
|
+
for (const row of page) {
|
|
100
|
+
const context = row.get("context");
|
|
101
|
+
if (context)
|
|
102
|
+
existingConfigs.set(context, row);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const existingEntries = new Map();
|
|
106
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Meta_Entry)
|
|
107
|
+
.startsWith("context", schedule_js_1.STEP_META_PREFIX)
|
|
108
|
+
.equalTo("entryClassName", index_js_1.Service_Schedule_Execution.className), batchSize)) {
|
|
109
|
+
for (const row of page) {
|
|
110
|
+
existingEntries.set(`${row.get("context")}|${row.get("entryObjectId")}`, row);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// ── 1. captured values, collected first ───────────────────────────────
|
|
114
|
+
// Before the configs, because a plan step needs the comment field exactly
|
|
115
|
+
// when one of its executions left a comment.
|
|
116
|
+
const plans = await schedule_js_1.PlanIndex.load(config);
|
|
117
|
+
const stepsByExecution = await (0, schedule_js_1.executionStepsByExecution)(config);
|
|
118
|
+
const pending = [];
|
|
119
|
+
const commentedSteps = new Set();
|
|
120
|
+
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), batchSize)) {
|
|
121
|
+
for (const execution of page) {
|
|
122
|
+
if (!execution.id)
|
|
123
|
+
continue;
|
|
124
|
+
// Not migrated (abandoned, or failed in pass 15) — nothing to attach to.
|
|
125
|
+
const executionId = map.get(index_js_1.Maintenance_Schedule_Execution.className, execution.id);
|
|
126
|
+
if (!executionId)
|
|
127
|
+
continue;
|
|
128
|
+
const rows = stepsByExecution.get(execution.id) ?? [];
|
|
129
|
+
const ids = (0, schedule_js_1.executionStepIds)(rows, plans.resolve(execution));
|
|
130
|
+
for (const row of rows) {
|
|
131
|
+
const stepId = row.id ? ids.get(row.id) : undefined;
|
|
132
|
+
if (!stepId)
|
|
133
|
+
continue;
|
|
134
|
+
const legacy = legacyEntries.get(row.id);
|
|
135
|
+
const legacyValues = legacy?.get("values") ??
|
|
136
|
+
{};
|
|
137
|
+
// The entry's own snapshot, else the step's config it was captured
|
|
138
|
+
// against — without either the values would have no labels.
|
|
139
|
+
const snapshot = legacy?.get("config")?.fields;
|
|
140
|
+
const v1StepId = (0, pass_js_1.refId)(row.get("step"));
|
|
141
|
+
const legacyFields = snapshot?.length
|
|
142
|
+
? snapshot
|
|
143
|
+
: legacy && v1StepId
|
|
144
|
+
? (legacyConfigs.get(v1StepId) ?? [])
|
|
145
|
+
: [];
|
|
146
|
+
// Era B: the config entries with their value next to them. `meta`
|
|
147
|
+
// can hold `undefined` holes — v1's direct maintenance pushed
|
|
148
|
+
// unfiltered.
|
|
149
|
+
const eraB = row.get("meta") ?? [];
|
|
150
|
+
const eraBValues = {};
|
|
151
|
+
for (const field of eraB) {
|
|
152
|
+
const name = field?.name?.trim();
|
|
153
|
+
if (name && field.value !== undefined && field.value !== null) {
|
|
154
|
+
eraBValues[name] = field.value;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const comment = String(row.get("comment") ?? "").trim();
|
|
158
|
+
const values = {
|
|
159
|
+
...eraBValues,
|
|
160
|
+
...legacyValues,
|
|
161
|
+
...(comment ? { [COMMENT_FIELD.name]: comment } : {}),
|
|
162
|
+
};
|
|
163
|
+
if (Object.keys(values).length === 0)
|
|
164
|
+
continue;
|
|
165
|
+
if (comment)
|
|
166
|
+
commentedSteps.add(stepId);
|
|
167
|
+
pending.push({
|
|
168
|
+
context: (0, ptr_js_1.contextToString)((0, schedule_js_1.stepMetaContext)(stepId)),
|
|
169
|
+
executionId,
|
|
170
|
+
tenantId: (0, pass_js_1.refId)(row.get("tenant")) ?? (0, pass_js_1.refId)(execution.get("tenant")),
|
|
171
|
+
values,
|
|
172
|
+
fields: unionFields(legacyFields, typedFields(eraB), comment ? [COMMENT_FIELD] : []),
|
|
173
|
+
createdAt: row.createdAt,
|
|
174
|
+
updatedAt: row.updatedAt,
|
|
175
|
+
label: `execution step ${row.id}`,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// ── 2. capture fields per plan / template step ────────────────────────
|
|
181
|
+
const steps = new schedule_js_1.StepSource(batchSize);
|
|
182
|
+
const configIds = new Map();
|
|
183
|
+
let configsWritten = 0;
|
|
184
|
+
let commentFields = 0;
|
|
185
|
+
// The v2 owner's tenant, as pass 13/14 resolved it — a v1 plan may have
|
|
186
|
+
// none of its own.
|
|
187
|
+
const tenantOfOwner = new Map();
|
|
188
|
+
await tenantsOf(index_js_1.Service_Schedule, batchSize, tenantOfOwner);
|
|
189
|
+
await tenantsOf(index_js_1.Service_Schedule_Template, batchSize, tenantOfOwner);
|
|
190
|
+
const writeConfig = async (row, stepId, ownerId, label) => {
|
|
191
|
+
const fields = unionFields(legacyConfigs.get(row.id) ?? typedFields(row.get("fields")), commentedSteps.has(stepId) ? [COMMENT_FIELD] : []);
|
|
192
|
+
if (fields.length === 0)
|
|
193
|
+
return;
|
|
194
|
+
if (commentedSteps.has(stepId))
|
|
195
|
+
commentFields += 1;
|
|
196
|
+
const context = (0, ptr_js_1.contextToString)((0, schedule_js_1.stepMetaContext)(stepId));
|
|
197
|
+
const existing = existingConfigs.get(context);
|
|
198
|
+
const tenantId = tenantOfOwner.get(ownerId);
|
|
199
|
+
const target = existing ?? new index_js_1.Meta_Config();
|
|
200
|
+
target.set("context", context);
|
|
201
|
+
target.set("config", { fields });
|
|
202
|
+
if (tenantId)
|
|
203
|
+
target.set("tenant", (0, ptr_js_1.tenantPtr)(tenantId));
|
|
204
|
+
// What `defaultAclHandler` gives a Meta_Config: the tenant reads it,
|
|
205
|
+
// its admins edit it.
|
|
206
|
+
if (!existing)
|
|
207
|
+
target.setACL((0, acl_js_1.migrationAcl)({ tenantId }));
|
|
208
|
+
if (config.dryRun) {
|
|
209
|
+
existing ? entry.updated++ : entry.created++;
|
|
210
|
+
configsWritten += 1;
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const id = await (0, acl_js_1.saveMigrated)(config, target, {
|
|
215
|
+
className: index_js_1.Meta_Config.className,
|
|
216
|
+
isNew: !existing,
|
|
217
|
+
createdAt: row.createdAt,
|
|
218
|
+
updatedAt: row.updatedAt,
|
|
219
|
+
});
|
|
220
|
+
configIds.set(context, id);
|
|
221
|
+
existing ? entry.updated++ : entry.created++;
|
|
222
|
+
configsWritten += 1;
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
report.error(entry, `${label} config failed: ${error.message}`);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
for (const template of await (0, pass_js_1.all)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule_Template), config.tenantId), batchSize)) {
|
|
229
|
+
const ownerId = template.id
|
|
230
|
+
? map.get(index_js_1.Maintenance_Schedule_Template.className, template.id)
|
|
231
|
+
: undefined;
|
|
232
|
+
if (!ownerId)
|
|
233
|
+
continue;
|
|
234
|
+
for (const row of await steps.of(template)) {
|
|
235
|
+
await writeConfig(row, (0, schedule_js_1.templateStepId)(template.id, row.id), ownerId, `template ${template.id} step ${row.id}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
for (const plan of await (0, pass_js_1.all)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule), config.tenantId), batchSize)) {
|
|
239
|
+
const ownerId = plan.id
|
|
240
|
+
? map.get(index_js_1.Maintenance_Schedule.className, plan.id)
|
|
241
|
+
: undefined;
|
|
242
|
+
if (!ownerId)
|
|
243
|
+
continue;
|
|
244
|
+
const { rows } = await steps.ofPlan(plan);
|
|
245
|
+
for (const row of rows) {
|
|
246
|
+
await writeConfig(row, (0, schedule_js_1.planStepId)(plan.id, row.id), ownerId, `plan ${plan.id} step ${row.id}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// ── 3. the entries ────────────────────────────────────────────────────
|
|
250
|
+
let entriesWritten = 0;
|
|
251
|
+
for (const item of pending) {
|
|
252
|
+
const key = `${item.context}|${item.executionId}`;
|
|
253
|
+
const existing = existingEntries.get(key);
|
|
254
|
+
const target = existing ?? new index_js_1.Meta_Entry();
|
|
255
|
+
target.set("context", item.context);
|
|
256
|
+
target.set("entryClassName", index_js_1.Service_Schedule_Execution.className);
|
|
257
|
+
target.set("entryObjectId", item.executionId);
|
|
258
|
+
target.set("values", item.values);
|
|
259
|
+
// An entry carries a snapshot of the fields it was captured against,
|
|
260
|
+
// so it still renders after the plan's fields change.
|
|
261
|
+
target.set("config", { fields: item.fields });
|
|
262
|
+
const originId = configIds.get(item.context) ?? existingConfigs.get(item.context)?.id;
|
|
263
|
+
const origin = (0, ptr_js_1.maybePtr)(index_js_1.Meta_Config.className, originId);
|
|
264
|
+
if (origin)
|
|
265
|
+
target.set("origin", origin);
|
|
266
|
+
if (item.tenantId)
|
|
267
|
+
target.set("tenant", (0, ptr_js_1.tenantPtr)(item.tenantId));
|
|
268
|
+
if (!existing) {
|
|
269
|
+
target.setACL((0, acl_js_1.migrationAcl)({ tenantId: item.tenantId, allowTenantUserWrite: true }));
|
|
270
|
+
}
|
|
271
|
+
if (config.dryRun) {
|
|
272
|
+
existing ? entry.updated++ : entry.created++;
|
|
273
|
+
entriesWritten += 1;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
await (0, acl_js_1.saveMigrated)(config, target, {
|
|
278
|
+
className: index_js_1.Meta_Entry.className,
|
|
279
|
+
isNew: !existing,
|
|
280
|
+
createdAt: item.createdAt,
|
|
281
|
+
updatedAt: item.updatedAt,
|
|
282
|
+
});
|
|
283
|
+
existing ? entry.updated++ : entry.created++;
|
|
284
|
+
entriesWritten += 1;
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
report.error(entry, `${item.label} values failed: ${error.message}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
report.info(entry, `${configsWritten} step field config(s), ${entriesWritten} captured ` +
|
|
291
|
+
`value set(s); ${commentedSteps.size} step(s) carry v1 comments ` +
|
|
292
|
+
`(${commentFields} plan step(s) gained a "${COMMENT_FIELD.label}" field)`);
|
|
293
|
+
if (legacyEntries.size > 0 || legacyConfigs.size > 0) {
|
|
294
|
+
report.info(entry, `read ${legacyConfigs.size} v1 step config(s) and ${legacyEntries.size} ` +
|
|
295
|
+
`v1 value set(s) from the 2026 meta store`);
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
/** objectId → tenant id of every row of a v2 class. */
|
|
300
|
+
async function tenantsOf(cls, batchSize, into) {
|
|
301
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(cls), batchSize)) {
|
|
302
|
+
for (const row of page) {
|
|
303
|
+
const tenantId = (0, pass_js_1.refId)(row.get("tenant"));
|
|
304
|
+
if (row.id && tenantId)
|
|
305
|
+
into.set(row.id, tenantId);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Pass } from "../lib/pass.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pass 17 — files of plans, steps and executions → the v2 asset contexts.
|
|
4
|
+
*
|
|
5
|
+
* v2 keeps two kinds of file for maintenance, both in `OD3_Assets`:
|
|
6
|
+
*
|
|
7
|
+
* - **machine documents** — manuals, instructions — under the *machine*
|
|
8
|
+
* (`od3-service-equipment-<id>`, per plan when it has no machine). v1's plan
|
|
9
|
+
* documents (`schedule-media-<plan>`) and step attachments
|
|
10
|
+
* (`schedule-step-media-<step>`, and the older `Schedule_Step.media`
|
|
11
|
+
* relation) are instructions, so they go there. v2 has no per-step files.
|
|
12
|
+
* - **execution media** — photos of the work — under the execution
|
|
13
|
+
* (`od3-service-execution-<id>`). v1's `schedule-execution-<id>` and the
|
|
14
|
+
* older `Execution.media` relation.
|
|
15
|
+
*
|
|
16
|
+
* Existing asset rows are re-addressed in place, like pass 11 does for
|
|
17
|
+
* tickets: the file stays where it is, only `context` changes. A
|
|
18
|
+
* `Maintenance_Media` file has no asset row yet and gets one.
|
|
19
|
+
*
|
|
20
|
+
* Not read: `Execution_Step.media`. v1 filled it only by copying the step's
|
|
21
|
+
* own media when a run started (`hooks/Maintenance_Schedule_Execution.ts`),
|
|
22
|
+
* so it holds the step's instructions a second time, not photos.
|
|
23
|
+
*
|
|
24
|
+
* A v1 step can belong to several plans on different machines, but an asset
|
|
25
|
+
* row has one context. It goes to the first plan's machine; the others are
|
|
26
|
+
* named in a warning. Copying the row would not help: deleting an asset
|
|
27
|
+
* destroys its file (`hooks/Assets.ts`), so two rows on one file means one
|
|
28
|
+
* deletion breaks the other.
|
|
29
|
+
*/
|
|
30
|
+
export declare const pass17: Pass;
|