41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
/// <reference path="../pb_data/types.d.ts" />
|
|
//
|
|
// M9 — Rename legacy repair order status `delivered` to `final_close`.
|
|
//
|
|
// The frontend now uses `final_close` as the canonical terminal post-completion
|
|
// status. This migration updates existing repair orders so historical data and
|
|
// new UI filters/counts stay aligned.
|
|
//
|
|
|
|
migrate(
|
|
(db) => {
|
|
const col = db.findCollectionByNameOrId('repairOrders');
|
|
if (!col) {
|
|
console.warn('[M9] repairOrders collection not found — skipping');
|
|
return;
|
|
}
|
|
|
|
const records = Array.from(db.findRecordsByFilter('repairOrders', "status = 'delivered'", 'id', 1000));
|
|
let updated = 0;
|
|
for (const rec of records) {
|
|
rec.set('status', 'final_close');
|
|
db.saveRecord(rec);
|
|
updated++;
|
|
}
|
|
console.log(`[M9] renamed ${updated} repair order(s) to final_close`);
|
|
},
|
|
(db) => {
|
|
const col = db.findCollectionByNameOrId('repairOrders');
|
|
if (!col) return;
|
|
|
|
const records = Array.from(db.findRecordsByFilter('repairOrders', "status = 'final_close'", 'id', 1000));
|
|
let reverted = 0;
|
|
for (const rec of records) {
|
|
rec.set('status', 'delivered');
|
|
db.saveRecord(rec);
|
|
reverted++;
|
|
}
|
|
console.log(`[M9] reverted ${reverted} repair order(s) to delivered`);
|
|
}
|
|
);
|