Files
spq-v2/pb_migrations/1739999000008_quote_viewed_at.js
T
2026-07-12 10:01:39 -04:00

32 lines
973 B
JavaScript

/// <reference path="../pb_data/types.d.ts" />
//
// M8 — Quote Viewed-At Timestamp.
//
// Adds a `viewedAt` text field to the `quotes` collection so the front-end
// can record the first time a customer opens the public approval link.
//
migrate(
(db) => {
const quotes = db.findCollectionByNameOrId('quotes');
if (!quotes) {
console.warn('[M8] quotes collection not found — skipping');
return;
}
if (!quotes.fields.find((f) => f.name === 'viewedAt')) {
quotes.fields.push(new TextField({ name: 'viewedAt', required: false }));
console.log('[M8] added viewedAt field to quotes');
}
db.save(quotes);
},
(db) => {
const quotes = db.findCollectionByNameOrId('quotes');
if (!quotes) return;
const idx = quotes.fields.findIndex((f) => f.name === 'viewedAt');
if (idx >= 0) {
quotes.fields.splice(idx, 1);
db.save(quotes);
console.log('[M8] removed viewedAt from quotes');
}
}
);