Files
blog/pocketbase/pb_migrations/1757500001_create_articles.js
T
davide 847edc7397 Cap articles.content at 10000 characters, with coverage
PocketBase silently enforced its own default max on unbounded text
fields, which broke saving a real production article longer than that.
Make the limit explicit and generous enough for the content this blog
actually publishes, and add a test asserting the exact boundary.
2026-09-11 13:53:17 +02:00

46 lines
1.8 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
// publishedAt mirrors Strapi's Draft & Publish semantics: empty = draft, set
// (and not in the future) = published. listRule/viewRule enforce this, so an
// unpublished or scheduled article is invisible to the public API by
// construction, not by a check in application code.
migrate((app) => {
const categories = app.findCollectionByNameOrId('categories')
const collection = new Collection({
type: 'base',
name: 'articles',
listRule: "publishedAt != '' && publishedAt <= @now",
viewRule: "publishedAt != '' && publishedAt <= @now",
createRule: null,
updateRule: null,
deleteRule: null,
fields: [
{ type: 'text', name: 'title', required: true, max: 160 },
{ type: 'text', name: 'slug', required: true, max: 160, pattern: '^[a-z0-9]+(-[a-z0-9]+)*$' },
{ type: 'text', name: 'content', required: true, max: 10000 },
{
type: 'file',
name: 'cover',
maxSelect: 1,
maxSize: 10485760,
mimeTypes: ['image/png', 'image/jpeg', 'image/webp', 'image/avif', 'image/gif'],
},
{ type: 'text', name: 'coverAlt', max: 200 },
{ type: 'relation', name: 'category', collectionId: categories.id, maxSelect: 1 },
{ type: 'date', name: 'publishedAt' },
{ type: 'text', name: 'authorName', max: 160 },
{ type: 'autodate', name: 'created', onCreate: true },
{ type: 'autodate', name: 'updated', onCreate: true, onUpdate: true },
],
indexes: [
'CREATE UNIQUE INDEX idx_articles_slug ON articles (slug)',
'CREATE INDEX idx_articles_category ON articles (category)',
'CREATE INDEX idx_articles_published ON articles (publishedAt)',
],
})
app.save(collection)
}, (app) => {
app.delete(app.findCollectionByNameOrId('articles'))
})