/// // 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 }, { 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')) })