const _ = require('lodash'); const Promise = require('bluebird'); const logging = require('../../../../../shared/logging'); const mobiledocLib = require('../../../../lib/mobiledoc'); const models = require('../../../../models'); const message1 = 'Migrating Koenig beta post\'s mobiledoc/HTML to 2.0 format'; const message2 = 'Migrated Koenig beta post\'s mobiledoc/HTML to 2.0 format'; const mobiledocIsCompatibleWithV1 = function mobiledocIsCompatibleWithV1(doc) { if (doc && doc.markups.length === 0 && doc.cards.length === 1 && doc.cards[0][0].match(/(?:card-)?markdown/) && doc.sections.length === 1 && doc.sections[0].length === 2 && doc.sections[0][0] === 10 && doc.sections[0][1] === 0 ) { return true; } return false; }; module.exports.config = { transaction: true }; module.exports.up = function regenerateKoenigBetaHTML(options) { let postAllColumns = ['id', 'html', 'mobiledoc']; let localOptions = _.merge({ context: {internal: true} }, options); logging.info(message1); return models.Post.findAll(_.merge({columns: postAllColumns}, localOptions)) .then(function (posts) { return Promise.map(posts.models, function (post) { let mobiledoc = JSON.parse(post.get('mobiledoc') || null); if ( post.get('html') && post.get('html').match(/^