mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added validation to posts status column
refs https://github.com/TryGhost/Toolbox/issues/309
- this commit adds `isIn` validation to the `status` column on the
`posts` table, with values pulled from the model: c0d82122b0/core/server/models/post.js (L28)
- this also adds a migration to update any posts with invalid statuses
to `draft`
This commit is contained in:
parent
ca82914052
commit
66652b6ea9
2 changed files with 16 additions and 2 deletions
|
@ -0,0 +1,15 @@
|
|||
const logging = require('@tryghost/logging');
|
||||
const {createTransactionalMigration} = require('../../utils');
|
||||
|
||||
module.exports = createTransactionalMigration(
|
||||
async function up(knex) {
|
||||
const affectedRows = await knex('posts')
|
||||
.update('status', 'draft')
|
||||
.whereNotIn('status', ['published', 'draft', 'scheduled', 'sent']);
|
||||
|
||||
logging.info(`Updated ${affectedRows} posts with invalid statuses to 'draft'`);
|
||||
},
|
||||
async function down() {
|
||||
// no-op: we don't want to set posts back to invalid statuses
|
||||
}
|
||||
);
|
|
@ -51,8 +51,7 @@ module.exports = {
|
|||
feature_image: {type: 'string', maxlength: 2000, nullable: true},
|
||||
featured: {type: 'bool', nullable: false, defaultTo: false},
|
||||
type: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'post', validations: {isIn: [['post', 'page']]}},
|
||||
// @TODO: add isIn validation here to control for all possible status values (published, draft, scheduled, sent)
|
||||
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'draft'},
|
||||
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'draft', validations: {isIn: [['published', 'draft', 'scheduled', 'sent']]}},
|
||||
// NOTE: unused at the moment and reserved for future features
|
||||
locale: {type: 'string', maxlength: 6, nullable: true},
|
||||
visibility: {
|
||||
|
|
Loading…
Add table
Reference in a new issue