Schema: explicit size limits on JSON fields
pb_schema.json had six JSON field limits under `options.maxSize`, which PocketBase ignores since 0.23, so those fields used PocketBase's default. That default dropped to 1MB in 0.29: on 0.40 a 1.5MB page that 0.23 saved is refused. Move the limits to the field's top level and add a migration that sets them on existing installs (pages/email blocks 2MB, globals 1MB, event categories 200KB, customer details 100KB). Tested on 0.40.6: existing install (migration applied, 1.5MB page saves, 2.5MB refused at 2MB) and fresh install + pb_schema.json import; both end with identical schemas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HA82gX7xH4zwYTr5vE7mf8
This commit is contained in:
parent
5b92cae225
commit
dc8c58f4c2
2 changed files with 53 additions and 12 deletions
47
pocketbase/pb_migrations/1793400000_json_field_limits.js
Normal file
47
pocketbase/pb_migrations/1793400000_json_field_limits.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/// <reference path="../pb_data/types.d.ts" />
|
||||
|
||||
// Give every JSON field an explicit size limit.
|
||||
//
|
||||
// pb_schema.json used to put these limits under `options.maxSize`, which
|
||||
// PocketBase has ignored since 0.23, so the fields below had no limit of
|
||||
// their own and fell back to PocketBase's default. That default dropped from
|
||||
// several MB to 1MB in PocketBase 0.29: a page's blocks over 1MB that saved
|
||||
// on 0.23 are refused on 0.40 ("The maximum allowed JSON size is 1048576
|
||||
// bytes"). Real pages are far smaller (the largest in the backups is ~17KB),
|
||||
// but the limit should be the one we chose, not whatever the default is.
|
||||
//
|
||||
// Only the limit changes; nothing is rewritten. A limit is checked when a
|
||||
// record is saved, so existing data is not affected.
|
||||
|
||||
const LIMITS = [
|
||||
['pages', 'blocks', 2000000],
|
||||
['email_templates', 'blocks', 2000000],
|
||||
['globals', 'data', 1000000],
|
||||
['events', 'categories', 200000],
|
||||
['baskets', 'customerDetails', 100000],
|
||||
['orders', 'customerDetails', 100000]
|
||||
];
|
||||
|
||||
function setLimits(app, size) {
|
||||
for (const [name, fieldName, limit] of LIMITS) {
|
||||
let collection;
|
||||
try {
|
||||
collection = app.findCollectionByNameOrId(name);
|
||||
} catch (e) {
|
||||
continue; // fresh install: pb_schema.json (already with these limits) is imported later
|
||||
}
|
||||
const field = collection.fields.getByName(fieldName);
|
||||
if (!field || field.type() !== 'json') continue;
|
||||
field.maxSize = size === undefined ? limit : size;
|
||||
try {
|
||||
app.save(collection);
|
||||
} catch (e) {
|
||||
console.log(`[migration] could not set the size limit on ${name}.${fieldName}: ${e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
migrate(
|
||||
(app) => setLimits(app),
|
||||
(app) => setLimits(app, 0)
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue