@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
|
@@ -4,10 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const node_1 = __importDefault(require("parse/node"));
|
|
7
|
+
const serviceCalendarMeta_js_1 = require("../../features/openservice/serviceSchedules/calendarSync/serviceCalendarMeta.js");
|
|
7
8
|
const index_js_1 = require("../../types/index.js");
|
|
9
|
+
const articleMeta_js_1 = require("./lib/articleMeta.js");
|
|
10
|
+
const equipmentMeta_js_1 = require("./lib/equipmentMeta.js");
|
|
8
11
|
const env_js_1 = require("./lib/env.js");
|
|
9
12
|
const message_js_1 = require("./lib/message.js");
|
|
10
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");
|
|
11
16
|
/** Pointer/array-of-ids fields to resolve, and the class they must resolve into. */
|
|
12
17
|
const REFERENCE_FIELDS = [
|
|
13
18
|
{ field: "status", className: index_js_1.Service_Status.className },
|
|
@@ -65,6 +70,75 @@ function comparable(value) {
|
|
|
65
70
|
};
|
|
66
71
|
return JSON.stringify(norm(value));
|
|
67
72
|
}
|
|
73
|
+
/** The v2 ids the migration recorded for a v1 class. */
|
|
74
|
+
async function migratedTargets(sourceClass, batchSize) {
|
|
75
|
+
const ids = new Set();
|
|
76
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query("OD3_Service_MigrationMap").equalTo("sourceClass", sourceClass), batchSize)) {
|
|
77
|
+
for (const row of page)
|
|
78
|
+
ids.add(row.get("targetId"));
|
|
79
|
+
}
|
|
80
|
+
return ids;
|
|
81
|
+
}
|
|
82
|
+
/** objectId → tenant id of every row of a class. */
|
|
83
|
+
async function tenantsById(cls, batchSize) {
|
|
84
|
+
const tenants = new Map();
|
|
85
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(cls), batchSize)) {
|
|
86
|
+
for (const row of page) {
|
|
87
|
+
if (row.id)
|
|
88
|
+
tenants.set(row.id, (0, pass_js_1.refId)(row.get("tenant")));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return tenants;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* What is wrong with a cadence, as the v2 plan editor and `@opendash/schedule`
|
|
95
|
+
* read one. An `RRULE:` prefix in particular computes fine but breaks the
|
|
96
|
+
* editor, which would corrupt the rule on the next save.
|
|
97
|
+
*/
|
|
98
|
+
function cadenceProblems(cadence) {
|
|
99
|
+
if (!cadence || typeof cadence !== "object")
|
|
100
|
+
return ["no cadence"];
|
|
101
|
+
const c = cadence;
|
|
102
|
+
if (c.kind === "manual")
|
|
103
|
+
return [];
|
|
104
|
+
if (c.kind !== "rrule")
|
|
105
|
+
return [`cadence kind ${String(c.kind)}`];
|
|
106
|
+
const problems = [];
|
|
107
|
+
const rule = typeof c.rrule === "string" ? c.rrule : "";
|
|
108
|
+
if (!rule.includes("FREQ="))
|
|
109
|
+
problems.push("rrule without FREQ");
|
|
110
|
+
if (/RRULE:|DTSTART/.test(rule))
|
|
111
|
+
problems.push("rrule carries a prefix/DTSTART");
|
|
112
|
+
const isDate = (v) => typeof v === "string" && !Number.isNaN(Date.parse(v));
|
|
113
|
+
if (!isDate(c.dtstart))
|
|
114
|
+
problems.push("dtstart not an ISO date");
|
|
115
|
+
if (c.until !== undefined && !isDate(c.until)) {
|
|
116
|
+
problems.push("until not an ISO date");
|
|
117
|
+
}
|
|
118
|
+
if (typeof c.timezone !== "string")
|
|
119
|
+
problems.push("no timezone");
|
|
120
|
+
return problems;
|
|
121
|
+
}
|
|
122
|
+
/** What is wrong with a `steps` array: ids must be unique, titles present. */
|
|
123
|
+
function stepProblems(steps) {
|
|
124
|
+
if (steps === undefined)
|
|
125
|
+
return [];
|
|
126
|
+
if (!Array.isArray(steps))
|
|
127
|
+
return ["steps not a list"];
|
|
128
|
+
const problems = [];
|
|
129
|
+
const ids = new Set();
|
|
130
|
+
for (const step of steps) {
|
|
131
|
+
if (typeof step?.id !== "string" || !step.id)
|
|
132
|
+
problems.push("step without id");
|
|
133
|
+
else if (ids.has(step.id))
|
|
134
|
+
problems.push(`duplicate step id ${step.id}`);
|
|
135
|
+
else
|
|
136
|
+
ids.add(step.id);
|
|
137
|
+
if (!step?.title)
|
|
138
|
+
problems.push("step without title");
|
|
139
|
+
}
|
|
140
|
+
return problems;
|
|
141
|
+
}
|
|
68
142
|
const checks = [
|
|
69
143
|
// ── Counts ───────────────────────────────────────────────────────────────
|
|
70
144
|
{
|
|
@@ -417,10 +491,20 @@ const checks = [
|
|
|
417
491
|
"material",
|
|
418
492
|
];
|
|
419
493
|
const mismatches = [];
|
|
494
|
+
let nativeSkipped = 0;
|
|
420
495
|
for await (const page of (0, pass_js_1.pages)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Service_Ticket), tenantId), batchSize)) {
|
|
421
496
|
for (const t of page) {
|
|
422
497
|
if (!t.id)
|
|
423
498
|
continue;
|
|
499
|
+
// Only tickets this migration created. A ticket made in v2 directly has
|
|
500
|
+
// no v1 side tables behind it and therefore no reconstructed history —
|
|
501
|
+
// flagging it would fail the cutover on any instance where v2 was
|
|
502
|
+
// trialled first, which the numbering note explicitly expects.
|
|
503
|
+
const origin = t.get("origin");
|
|
504
|
+
if (typeof origin !== "string" || !origin.startsWith("legacy:")) {
|
|
505
|
+
nativeSkipped += 1;
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
424
508
|
const snapshot = latestSnapshot.get(t.id);
|
|
425
509
|
if (!snapshot) {
|
|
426
510
|
if (mismatches.length < 10) {
|
|
@@ -443,7 +527,19 @@ const checks = [
|
|
|
443
527
|
}
|
|
444
528
|
}
|
|
445
529
|
}
|
|
446
|
-
|
|
530
|
+
if (mismatches.length) {
|
|
531
|
+
return (`e.g. ${mismatches.join("; ")}` +
|
|
532
|
+
(nativeSkipped
|
|
533
|
+
? ` (${nativeSkipped} non-migrated ticket(s) skipped)`
|
|
534
|
+
: ""));
|
|
535
|
+
}
|
|
536
|
+
// Said out loud rather than silently passing: on an instance that trialled
|
|
537
|
+
// v2 first, the number of tickets this check does not cover is worth seeing.
|
|
538
|
+
if (nativeSkipped > 0) {
|
|
539
|
+
console.log(` note: ${nativeSkipped} ticket(s) were created in v2 directly ` +
|
|
540
|
+
`(no legacy: origin) and are outside this check`);
|
|
541
|
+
}
|
|
542
|
+
return undefined;
|
|
447
543
|
},
|
|
448
544
|
},
|
|
449
545
|
{
|
|
@@ -453,24 +549,36 @@ const checks = [
|
|
|
453
549
|
// Under the master key Parse silently stamps `createdAt = now`, which would
|
|
454
550
|
// collapse the whole trail onto the migration date. This is the check that
|
|
455
551
|
// catches a run that used the wrong key.
|
|
552
|
+
//
|
|
553
|
+
// Judged per class: pass 12 (tickets) and pass 19 (plans, executions)
|
|
554
|
+
// can run separately, and one class with genuine history must not hide
|
|
555
|
+
// another whose history collapsed.
|
|
456
556
|
const cutoff = Date.now() - 60 * 60 * 1000;
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
557
|
+
const tally = new Map();
|
|
558
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Changelog).containedIn("nameOfClass", [
|
|
559
|
+
index_js_1.Service_Ticket.className,
|
|
560
|
+
index_js_1.Service_Schedule.className,
|
|
561
|
+
index_js_1.Service_Schedule_Execution.className,
|
|
562
|
+
]), batchSize)) {
|
|
460
563
|
for (const row of page) {
|
|
461
564
|
const context = row.get("context");
|
|
462
565
|
if (!context?.migrated)
|
|
463
566
|
continue;
|
|
464
|
-
|
|
567
|
+
const cls = row.get("nameOfClass");
|
|
568
|
+
const counts = tally.get(cls) ?? { total: 0, recent: 0 };
|
|
569
|
+
counts.total += 1;
|
|
465
570
|
if ((row.createdAt?.getTime() ?? 0) > cutoff)
|
|
466
|
-
recent += 1;
|
|
571
|
+
counts.recent += 1;
|
|
572
|
+
tally.set(cls, counts);
|
|
467
573
|
}
|
|
468
574
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
`
|
|
575
|
+
const collapsed = [...tally].filter(([, { total, recent }]) => total > 0 && recent === total);
|
|
576
|
+
return collapsed.length
|
|
577
|
+
? collapsed
|
|
578
|
+
.map(([cls, { total }]) => `all ${total} reconstructed ${cls} entries were created within ` +
|
|
579
|
+
`the last hour`)
|
|
580
|
+
.join("; ") +
|
|
581
|
+
` — timestamps were NOT preserved (was the maintenance key actually used?)`
|
|
474
582
|
: undefined;
|
|
475
583
|
},
|
|
476
584
|
},
|
|
@@ -503,12 +611,15 @@ const checks = [
|
|
|
503
611
|
index_js_1.Service_Tag.className,
|
|
504
612
|
index_js_1.Service_Equipment.className,
|
|
505
613
|
index_js_1.Service_Project.className,
|
|
614
|
+
index_js_1.Service_Schedule.className,
|
|
615
|
+
index_js_1.Service_Schedule_Template.className,
|
|
616
|
+
index_js_1.Service_Schedule_Execution.className,
|
|
506
617
|
])
|
|
507
618
|
.notEqualTo("masterkey", true), batchSize)) {
|
|
508
619
|
for (const row of page) {
|
|
509
620
|
const context = row.get("context");
|
|
510
621
|
if (context?.migrated)
|
|
511
|
-
continue; // written by pass 12, on purpose
|
|
622
|
+
continue; // written by pass 12 / 19, on purpose
|
|
512
623
|
if (row.get("actingUser"))
|
|
513
624
|
continue; // a real edit by a real user
|
|
514
625
|
total += 1;
|
|
@@ -523,6 +634,333 @@ const checks = [
|
|
|
523
634
|
: undefined;
|
|
524
635
|
},
|
|
525
636
|
},
|
|
637
|
+
// ── Articles: stock keeping belongs on the class ─────────────────────────
|
|
638
|
+
{
|
|
639
|
+
name: "no article carries stock-keeping values as plugin-meta",
|
|
640
|
+
hard: true,
|
|
641
|
+
async run(_tenantId, batchSize) {
|
|
642
|
+
const offenders = [];
|
|
643
|
+
let total = 0;
|
|
644
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Meta_Entry)
|
|
645
|
+
.equalTo("context", (0, ptr_js_1.contextToString)(articleMeta_js_1.ARTICLE_META_CONTEXT))
|
|
646
|
+
.equalTo("entryClassName", index_js_1.BDE_Article.className), batchSize)) {
|
|
647
|
+
for (const row of page) {
|
|
648
|
+
const values = (row.get("values") ?? {});
|
|
649
|
+
const stale = articleMeta_js_1.META_KEYS_NOW_COLUMNS.filter((key) => key in values);
|
|
650
|
+
if (stale.length === 0)
|
|
651
|
+
continue;
|
|
652
|
+
total += 1;
|
|
653
|
+
if (offenders.length < 3) {
|
|
654
|
+
offenders.push(`${row.get("entryObjectId")} (${stale.join(", ")})`);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
// These became columns on 2026-09-18. An entry still holding them means
|
|
659
|
+
// pass 05 last ran before 2026-09-25: the article form and *Kopfdaten*
|
|
660
|
+
// would each show the value, and editing one would not update the other.
|
|
661
|
+
return total > 0
|
|
662
|
+
? `${total} article meta entr(ies) still hold stock-keeping values — ` +
|
|
663
|
+
`re-run pass 05, which strips them. e.g. ${offenders.join("; ")}`
|
|
664
|
+
: undefined;
|
|
665
|
+
},
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
name: "migrated articles carry their v1 stock numbers as columns",
|
|
669
|
+
hard: true,
|
|
670
|
+
async run(tenantId, batchSize) {
|
|
671
|
+
let v1WithStock = 0;
|
|
672
|
+
for await (const page of (0, pass_js_1.pages)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Item), tenantId), batchSize)) {
|
|
673
|
+
for (const item of page) {
|
|
674
|
+
if (typeof item.get("stock") === "number" ||
|
|
675
|
+
typeof item.get("stockAlarmAt") === "number") {
|
|
676
|
+
v1WithStock += 1;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
if (v1WithStock === 0)
|
|
681
|
+
return undefined;
|
|
682
|
+
let v2WithStock = 0;
|
|
683
|
+
for await (const page of (0, pass_js_1.pages)(() => node_1.default.Query.or(new node_1.default.Query(index_js_1.BDE_Article).exists("stock"), new node_1.default.Query(index_js_1.BDE_Article).exists("minimumStock")), batchSize)) {
|
|
684
|
+
v2WithStock += page.length;
|
|
685
|
+
}
|
|
686
|
+
// The failure this guards: a container still serving the schema baked
|
|
687
|
+
// before 2026-09-25 has no stock columns, and `initSchema` runs with
|
|
688
|
+
// `deleteFields` wherever FORCE_SCHEMA is on — so the values would be
|
|
689
|
+
// written and then removed on the next boot. Counts rather than a join;
|
|
690
|
+
// wholesale loss is the failure mode that matters.
|
|
691
|
+
return v2WithStock >= v1WithStock
|
|
692
|
+
? undefined
|
|
693
|
+
: `${v1WithStock} v1 item(s) carry stock numbers but only ` +
|
|
694
|
+
`${v2WithStock} article(s) do — is the container serving a schema ` +
|
|
695
|
+
`without the stock columns? (pnpm docker:rebuild)`;
|
|
696
|
+
},
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
name: "every migrated source's header data reached its equipment",
|
|
700
|
+
hard: true,
|
|
701
|
+
async run(_tenantId, batchSize) {
|
|
702
|
+
// sourceId -> equipmentId, straight from the map: immune to equipment
|
|
703
|
+
// created in v2 afterwards.
|
|
704
|
+
const equipmentBySource = new Map();
|
|
705
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query("OD3_Service_MigrationMap").equalTo("sourceClass", index_js_1.Source.className), batchSize)) {
|
|
706
|
+
for (const row of page) {
|
|
707
|
+
const from = row.get("sourceId");
|
|
708
|
+
const to = row.get("targetId");
|
|
709
|
+
if (from && to)
|
|
710
|
+
equipmentBySource.set(from, to);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
if (equipmentBySource.size === 0)
|
|
714
|
+
return undefined;
|
|
715
|
+
// Which migrated sources carry header data worth an entry. A SourceMeta
|
|
716
|
+
// with nothing in it produces no row, by design.
|
|
717
|
+
const metaIdBySource = new Map();
|
|
718
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Source), batchSize)) {
|
|
719
|
+
for (const source of page) {
|
|
720
|
+
const metaId = (0, pass_js_1.refId)(source.get("meta"));
|
|
721
|
+
if (source.id && metaId && equipmentBySource.has(source.id)) {
|
|
722
|
+
metaIdBySource.set(source.id, metaId);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (metaIdBySource.size === 0)
|
|
727
|
+
return undefined;
|
|
728
|
+
const hasContent = new Set();
|
|
729
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.SourceMeta), batchSize)) {
|
|
730
|
+
for (const meta of page) {
|
|
731
|
+
if (!meta.id)
|
|
732
|
+
continue;
|
|
733
|
+
const data = (meta.get("data") ?? {});
|
|
734
|
+
const any = Object.keys(data).length > 0 ||
|
|
735
|
+
["name", "description", "location", "file"].some((c) => Boolean(meta.get(c)));
|
|
736
|
+
if (any)
|
|
737
|
+
hasContent.add(meta.id);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
const entries = new Set();
|
|
741
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Meta_Entry)
|
|
742
|
+
.equalTo("context", (0, ptr_js_1.contextToString)(equipmentMeta_js_1.EQUIPMENT_META_CONTEXT))
|
|
743
|
+
.equalTo("entryClassName", index_js_1.Service_Equipment.className), batchSize)) {
|
|
744
|
+
for (const row of page) {
|
|
745
|
+
const id = row.get("entryObjectId");
|
|
746
|
+
if (id)
|
|
747
|
+
entries.add(id);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
const missing = [];
|
|
751
|
+
for (const [sourceId, metaId] of metaIdBySource) {
|
|
752
|
+
if (!hasContent.has(metaId))
|
|
753
|
+
continue;
|
|
754
|
+
const equipmentId = equipmentBySource.get(sourceId);
|
|
755
|
+
if (!entries.has(equipmentId) && missing.length < 5) {
|
|
756
|
+
missing.push(`source ${sourceId} -> equipment ${equipmentId}`);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
// D2 was reversed on 2026-09-25: SourceMeta migrates because clients use
|
|
760
|
+
// it. Losing it silently is exactly the failure this guards.
|
|
761
|
+
return missing.length
|
|
762
|
+
? `${missing.length} source(s) with header data have no equipment meta ` +
|
|
763
|
+
`entry — e.g. ${missing.join("; ")}`
|
|
764
|
+
: undefined;
|
|
765
|
+
},
|
|
766
|
+
},
|
|
767
|
+
// ── Schedules ────────────────────────────────────────────────────────────
|
|
768
|
+
{
|
|
769
|
+
name: "every v1 schedule template was migrated",
|
|
770
|
+
hard: true,
|
|
771
|
+
async run(tenantId, batchSize) {
|
|
772
|
+
const [v1, migrated] = await Promise.all([
|
|
773
|
+
(0, pass_js_1.countAll)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule_Template), tenantId), batchSize),
|
|
774
|
+
migratedCount(index_js_1.Maintenance_Schedule_Template.className, batchSize),
|
|
775
|
+
]);
|
|
776
|
+
return migrated >= v1
|
|
777
|
+
? undefined
|
|
778
|
+
: `${v1} v1 template(s) but only ${migrated} mapping(s)`;
|
|
779
|
+
},
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
name: "every v1 maintenance plan was migrated",
|
|
783
|
+
hard: true,
|
|
784
|
+
async run(tenantId, batchSize) {
|
|
785
|
+
const [v1, migrated] = await Promise.all([
|
|
786
|
+
(0, pass_js_1.countAll)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Maintenance_Schedule), tenantId), batchSize),
|
|
787
|
+
migratedCount(index_js_1.Maintenance_Schedule.className, batchSize),
|
|
788
|
+
]);
|
|
789
|
+
return migrated >= v1
|
|
790
|
+
? undefined
|
|
791
|
+
: `${v1} v1 plan(s) but only ${migrated} mapping(s)`;
|
|
792
|
+
},
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
name: "every v1 execution was migrated, except the abandoned runs",
|
|
796
|
+
hard: true,
|
|
797
|
+
async run(tenantId, batchSize) {
|
|
798
|
+
// The same classification pass 15 applies — imported, so the check
|
|
799
|
+
// cannot disagree with the pass it checks.
|
|
800
|
+
const scope = { tenantId, batchSize };
|
|
801
|
+
const plans = await schedule_js_1.PlanIndex.load(scope);
|
|
802
|
+
const stepsByExecution = await (0, schedule_js_1.executionStepsByExecution)(scope);
|
|
803
|
+
let expected = 0;
|
|
804
|
+
let abandoned = 0;
|
|
805
|
+
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), tenantId), batchSize)) {
|
|
806
|
+
for (const execution of page) {
|
|
807
|
+
const fate = (0, schedule_js_1.classifyExecution)(execution, stepsByExecution.get(execution.id ?? "") ?? [], !!plans.resolve(execution));
|
|
808
|
+
if (fate.fate === "abandoned")
|
|
809
|
+
abandoned += 1;
|
|
810
|
+
else
|
|
811
|
+
expected += 1;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
const migrated = await migratedCount(index_js_1.Maintenance_Schedule_Execution.className, batchSize);
|
|
815
|
+
return migrated >= expected
|
|
816
|
+
? undefined
|
|
817
|
+
: `${expected} v1 execution(s) to migrate (${abandoned} abandoned left ` +
|
|
818
|
+
`out) but only ${migrated} mapping(s)`;
|
|
819
|
+
},
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
name: "every migrated plan and template has a readable cadence and steps",
|
|
823
|
+
hard: true,
|
|
824
|
+
async run(tenantId, batchSize) {
|
|
825
|
+
const bad = [];
|
|
826
|
+
const inspect = (row) => {
|
|
827
|
+
const problems = [
|
|
828
|
+
...cadenceProblems(row.get("cadence")),
|
|
829
|
+
...stepProblems(row.get("steps")),
|
|
830
|
+
];
|
|
831
|
+
if (!row.get("title"))
|
|
832
|
+
problems.push("no title");
|
|
833
|
+
if (!(0, pass_js_1.refId)(row.get("tenant")))
|
|
834
|
+
problems.push("no tenant");
|
|
835
|
+
if (problems.length && bad.length < 10) {
|
|
836
|
+
bad.push(`${row.className} ${row.id}: ${problems.join(", ")}`);
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
for await (const page of (0, pass_js_1.pages)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Service_Schedule), tenantId).startsWith("origin", "legacy:"), batchSize)) {
|
|
840
|
+
page.forEach(inspect);
|
|
841
|
+
}
|
|
842
|
+
const templates = await migratedTargets(index_js_1.Maintenance_Schedule_Template.className, batchSize);
|
|
843
|
+
for await (const page of (0, pass_js_1.pages)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Service_Schedule_Template), tenantId), batchSize)) {
|
|
844
|
+
page.filter((row) => templates.has(row.id ?? "")).forEach(inspect);
|
|
845
|
+
}
|
|
846
|
+
return bad.length ? `e.g. ${bad.join("; ")}` : undefined;
|
|
847
|
+
},
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
name: "every migrated execution has its plan or machine, in its own tenant",
|
|
851
|
+
hard: true,
|
|
852
|
+
async run(tenantId, batchSize) {
|
|
853
|
+
const migrated = await migratedTargets(index_js_1.Maintenance_Schedule_Execution.className, batchSize);
|
|
854
|
+
const plans = await tenantsById(index_js_1.Service_Schedule, batchSize);
|
|
855
|
+
const machines = await tenantsById(index_js_1.Service_Equipment, batchSize);
|
|
856
|
+
const bad = [];
|
|
857
|
+
for await (const page of (0, pass_js_1.pages)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Service_Schedule_Execution), tenantId), batchSize)) {
|
|
858
|
+
for (const execution of page) {
|
|
859
|
+
if (!execution.id || !migrated.has(execution.id))
|
|
860
|
+
continue;
|
|
861
|
+
const own = (0, pass_js_1.refId)(execution.get("tenant"));
|
|
862
|
+
const problems = [];
|
|
863
|
+
const planId = (0, pass_js_1.refId)(execution.get("schedule"));
|
|
864
|
+
const machineId = (0, pass_js_1.refId)(execution.get("equipment"));
|
|
865
|
+
if (!planId && !machineId)
|
|
866
|
+
problems.push("neither schedule nor equipment");
|
|
867
|
+
const references = [
|
|
868
|
+
["schedule", planId, plans],
|
|
869
|
+
["equipment", machineId, machines],
|
|
870
|
+
];
|
|
871
|
+
for (const [what, id, known] of references) {
|
|
872
|
+
if (!id)
|
|
873
|
+
continue;
|
|
874
|
+
if (!known.has(id))
|
|
875
|
+
problems.push(`${what} ${id} does not exist`);
|
|
876
|
+
else if (known.get(id) !== own)
|
|
877
|
+
problems.push(`${what} of another tenant`);
|
|
878
|
+
}
|
|
879
|
+
if (!own)
|
|
880
|
+
problems.push("no tenant");
|
|
881
|
+
if (problems.length && bad.length < 10) {
|
|
882
|
+
bad.push(`${execution.id}: ${problems.join(", ")}`);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return bad.length ? `e.g. ${bad.join("; ")}` : undefined;
|
|
887
|
+
},
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
name: "every migrated execution's results and values belong to its steps",
|
|
891
|
+
hard: true,
|
|
892
|
+
async run(tenantId, batchSize) {
|
|
893
|
+
// The protocol pairs `stepResults` and captured `Meta_Entry` values with
|
|
894
|
+
// `steps` by id. A mismatch renders as a step without its result — the
|
|
895
|
+
// id minting in lib/schedule.ts is what this checks.
|
|
896
|
+
const migrated = await migratedTargets(index_js_1.Maintenance_Schedule_Execution.className, batchSize);
|
|
897
|
+
const stepIds = new Map();
|
|
898
|
+
const bad = [];
|
|
899
|
+
for await (const page of (0, pass_js_1.pages)(() => (0, pass_js_1.scopeToTenant)(new node_1.default.Query(index_js_1.Service_Schedule_Execution), tenantId), batchSize)) {
|
|
900
|
+
for (const execution of page) {
|
|
901
|
+
if (!execution.id || !migrated.has(execution.id))
|
|
902
|
+
continue;
|
|
903
|
+
const steps = (execution.get("steps") ?? []);
|
|
904
|
+
const problems = stepProblems(steps);
|
|
905
|
+
const ids = new Set(steps.map((step) => step.id ?? ""));
|
|
906
|
+
stepIds.set(execution.id, ids);
|
|
907
|
+
const results = (execution.get("stepResults") ?? []);
|
|
908
|
+
for (const result of results) {
|
|
909
|
+
if (!ids.has(result.stepId ?? "")) {
|
|
910
|
+
problems.push(`result for unknown step ${result.stepId}`);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (problems.length && bad.length < 10) {
|
|
914
|
+
bad.push(`${execution.id}: ${problems.join(", ")}`);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Meta_Entry)
|
|
919
|
+
.startsWith("context", schedule_js_1.STEP_META_PREFIX)
|
|
920
|
+
.equalTo("entryClassName", index_js_1.Service_Schedule_Execution.className), batchSize)) {
|
|
921
|
+
for (const row of page) {
|
|
922
|
+
const ids = stepIds.get(row.get("entryObjectId") ?? "");
|
|
923
|
+
if (!ids)
|
|
924
|
+
continue; // not a migrated execution, or outside --tenant
|
|
925
|
+
const stepId = (0, schedule_js_1.stepIdOfContext)(row.get("context") ?? "");
|
|
926
|
+
if ((!stepId || !ids.has(stepId)) && bad.length < 10) {
|
|
927
|
+
bad.push(`values ${row.id} name step ${stepId}, which execution ` +
|
|
928
|
+
`${row.get("entryObjectId")} does not have`);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return bad.length ? `e.g. ${bad.join("; ")}` : undefined;
|
|
933
|
+
},
|
|
934
|
+
},
|
|
935
|
+
{
|
|
936
|
+
name: "no Outlook event is linked to two v2 plans",
|
|
937
|
+
hard: true,
|
|
938
|
+
async run(_tenantId, batchSize) {
|
|
939
|
+
// Two plans on one event means every edit of either rewrites the same
|
|
940
|
+
// appointment, and the v2 poller cannot tell which plan an Outlook change
|
|
941
|
+
// is for.
|
|
942
|
+
const plansByEvent = new Map();
|
|
943
|
+
for await (const page of (0, pass_js_1.pages)(() => new node_1.default.Query(index_js_1.Meta_Entry)
|
|
944
|
+
.equalTo("context", serviceCalendarMeta_js_1.SERVICE_CALENDAR_SYNC_CONTEXT)
|
|
945
|
+
.equalTo("entryClassName", index_js_1.Service_Schedule.className), batchSize)) {
|
|
946
|
+
for (const row of page) {
|
|
947
|
+
const eventId = row.get("values")?.microsoftCalendarEventId;
|
|
948
|
+
if (!eventId)
|
|
949
|
+
continue;
|
|
950
|
+
const plans = plansByEvent.get(eventId) ?? new Set();
|
|
951
|
+
plans.add(row.get("entryObjectId") ?? "");
|
|
952
|
+
plansByEvent.set(eventId, plans);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
const doubled = [...plansByEvent].filter(([, plans]) => plans.size > 1);
|
|
956
|
+
return doubled.length
|
|
957
|
+
? `e.g. ${doubled
|
|
958
|
+
.slice(0, 5)
|
|
959
|
+
.map(([event, plans]) => `${event} → ${[...plans].join(", ")}`)
|
|
960
|
+
.join("; ")}`
|
|
961
|
+
: undefined;
|
|
962
|
+
},
|
|
963
|
+
},
|
|
526
964
|
// ── Soft: distribution sanity ────────────────────────────────────────────
|
|
527
965
|
{
|
|
528
966
|
name: "ticket status distribution looks plausible",
|
|
@@ -37,5 +37,7 @@
|
|
|
37
37
|
* - an assignment batch (three rows, one `batchStamp`)
|
|
38
38
|
* - a message referencing a non-ticket object (orphan skip)
|
|
39
39
|
* - assets on a real and on a `temp-` media context
|
|
40
|
+
* - maintenance plans, templates and executions in every v1 shape — see
|
|
41
|
+
* `seedSchedules`
|
|
40
42
|
*/
|
|
41
43
|
export {};
|