@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.
Files changed (39) hide show
  1. package/dist/features/schema/helper/migrationMode.js +2 -0
  2. package/dist/hooks/Service_Schedule.js +7 -0
  3. package/dist/hooks/Service_Schedule_Template.js +5 -0
  4. package/dist/scripts/migration/lib/articleMeta.d.ts +34 -10
  5. package/dist/scripts/migration/lib/articleMeta.js +58 -11
  6. package/dist/scripts/migration/lib/cadence.d.ts +75 -0
  7. package/dist/scripts/migration/lib/cadence.js +246 -0
  8. package/dist/scripts/migration/lib/env.d.ts +5 -0
  9. package/dist/scripts/migration/lib/env.js +23 -0
  10. package/dist/scripts/migration/lib/equipmentMeta.d.ts +65 -0
  11. package/dist/scripts/migration/lib/equipmentMeta.js +155 -0
  12. package/dist/scripts/migration/lib/schedule.d.ts +306 -0
  13. package/dist/scripts/migration/lib/schedule.js +613 -0
  14. package/dist/scripts/migration/passes/03-equipment.js +181 -4
  15. package/dist/scripts/migration/passes/05-articles.d.ts +12 -15
  16. package/dist/scripts/migration/passes/05-articles.js +83 -33
  17. package/dist/scripts/migration/passes/13-schedule-templates.d.ts +15 -0
  18. package/dist/scripts/migration/passes/13-schedule-templates.js +163 -0
  19. package/dist/scripts/migration/passes/14-schedules.d.ts +30 -0
  20. package/dist/scripts/migration/passes/14-schedules.js +239 -0
  21. package/dist/scripts/migration/passes/15-executions.d.ts +34 -0
  22. package/dist/scripts/migration/passes/15-executions.js +244 -0
  23. package/dist/scripts/migration/passes/16-schedule-meta.d.ts +23 -0
  24. package/dist/scripts/migration/passes/16-schedule-meta.js +308 -0
  25. package/dist/scripts/migration/passes/17-schedule-assets.d.ts +30 -0
  26. package/dist/scripts/migration/passes/17-schedule-assets.js +240 -0
  27. package/dist/scripts/migration/passes/18-calendar-links.d.ts +25 -0
  28. package/dist/scripts/migration/passes/18-calendar-links.js +132 -0
  29. package/dist/scripts/migration/passes/19-schedule-history.d.ts +18 -0
  30. package/dist/scripts/migration/passes/19-schedule-history.js +186 -0
  31. package/dist/scripts/migration/run.js +20 -9
  32. package/dist/scripts/migration/verify.js +450 -12
  33. package/dist/scripts/seed-v1-testdata.d.ts +2 -0
  34. package/dist/scripts/seed-v1-testdata.js +449 -10
  35. package/dist/types/Service_Schedule.d.ts +3 -0
  36. package/dist/types/Service_Schedule.js +6 -0
  37. package/dist/types/Service_Schedule_Execution.d.ts +1 -1
  38. package/package.json +1 -1
  39. package/schema/Service_Schedule.json +4 -0
@@ -7,6 +7,7 @@ exports.pass03 = void 0;
7
7
  const node_1 = __importDefault(require("parse/node"));
8
8
  const index_js_1 = require("../../../types/index.js");
9
9
  const acl_js_1 = require("../lib/acl.js");
10
+ const equipmentMeta_js_1 = require("../lib/equipmentMeta.js");
10
11
  const map_js_1 = require("../lib/map.js");
11
12
  const latest_js_1 = require("../lib/latest.js");
12
13
  const ptr_js_1 = require("../lib/ptr.js");
@@ -35,16 +36,186 @@ async function referencedSourceIds(ctx) {
35
36
  ids.add(src.id);
36
37
  }
37
38
  }
38
- // Schedules are deferred (MIGRATION_PLAN §4.5) but their sources are included
39
- // anyway: the equipment they will need should exist before that work starts, and
40
- // a schedule's source is by definition real equipment.
39
+ // A schedule's source is by definition real equipment — pass 14 puts the plan
40
+ // on it.
41
41
  for (const schedule of await (0, pass_js_1.all)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule), config.tenantId), config.batchSize)) {
42
42
  const id = (0, pass_js_1.refId)(schedule.get("source"));
43
43
  if (id)
44
44
  ids.add(id);
45
45
  }
46
+ // So is the source of an execution: v1's direct maintenance names only its
47
+ // source, and pass 15 has nowhere else to put it — v2 refuses an execution
48
+ // with neither a plan nor a machine.
49
+ for (const execution of await (0, pass_js_1.all)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule_Execution), config.tenantId), config.batchSize)) {
50
+ const id = (0, pass_js_1.refId)(execution.get("source"));
51
+ if (id)
52
+ ids.add(id);
53
+ }
46
54
  return ids;
47
55
  }
56
+ /** `SourceMeta` columns that are not `data` and have no Equipment column either. */
57
+ const RESERVED_COLUMNS = ["name", "description", "location", "file"];
58
+ /**
59
+ * `OD3_SourceMeta` → equipment header data under
60
+ * `["service","equipment","meta"]`.
61
+ *
62
+ * Runs inside pass 03 for the same reason pass 05 writes article meta: the
63
+ * equipment ids are already in hand here, and a separate pass would only have to
64
+ * re-derive them.
65
+ *
66
+ * Only sources that actually became Equipment are covered — meta on a source D3
67
+ * left behind has nothing to hang off, and is counted rather than dropped
68
+ * silently.
69
+ */
70
+ async function migrateSourceMeta(ctx, allSources, equipmentBySource) {
71
+ const { config, report, entry } = ctx;
72
+ const metaIdBySource = new Map();
73
+ let orphaned = 0;
74
+ for (const source of allSources) {
75
+ const metaId = (0, pass_js_1.refId)(source.get("meta"));
76
+ if (!source.id || !metaId)
77
+ continue;
78
+ if (equipmentBySource.has(source.id))
79
+ metaIdBySource.set(source.id, metaId);
80
+ else
81
+ orphaned += 1;
82
+ }
83
+ if (orphaned > 0) {
84
+ report.info(entry, `${orphaned} source meta record(s) belong to sources that did not become ` +
85
+ `Equipment (D3: referenced sources only) — left on the Source`);
86
+ }
87
+ if (metaIdBySource.size === 0)
88
+ return;
89
+ // Load the SourceMeta rows in id batches; Parse caps containedIn well above
90
+ // this, but the sources on one instance are few enough that 100 is plenty.
91
+ const metaById = new Map();
92
+ const metaIds = [...new Set(metaIdBySource.values())];
93
+ for (let i = 0; i < metaIds.length; i += 100) {
94
+ const slice = metaIds.slice(i, i + 100);
95
+ const rows = await (0, pass_js_1.all)(() => new node_1.default.Query(index_js_1.SourceMeta).containedIn("objectId", slice), config.batchSize);
96
+ for (const row of rows)
97
+ if (row.id)
98
+ metaById.set(row.id, row);
99
+ }
100
+ const contextString = (0, ptr_js_1.contextToString)(equipmentMeta_js_1.EQUIPMENT_META_CONTEXT);
101
+ const existingEntries = config.dryRun
102
+ ? new Map()
103
+ : await (0, equipmentMeta_js_1.loadEquipmentMetaEntries)(config);
104
+ const fieldsByTenant = new Map();
105
+ const valuesByEquipment = new Map();
106
+ const conflicts = [];
107
+ let converted = 0;
108
+ for (const source of allSources) {
109
+ const sourceId = source.id;
110
+ if (!sourceId)
111
+ continue;
112
+ const metaId = metaIdBySource.get(sourceId);
113
+ const equipmentId = equipmentBySource.get(sourceId);
114
+ if (!metaId || !equipmentId)
115
+ continue;
116
+ const meta = metaById.get(metaId);
117
+ if (!meta)
118
+ continue;
119
+ const tenantId = (0, pass_js_1.refId)(source.get("tenant")) ?? "";
120
+ const fields = fieldsByTenant.get(tenantId) ?? new Map();
121
+ fieldsByTenant.set(tenantId, fields);
122
+ const values = {};
123
+ const remember = (name, raw) => {
124
+ const inferred = (0, equipmentMeta_js_1.inferMetaField)(name, raw);
125
+ if (!inferred)
126
+ return;
127
+ const seen = fields.get(name);
128
+ if (!seen)
129
+ fields.set(name, inferred);
130
+ else if (seen.type !== inferred.type ||
131
+ Boolean(seen.multiple) !== Boolean(inferred.multiple)) {
132
+ conflicts.push(`"${name}" is ${seen.type}${seen.multiple ? "[]" : ""} on one source ` +
133
+ `and ${inferred.type}${inferred.multiple ? "[]" : ""} on ${sourceId}`);
134
+ }
135
+ };
136
+ // `data` is the client-authored map and wins on name collisions.
137
+ const data = (meta.get("data") ?? {});
138
+ for (const [key, raw] of Object.entries(data)) {
139
+ const name = key.trim();
140
+ if (!name)
141
+ continue;
142
+ const stored = (0, equipmentMeta_js_1.metaValue)(raw);
143
+ if (stored === undefined)
144
+ continue;
145
+ values[name] = stored;
146
+ remember(name, raw);
147
+ }
148
+ for (const column of RESERVED_COLUMNS) {
149
+ const raw = meta.get(column);
150
+ const stored = (0, equipmentMeta_js_1.metaValue)(raw);
151
+ if (stored === undefined)
152
+ continue;
153
+ const taken = Object.prototype.hasOwnProperty.call(values, column);
154
+ const name = taken ? (0, equipmentMeta_js_1.reservedFallback)(column) : column;
155
+ if (taken) {
156
+ report.warn(entry, `source ${sourceId}: meta data already defines "${column}", so the ` +
157
+ `SourceMeta column moved to "${name}" rather than overwriting it`);
158
+ }
159
+ if (column === "location" || column === "file")
160
+ converted += 1;
161
+ values[name] = stored;
162
+ remember(name, raw);
163
+ }
164
+ if (Object.keys(values).length === 0)
165
+ continue;
166
+ valuesByEquipment.set(equipmentId, { tenantId, values, source });
167
+ }
168
+ if (converted > 0) {
169
+ report.info(entry, `${converted} location/file value(s) stored as text — plugin-meta has no ` +
170
+ `geo or file field type, so a GeoPoint becomes "lat,lng" and a File its URL`);
171
+ }
172
+ for (const conflict of conflicts) {
173
+ report.warn(entry, `equipment meta field type conflict: ${conflict} — first wins`);
174
+ }
175
+ if (config.dryRun) {
176
+ report.info(entry, `${valuesByEquipment.size} equipment would carry header data from ` +
177
+ `OD3_SourceMeta under ["service","equipment","meta"]`);
178
+ return;
179
+ }
180
+ // Config before entries: an entry whose fields are undeclared renders blank.
181
+ const configByTenant = new Map();
182
+ for (const [tenantId, fields] of fieldsByTenant) {
183
+ configByTenant.set(tenantId, await (0, equipmentMeta_js_1.ensureEquipmentMetaConfig)(config, tenantId, [...fields.values()]));
184
+ }
185
+ let written = 0;
186
+ for (const [equipmentId, { tenantId, values, source }] of valuesByEquipment) {
187
+ try {
188
+ const existing = existingEntries.get(equipmentId);
189
+ const target = existing ?? new index_js_1.Meta_Entry();
190
+ target.set("context", contextString);
191
+ target.set("entryClassName", index_js_1.Service_Equipment.className);
192
+ target.set("entryObjectId", equipmentId);
193
+ target.set("values", values);
194
+ const originPtr = (0, ptr_js_1.maybePtr)("OD3_Meta_Config", configByTenant.get(tenantId));
195
+ if (originPtr)
196
+ target.set("origin", originPtr);
197
+ if (tenantId)
198
+ target.set("tenant", (0, ptr_js_1.tenantPtr)(tenantId));
199
+ if (!existing) {
200
+ target.setACL((0, acl_js_1.migrationAcl)({ tenantId, allowTenantUserWrite: true }));
201
+ }
202
+ await (0, acl_js_1.saveMigrated)(config, target, {
203
+ className: index_js_1.Meta_Entry.className,
204
+ isNew: !existing,
205
+ createdAt: source.createdAt,
206
+ updatedAt: source.updatedAt,
207
+ });
208
+ written += 1;
209
+ }
210
+ catch (error) {
211
+ report.error(entry, `equipment ${equipmentId} meta failed: ${error.message}`);
212
+ }
213
+ }
214
+ if (written > 0) {
215
+ report.info(entry, `${written} equipment carry header data from OD3_SourceMeta under ` +
216
+ `["service","equipment","meta"] — editable in the equipment admin view`);
217
+ }
218
+ }
48
219
  /**
49
220
  * Pass 03 — `OD3_Source` → `OD3_Service_Equipment`.
50
221
  *
@@ -65,7 +236,7 @@ exports.pass03 = {
65
236
  const { config, map, report, entry } = ctx;
66
237
  const referenced = await referencedSourceIds(ctx);
67
238
  if (referenced.size === 0) {
68
- report.warn(entry, "no source is referenced by any ticket, item or schedule");
239
+ report.warn(entry, "no source is referenced by any ticket, item, schedule or execution");
69
240
  return;
70
241
  }
71
242
  // Load every source once; the tree walk needs arbitrary parents anyway.
@@ -109,6 +280,8 @@ exports.pass03 = {
109
280
  const ordered = [...needed]
110
281
  .map((id) => byId.get(id))
111
282
  .sort((a, b) => depth(a.id) - depth(b.id));
283
+ // sourceId -> equipment id, for the SourceMeta step below.
284
+ const equipmentBySource = new Map();
112
285
  for (const source of ordered) {
113
286
  const sourceId = source.id;
114
287
  if (!sourceId)
@@ -147,6 +320,7 @@ exports.pass03 = {
147
320
  }
148
321
  if (config.dryRun) {
149
322
  existingId ? entry.updated++ : entry.created++;
323
+ equipmentBySource.set(sourceId, existingId ?? map_js_1.MigrationMap.dryId(sourceId));
150
324
  if (!existingId) {
151
325
  await map.record(index_js_1.Source.className, sourceId, index_js_1.Service_Equipment.className, map_js_1.MigrationMap.dryId(sourceId));
152
326
  }
@@ -159,6 +333,7 @@ exports.pass03 = {
159
333
  createdAt: source.createdAt,
160
334
  updatedAt: source.updatedAt,
161
335
  });
336
+ equipmentBySource.set(sourceId, newId);
162
337
  if (existingId) {
163
338
  entry.updated++;
164
339
  }
@@ -172,5 +347,7 @@ exports.pass03 = {
172
347
  continue;
173
348
  }
174
349
  }
350
+ // Header data last: it needs the equipment ids this loop just handed out.
351
+ await migrateSourceMeta(ctx, allSources, equipmentBySource);
175
352
  },
176
353
  };
@@ -6,24 +6,21 @@ import { type Pass } from "../lib/pass.js";
6
6
  * retired and material now references the shared article catalogue instead, so
7
7
  * the same v1 rows land in `OD3_BDE_Article` with `type: "spare_part"`.
8
8
  *
9
- * **Stock keeping lands in columns (since 2026-09-18).** `BDE_Article` used to
10
- * be a lean catalogue that was shared with BDE and therefore not ours to
11
- * widen, so v1's stock fields went to a `Meta_Entry` instead. The class has
12
- * since gained `stock`, `minimumStock`, `storageLocation`, `supplier`,
13
- * `orderNumber`, `price`, `priceCurrency` and `packageSize`, and this pass
14
- * writes them there.
9
+ * **Stock keeping goes to columns since 2026-09-25.** `OD3_BDE_Article` gained
10
+ * `stock`, `minimumStock`, `storageLocation`, `supplier`, `orderNumber`,
11
+ * `price`, `priceCurrency` and `packageSize` on 2026-09-18, so the values this
12
+ * pass used to park in plugin-meta are written to the class itself. An entry
13
+ * left from an earlier run has those keys stripped and is removed when nothing
14
+ * else remains — otherwise every value would show twice, once in the article
15
+ * form and once under *Kopfdaten*.
15
16
  *
16
- * What still goes to meta under `["service","article","meta"]`: `category`,
17
- * which deliberately got no column (tags and `type` already classify), and the
18
- * equipment links. Nothing is dropped. See `lib/articleMeta.ts` for why that
17
+ * **What still has no column stays meta** under `["service","article","meta"]`:
18
+ * v1's `category` — deliberately never given a column, since tags and `type`
19
+ * already classify and a third such field goes stale — v1's `description`, for
20
+ * which the label column is taken by v1's `name`, and the equipment links behind
21
+ * `Item.sources`. Nothing is dropped. See `lib/articleMeta.ts` for why that
19
22
  * context and not the ABAS one.
20
23
  *
21
- * ⚠️ **Installations migrated before this change keep their values in meta.**
22
- * There is no repair pass: few installations track material at all, so
23
- * re-entering the handful of articles was judged cheaper than a script running
24
- * against customer data. Such an installation shows the values in the meta
25
- * block of the article admin view while the columns sit empty.
26
- *
27
24
  * Two naming traps, both inherited from BDE: the label column is `description`,
28
25
  * not `name`; and the soft-delete flag is `isDeleted`, not `deleted`.
29
26
  *
@@ -28,24 +28,21 @@ const ARTICLE_TYPE_SPARE_PART = "spare_part";
28
28
  * retired and material now references the shared article catalogue instead, so
29
29
  * the same v1 rows land in `OD3_BDE_Article` with `type: "spare_part"`.
30
30
  *
31
- * **Stock keeping lands in columns (since 2026-09-18).** `BDE_Article` used to
32
- * be a lean catalogue that was shared with BDE and therefore not ours to
33
- * widen, so v1's stock fields went to a `Meta_Entry` instead. The class has
34
- * since gained `stock`, `minimumStock`, `storageLocation`, `supplier`,
35
- * `orderNumber`, `price`, `priceCurrency` and `packageSize`, and this pass
36
- * writes them there.
31
+ * **Stock keeping goes to columns since 2026-09-25.** `OD3_BDE_Article` gained
32
+ * `stock`, `minimumStock`, `storageLocation`, `supplier`, `orderNumber`,
33
+ * `price`, `priceCurrency` and `packageSize` on 2026-09-18, so the values this
34
+ * pass used to park in plugin-meta are written to the class itself. An entry
35
+ * left from an earlier run has those keys stripped and is removed when nothing
36
+ * else remains — otherwise every value would show twice, once in the article
37
+ * form and once under *Kopfdaten*.
37
38
  *
38
- * What still goes to meta under `["service","article","meta"]`: `category`,
39
- * which deliberately got no column (tags and `type` already classify), and the
40
- * equipment links. Nothing is dropped. See `lib/articleMeta.ts` for why that
39
+ * **What still has no column stays meta** under `["service","article","meta"]`:
40
+ * v1's `category` — deliberately never given a column, since tags and `type`
41
+ * already classify and a third such field goes stale — v1's `description`, for
42
+ * which the label column is taken by v1's `name`, and the equipment links behind
43
+ * `Item.sources`. Nothing is dropped. See `lib/articleMeta.ts` for why that
41
44
  * context and not the ABAS one.
42
45
  *
43
- * ⚠️ **Installations migrated before this change keep their values in meta.**
44
- * There is no repair pass: few installations track material at all, so
45
- * re-entering the handful of articles was judged cheaper than a script running
46
- * against customer data. Such an installation shows the values in the meta
47
- * block of the article admin view while the columns sit empty.
48
- *
49
46
  * Two naming traps, both inherited from BDE: the label column is `description`,
50
47
  * not `name`; and the soft-delete flag is `isDeleted`, not `deleted`.
51
48
  *
@@ -68,6 +65,9 @@ exports.pass05 = {
68
65
  const contextString = (0, ptr_js_1.contextToString)(articleMeta_js_1.ARTICLE_META_CONTEXT);
69
66
  let withMeta = 0;
70
67
  let unparseablePrices = 0;
68
+ let legacyStripped = 0;
69
+ let legacyRemoved = 0;
70
+ const strippedTenants = new Set();
71
71
  for (const item of items) {
72
72
  const sourceId = item.id;
73
73
  if (!sourceId)
@@ -90,9 +90,8 @@ exports.pass05 = {
90
90
  }
91
91
  if (item.get("stockUnit"))
92
92
  target.set("unit", item.get("stockUnit"));
93
- // Stock keeping goes onto the class. It used to go to meta because
94
- // `BDE_Article` was shared with BDE and not ours to widen; the columns
95
- // were added on 2026-09-18, so the values belong in them.
93
+ // Stock keeping: real columns since 2026-09-18. v1's `stockAlarmAt` is
94
+ // the same idea as `minimumStock` under its older name.
96
95
  for (const [from, to] of [
97
96
  ["storageLocation", "storageLocation"],
98
97
  ["supplier", "supplier"],
@@ -103,8 +102,6 @@ exports.pass05 = {
103
102
  target.set(to, value.trim());
104
103
  }
105
104
  }
106
- // v1's `stockAlarmAt` is the reorder level; renamed because it raises no
107
- // alarm.
108
105
  for (const [from, to] of [
109
106
  ["stock", "stock"],
110
107
  ["stockAlarmAt", "minimumStock"],
@@ -113,24 +110,37 @@ exports.pass05 = {
113
110
  if (typeof value === "number")
114
111
  target.set(to, value);
115
112
  }
116
- // Only what still has no column. `category` was deliberately not added —
117
- // tags and `type` already classify, and a third such field goes stale.
118
- const metaValues = {};
119
- const category = item.get("category");
120
- if (typeof category === "string" && category.trim()) {
121
- metaValues.category = category.trim();
122
- }
123
113
  // v1 stored price as a free-form string; keep the number, report the rest
124
114
  // rather than silently discarding it.
115
+ //
116
+ // Note `price` carries `defaultValue: 0` in the schema, so an unparseable
117
+ // one does not stay empty — it reads as 0, i.e. free. The warning below is
118
+ // the only signal that it was never a number, so do not drop it.
125
119
  const rawPrice = item.get("price");
126
120
  const price = (0, articleMeta_js_1.parsePrice)(rawPrice);
127
- if (price !== undefined)
121
+ if (price !== undefined) {
128
122
  target.set("price", price);
123
+ const currency = (0, articleMeta_js_1.parsePriceCurrency)(rawPrice);
124
+ if (currency)
125
+ target.set("priceCurrency", currency);
126
+ }
129
127
  else if (rawPrice) {
130
128
  unparseablePrices += 1;
131
129
  report.warn(entry, `item ${sourceId} ("${item.get("name")}") price "${String(rawPrice)}" ` +
132
130
  `is not a number — left unset on the article`);
133
131
  }
132
+ // What the catalogue still has no column for. v1 carried both a `name`
133
+ // and a `description`; `name` is the label (BDE calls that column
134
+ // `description`), so v1's own description would otherwise be dropped.
135
+ const metaValues = {};
136
+ const category = item.get("category");
137
+ if (typeof category === "string" && category.trim()) {
138
+ metaValues.category = category.trim();
139
+ }
140
+ const notes = item.get("description");
141
+ if (typeof notes === "string" && notes.trim()) {
142
+ metaValues.notes = notes.trim();
143
+ }
134
144
  // `Item.sources` (Relation<Source>) -> the migrated Equipment ids.
135
145
  const equipmentIds = [];
136
146
  for (const src of await (0, latest_js_1.relationObjects)(item, "sources", config.batchSize)) {
@@ -175,16 +185,42 @@ exports.pass05 = {
175
185
  }
176
186
  // Meta last: it needs the article id, and an entry with no values is
177
187
  // not worth a row.
178
- if (Object.keys(metaValues).length > 0) {
188
+ const existingMeta = metaByArticle.get(newId);
189
+ // An entry written before 2026-09-25 still carries the stock-keeping
190
+ // values that are columns now. Keep whatever else it holds, drop those.
191
+ const carried = {
192
+ ...(existingMeta?.get("values") ?? {}),
193
+ };
194
+ let strippedHere = 0;
195
+ for (const key of articleMeta_js_1.META_KEYS_NOW_COLUMNS) {
196
+ if (key in carried) {
197
+ delete carried[key];
198
+ strippedHere += 1;
199
+ }
200
+ }
201
+ if (strippedHere > 0) {
202
+ legacyStripped += 1;
203
+ strippedTenants.add(tenantId ?? "");
204
+ }
205
+ const nextValues = { ...carried, ...metaValues };
206
+ if (Object.keys(nextValues).length === 0) {
207
+ // Nothing left that has no column of its own. A row holding `{}`
208
+ // would render as an empty *Kopfdaten* block, so drop the row.
209
+ if (existingMeta) {
210
+ await existingMeta.destroy(acl_js_1.MIGRATION_SAVE);
211
+ metaByArticle.delete(newId);
212
+ legacyRemoved += 1;
213
+ }
214
+ }
215
+ else {
179
216
  if (!metaConfigByTenant.has(tenantId ?? "")) {
180
217
  metaConfigByTenant.set(tenantId ?? "", await (0, articleMeta_js_1.ensureArticleMetaConfig)(config, tenantId ?? ""));
181
218
  }
182
- const existingMeta = metaByArticle.get(newId);
183
219
  const metaEntry = existingMeta ?? new index_js_1.Meta_Entry();
184
220
  metaEntry.set("context", contextString);
185
221
  metaEntry.set("entryClassName", index_js_1.BDE_Article.className);
186
222
  metaEntry.set("entryObjectId", newId);
187
- metaEntry.set("values", metaValues);
223
+ metaEntry.set("values", nextValues);
188
224
  const originPtr = (0, ptr_js_1.maybePtr)("OD3_Meta_Config", metaConfigByTenant.get(tenantId ?? ""));
189
225
  if (originPtr)
190
226
  metaEntry.set("origin", originPtr);
@@ -208,9 +244,23 @@ exports.pass05 = {
208
244
  continue;
209
245
  }
210
246
  }
247
+ // A tenant whose entries all emptied never reaches ensureArticleMetaConfig
248
+ // in the loop, so its `Meta_Config` would go on offering the stock fields as
249
+ // an empty form — the same duplication, one layer up.
250
+ for (const strippedTenant of strippedTenants) {
251
+ if (!metaConfigByTenant.has(strippedTenant)) {
252
+ await (0, articleMeta_js_1.ensureArticleMetaConfig)(config, strippedTenant);
253
+ }
254
+ }
211
255
  if (withMeta > 0) {
212
- report.info(entry, `${withMeta} article(s) carry stock-keeping data as meta under ` +
213
- `["service","article","meta"] — editable in the article admin view`);
256
+ report.info(entry, `${withMeta} article(s) carry category, v1 description or equipment ` +
257
+ `links as meta under ["service","article","meta"] — stock keeping is ` +
258
+ `on the article itself`);
259
+ }
260
+ if (legacyStripped > 0) {
261
+ report.info(entry, `${legacyStripped} meta entr(ies) from a run before 2026-09-25 had ` +
262
+ `their stock-keeping values stripped — those are columns now; ` +
263
+ `${legacyRemoved} entr(ies) held nothing else and were removed`);
214
264
  }
215
265
  if (unparseablePrices > 0) {
216
266
  report.info(entry, `${unparseablePrices} price(s) could not be parsed into a number — see ` +
@@ -0,0 +1,15 @@
1
+ import { type Pass } from "../lib/pass.js";
2
+ /**
3
+ * Pass 13 — `OD3_Maintenance_Schedule_Template` → `OD3_Service_Schedule_Template`.
4
+ *
5
+ * A v1 template is a live parent: its plans inherit its interval and, when
6
+ * they have no steps of their own, its steps. A v2 template is a snapshot a
7
+ * plan is *copied* from and then forgets. So pass 14 resolves each plan's
8
+ * inheritance itself, and this pass only carries the templates over as the
9
+ * library they are in v2 — for plans still to be created.
10
+ *
11
+ * Dropped on the way, each reported: `color` (no column on the v2 template)
12
+ * and `sources` (v2 templates are equipment-agnostic; the plans made from a
13
+ * template are the link to the machines, and those migrate in pass 14).
14
+ */
15
+ export declare const pass13: Pass;
@@ -0,0 +1,163 @@
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.pass13 = 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
+ /**
18
+ * Pass 13 — `OD3_Maintenance_Schedule_Template` → `OD3_Service_Schedule_Template`.
19
+ *
20
+ * A v1 template is a live parent: its plans inherit its interval and, when
21
+ * they have no steps of their own, its steps. A v2 template is a snapshot a
22
+ * plan is *copied* from and then forgets. So pass 14 resolves each plan's
23
+ * inheritance itself, and this pass only carries the templates over as the
24
+ * library they are in v2 — for plans still to be created.
25
+ *
26
+ * Dropped on the way, each reported: `color` (no column on the v2 template)
27
+ * and `sources` (v2 templates are equipment-agnostic; the plans made from a
28
+ * template are the link to the machines, and those migrate in pass 14).
29
+ */
30
+ exports.pass13 = {
31
+ id: "13",
32
+ title: "schedule-templates",
33
+ needs: [],
34
+ async run({ config, map, report, entry }) {
35
+ const templates = await (0, pass_js_1.all)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule_Template), config.tenantId), config.batchSize);
36
+ if (templates.length === 0)
37
+ return;
38
+ const roleIdByName = new Map([...(await (0, ticket_js_1.loadRoleNames)(config))].map(([id, name]) => [name, id]));
39
+ const steps = new schedule_js_1.StepSource(config.batchSize);
40
+ let manual = 0;
41
+ let monthEnd = 0;
42
+ let colors = 0;
43
+ let withSources = 0;
44
+ for (const template of templates) {
45
+ const sourceId = template.id;
46
+ if (!sourceId)
47
+ continue;
48
+ const tenantId = (0, pass_js_1.refId)(template.get("tenant"));
49
+ if (!tenantId) {
50
+ report.error(entry, `template ${sourceId} has no tenant; Schedule_Template.tenant is ` +
51
+ `required — skipped`);
52
+ entry.skipped++;
53
+ continue;
54
+ }
55
+ const existingId = map.get(index_js_1.Maintenance_Schedule_Template.className, sourceId);
56
+ const target = existingId
57
+ ? new index_js_1.Service_Schedule_Template({ objectId: existingId })
58
+ : new index_js_1.Service_Schedule_Template();
59
+ const label = `template ${sourceId} ("${template.get("title") ?? ""}")`;
60
+ const access = (0, schedule_js_1.readV1Access)(template, tenantId);
61
+ const roles = (0, schedule_js_1.resolveRoles)((0, schedule_js_1.assignedRoleNames)(access, tenantId), roleIdByName);
62
+ const { cadence, warnings, notes } = (0, cadence_js_1.toCadence)(template.get("cron"), {
63
+ timezone: config.timezone,
64
+ fallbackStart: template.createdAt,
65
+ });
66
+ for (const warning of warnings)
67
+ report.warn(entry, `${label}: ${warning}`);
68
+ if (cadence.kind === "manual")
69
+ manual += 1;
70
+ if (notes.includes("month-end"))
71
+ monthEnd += 1;
72
+ const rows = await steps.of(template);
73
+ const contactIds = await (0, latest_js_1.relationIds)(template, "contacts", config.batchSize);
74
+ // A v1 template only carried the *timing* of a reminder; who was told
75
+ // came from each plan. So its rules name nobody and notify the roles the
76
+ // plan is assigned to — the editor's default — because applying a
77
+ // template in v2 copies its rules onto every new plan.
78
+ const rules = (0, schedule_js_1.notificationRules)(`${index_js_1.Maintenance_Schedule_Template.className}:${sourceId}`, template.get("notifyBeforeDue"), { assignedRoles: true });
79
+ if (rules.deviation)
80
+ report.warn(entry, `${label}: ${rules.deviation}`);
81
+ target.set("title", String(template.get("title") ?? "").trim() || `Vorlage ${sourceId}`);
82
+ if (template.get("description")) {
83
+ target.set("description", template.get("description"));
84
+ }
85
+ target.set("tenant", (0, ptr_js_1.tenantPtr)(tenantId));
86
+ target.set("cadence", cadence);
87
+ target.set("steps", rows.map((row, index) => (0, schedule_js_1.toV2Step)(row, (0, schedule_js_1.templateStepId)(sourceId, row.id), index, true)));
88
+ target.set("serviceProviders", (0, schedule_js_1.serviceProviders)(contactIds));
89
+ target.set("notifications", rules.rules);
90
+ if (access.creatorId)
91
+ target.set("user", (0, ptr_js_1.userPtr)(access.creatorId));
92
+ // v1 lists only `enabled === true` templates; a disabled one is retired,
93
+ // which v2 spells as archived.
94
+ if (template.get("enabled") !== true) {
95
+ target.set("deletedAt", template.updatedAt ?? new Date());
96
+ }
97
+ if (template.get("color"))
98
+ colors += 1;
99
+ if ((await (0, latest_js_1.relationIds)(template, "sources", config.batchSize)).length) {
100
+ withSources += 1;
101
+ }
102
+ if (access.readerUserIds.length) {
103
+ report.warn(entry, `${label}: v1 also let ${access.readerUserIds.length} further ` +
104
+ `user(s) read it — v2 templates are shared by role only, so they lose it`);
105
+ }
106
+ if (roles.unknown.length) {
107
+ report.warn(entry, `${label}: ACL names role(s) ${roles.unknown.join(", ")} that no longer ` +
108
+ `exist — not carried over`);
109
+ }
110
+ if (!existingId) {
111
+ target.setACL((0, schedule_js_1.privateAcl)({
112
+ tenantId,
113
+ creatorId: access.creatorId,
114
+ roleNames: roles.names,
115
+ userIds: [],
116
+ }));
117
+ }
118
+ if (config.dryRun) {
119
+ existingId ? entry.updated++ : entry.created++;
120
+ if (!existingId) {
121
+ await map.record(index_js_1.Maintenance_Schedule_Template.className, sourceId, index_js_1.Service_Schedule_Template.className, map_js_1.MigrationMap.dryId(sourceId));
122
+ }
123
+ continue;
124
+ }
125
+ try {
126
+ const newId = await (0, acl_js_1.saveMigrated)(config, target, {
127
+ className: index_js_1.Service_Schedule_Template.className,
128
+ isNew: !existingId,
129
+ createdAt: template.createdAt,
130
+ updatedAt: template.updatedAt,
131
+ });
132
+ await (0, schedule_js_1.addAssignments)(index_js_1.Service_Schedule_Template.className, newId, {
133
+ roleIds: roles.ids,
134
+ });
135
+ if (existingId) {
136
+ entry.updated++;
137
+ }
138
+ else {
139
+ entry.created++;
140
+ await map.record(index_js_1.Maintenance_Schedule_Template.className, sourceId, index_js_1.Service_Schedule_Template.className, newId);
141
+ }
142
+ }
143
+ catch (error) {
144
+ report.error(entry, `${label} failed: ${error.message}`);
145
+ }
146
+ }
147
+ if (manual > 0) {
148
+ report.info(entry, `${manual} template(s) without a usable interval → manual`);
149
+ }
150
+ if (monthEnd > 0) {
151
+ report.info(entry, `${monthEnd} template(s) start on a month end — their rule uses ` +
152
+ `BYSETPOS, which the series editor simplifies when re-edited`);
153
+ }
154
+ if (colors > 0) {
155
+ report.info(entry, `${colors} template colour(s) dropped — the v2 template has no colour ` +
156
+ `(plans keep theirs)`);
157
+ }
158
+ if (withSources > 0) {
159
+ report.info(entry, `${withSources} template(s) listed sources — dropped: v2 templates are ` +
160
+ `equipment-agnostic, the plans made from them carry the machine`);
161
+ }
162
+ },
163
+ };