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:
agent 2026-11-03 09:43:49 +00:00
parent 5b92cae225
commit dc8c58f4c2
2 changed files with 53 additions and 12 deletions

View file

@ -47,9 +47,7 @@
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSize": 2000000
}
"maxSize": 2000000
},
{
"id": "bool_published",
@ -103,9 +101,7 @@
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSize": 1000000
}
"maxSize": 1000000
},
{"id": "autodate_created", "name": "created", "type": "autodate", "system": false, "hidden": false, "presentable": false, "onCreate": true, "onUpdate": false},
{"id": "autodate_updated", "name": "updated", "type": "autodate", "system": false, "hidden": false, "presentable": false, "onCreate": true, "onUpdate": true}
@ -279,9 +275,7 @@
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSize": 200000
}
"maxSize": 200000
},
{
"id": "bool_eventpub",
@ -388,7 +382,7 @@
{ "id": "sel_basketstat0", "name": "status", "type": "select", "system": false, "required": true, "presentable": false, "unique": false, "maxSelect": 1, "values": ["active", "completed", "abandoned"] },
{ "id": "date_basketexp0", "name": "expiresAt", "type": "date", "system": false, "required": true, "presentable": false, "unique": false, "options": { "min": "", "max": "" } },
{ "id": "text_basketemai", "name": "email", "type": "text", "system": false, "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 254, "pattern": "" } },
{ "id": "json_basketcust", "name": "customerDetails", "type": "json", "system": false, "required": false, "presentable": false, "unique": false, "options": { "maxSize": 100000 } },
{ "id": "json_basketcust", "name": "customerDetails", "type": "json", "system": false, "required": false, "presentable": false, "unique": false, "maxSize": 100000 },
{ "id": "text_basketstrip", "name": "stripePaymentIntentId", "type": "text", "system": false, "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 200, "pattern": "" } },
{ "id": "rel_basketpass01", "name": "pass", "type": "relation", "system": false, "required": false, "presentable": false, "hidden": false, "collectionId": "pbc_passes00001", "cascadeDelete": false, "minSelect": 0, "maxSelect": 1 },
{"id": "autodate_created", "name": "created", "type": "autodate", "system": false, "hidden": false, "presentable": false, "onCreate": true, "onUpdate": false},
@ -449,7 +443,7 @@
{ "id": "text3208210256", "name": "id", "type": "text", "system": true, "required": true, "presentable": false, "hidden": false, "primaryKey": true, "autogeneratePattern": "[a-z0-9]{15}", "min": 15, "max": 15, "pattern": "^[a-z0-9]+$" },
{ "id": "rel_orderbasket0", "name": "basket", "type": "relation", "system": false, "required": true, "presentable": false, "unique": false, "collectionId": "pbc_baskets0001", "cascadeDelete": false, "minSelect": 0, "maxSelect": 1, "displayFields": null },
{ "id": "text_orderemail0", "name": "email", "type": "text", "system": false, "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 254, "pattern": "" } },
{ "id": "json_ordercustde", "name": "customerDetails", "type": "json", "system": false, "required": false, "presentable": false, "unique": false, "options": { "maxSize": 100000 } },
{ "id": "json_ordercustde", "name": "customerDetails", "type": "json", "system": false, "required": false, "presentable": false, "unique": false, "maxSize": 100000 },
{ "id": "num_ordertotal01", "name": "total", "type": "number", "system": false, "required": false, "presentable": false, "unique": false, "options": { "min": 0, "max": null } },
{ "id": "sel_orderstatus0", "name": "status", "type": "select", "system": false, "required": true, "presentable": false, "unique": false, "maxSelect": 1, "values": ["pending", "paid", "refunded"] },
{ "id": "text_orderstripe0", "name": "stripePaymentIntentId", "type": "text", "system": false, "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 200, "pattern": "" } },
@ -515,7 +509,7 @@
{ "id": "text3208210256", "name": "id", "type": "text", "system": true, "required": true, "presentable": false, "hidden": false, "primaryKey": true, "autogeneratePattern": "[a-z0-9]{15}", "min": 15, "max": 15, "pattern": "^[a-z0-9]+$" },
{ "id": "text_etplkey0001", "name": "key", "type": "text", "system": false, "required": true, "presentable": true, "unique": true, "options": { "min": null, "max": 80, "pattern": "" } },
{ "id": "text_etplsubject", "name": "subject", "type": "text", "system": false, "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 300, "pattern": "" } },
{ "id": "json_etplblocks0", "name": "blocks", "type": "json", "system": false, "required": false, "presentable": false, "unique": false, "options": { "maxSize": 2000000 } },
{ "id": "json_etplblocks0", "name": "blocks", "type": "json", "system": false, "required": false, "presentable": false, "unique": false, "maxSize": 2000000 },
{ "id": "text_etplrecips0", "name": "recipients", "type": "text", "system": false, "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 500, "pattern": "" } },
{ "id": "bool_etplenabled", "name": "enabled", "type": "bool", "system": false, "required": false, "presentable": false, "unique": false, "options": {} },
{"id": "autodate_created", "name": "created", "type": "autodate", "system": false, "hidden": false, "presentable": false, "onCreate": true, "onUpdate": false},

View 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)
);