Files
spq-v2/pb_migrations/1740000000010_add_customerId_to_appointments.js
2026-07-12 10:01:39 -04:00

39 lines
1.1 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
//
// M19 — Add customerId to appointments collection.
migrate(
function (db) {
var col = null;
try { col = db.findCollectionByNameOrId('appointments'); } catch (e) {}
if (!col) {
console.warn('[M19] appointments collection not found — skipping');
return;
}
for (var i = 0; i < col.fields.length; i++) {
if (col.fields[i].name === 'customerId') {
console.log('[M19] customerId already exists — skipping');
return;
}
}
col.fields.push(new TextField({ name: 'customerId', required: false }));
db.save(col);
console.log('[M19] added customerId to appointments');
},
function (db) {
var col = null;
try { col = db.findCollectionByNameOrId('appointments'); } catch (e) {}
if (!col) return;
for (var i = 0; i < col.fields.length; i++) {
if (col.fields[i].name === 'customerId') {
col.fields.splice(i, 1);
db.save(col);
console.log('[M19] removed customerId from appointments');
return;
}
}
}
);