initial commit

This commit is contained in:
ray
2026-07-12 10:01:39 -04:00
commit fc8290d668
185 changed files with 38831 additions and 0 deletions
@@ -0,0 +1,61 @@
/// <reference path="../pb_data/types.d.ts" />
//
// M2 — Add integer-minutes `estimatedDuration` column to `repairOrders`.
//
// Today the duration is stored as `estimatedTime` (a HOURS STRING such as
// "0.3"), converted back to minutes via Math.round(hours*60) on read. That
// round-trip is lossy: 15 min → "0.3" → 18 min, drifting the due time every
// reload. This migration adds a numeric `estimatedDuration` (integer minutes)
// column and backfills it from `estimatedTime`.
//
// The frontend still writes BOTH columns after this migration (for backward
// compat with older clients), but reads prefer `estimatedDuration` when
// present. A follow-up cleanup can drop the `estimatedTime` writes once all
// clients are upgraded.
//
migrate(
(db) => {
const col = db.findCollectionByNameOrId('repairOrders');
if (!col) {
console.warn('[M2] repairOrders collection not found — skipping');
return;
}
if (!col.fields.find((f) => f.name === 'estimatedDuration')) {
const field = new NumberField({
name: 'estimatedDuration',
required: false,
min: 0,
});
col.fields.push(field);
db.save(col);
console.log('[M2] added estimatedDuration field');
}
const records = Array.from(db.findRecordsByFilter(
"repairOrders",
"1=1",
"id",
500
));
let backfilled = 0;
for (const rec of records) {
if (rec.get('estimatedDuration') != null) continue; // don't overwrite
const raw = rec.get('estimatedTime');
const hours = parseFloat(String(raw || '0')) || 0;
rec.set('estimatedDuration', Math.round(hours * 60));
db.saveRecord(rec);
backfilled++;
}
console.log(`[M2] backfilled ${backfilled} records`);
},
(db) => {
const col = db.findCollectionByNameOrId('repairOrders');
if (!col) return;
const idx = col.fields.findIndex((f) => f.name === 'estimatedDuration');
if (idx >= 0) {
col.fields.splice(idx, 1);
db.save(col);
}
}
);