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

46 lines
1.5 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
// M22 — Add logo file field to settings collection.
//
// Currently the shop logo is stored as a base64 data-URL inside the `data`
// JSON blob. This migration adds a proper `logo` file field so logos are
// stored as PB file records instead, eliminating bloated localStorage and
// PB round-trips.
//
// The frontend continues to cache a base64 version in localStorage for
// backward compatibility with PDF generation (jsPDF addImage expects
// data URLs or Image objects). The PB file field is the canonical store.
//
// Migration is a no-op if the field already exists (idempotent).
migrate(
(app) => {
const col = app.findCollectionByNameOrId('settings');
if (!col) {
console.log('[M22] settings collection not found — skipping');
return;
}
if (col.fields.find(f => f.name === 'logo')) {
console.log('[M22] logo field already exists — skipping');
return;
}
col.fields.add(new FileField({
name: 'logo',
required: false,
maxSize: 5242880,
allowedMimeTypes: ['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml'],
}));
app.save(col);
console.log('[M22] added logo file field to settings collection');
},
(app) => {
const col = app.findCollectionByNameOrId('settings');
if (!col) return;
const field = col.fields.find(f => f.name === 'logo');
if (field) {
col.fields.remove(field);
app.save(col);
console.log('[M22] removed logo file field from settings collection');
}
}
);