mirror of https://github.com/TryGhost/Ghost.git
🎨 Added Koenig Demo Post (#9747)
no issue - add a new migration for 1.25 to insert the draft demo post for existing blogs - ensure new blogs get the draft demo post as well - tested on sqlite3 + mysql - added handling if Ghost Author user doesn't exist anymore (fallback to owner user)
This commit is contained in:
parent
14d9a04fb0
commit
76b9a49eb8
|
@ -9,7 +9,8 @@ module.exports.config = {
|
|||
|
||||
module.exports.up = function insertFixtures(options) {
|
||||
var localOptions = _.merge({
|
||||
context: {internal: true}
|
||||
context: {internal: true},
|
||||
migrating: true
|
||||
}, options);
|
||||
|
||||
return Promise.mapSeries(fixtures.models, function (model) {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
const _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const common = require('../../../../lib/common');
|
||||
const converters = require('../../../../lib/mobiledoc/converters');
|
||||
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
|
||||
|
@ -19,6 +22,10 @@ const mobiledocIsCompatibleWithV1 = function mobiledocIsCompatibleWithV1(doc) {
|
|||
return false;
|
||||
};
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
||||
module.exports.up = function regenerateKoenigBetaHTML(options) {
|
||||
let postAllColumns = ['id', 'html', 'mobiledoc'];
|
||||
|
||||
|
@ -26,7 +33,7 @@ module.exports.up = function regenerateKoenigBetaHTML(options) {
|
|||
context: {internal: true}
|
||||
}, options);
|
||||
|
||||
common.logging.info('Migrating Koenig beta post\'s mobiledoc/HTML to 2.0 format');
|
||||
common.logging.info(message1);
|
||||
|
||||
return models.Post.findAll(_.merge({columns: postAllColumns}, localOptions))
|
||||
.then(function (posts) {
|
||||
|
@ -55,5 +62,8 @@ module.exports.up = function regenerateKoenigBetaHTML(options) {
|
|||
}, _.merge({id: post.id}, localOptions));
|
||||
}
|
||||
}, {concurrency: 100});
|
||||
})
|
||||
.then(() => {
|
||||
common.logging.info(message2);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
const _ = require('lodash');
|
||||
const common = require('../../../../lib/common');
|
||||
const models = require('../../../../models');
|
||||
const fixtures = require('../../../../data/schema/fixtures');
|
||||
const message1 = 'Adding demo post.';
|
||||
const message2 = 'Added demo post.';
|
||||
const message3 = 'Skipped: Adding demo post. Slug already in use.';
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
||||
module.exports.up = (options) => {
|
||||
let localOptions = _.merge({
|
||||
context: {internal: true},
|
||||
columns: ['id']
|
||||
}, options);
|
||||
|
||||
let userId;
|
||||
|
||||
common.logging.info(message1);
|
||||
|
||||
const demoPost = _.cloneDeep(fixtures.models[5].entries[0]);
|
||||
|
||||
return models.Post.findOne({slug: demoPost.slug, status: 'all'}, localOptions)
|
||||
.then((model) => {
|
||||
if (model) {
|
||||
common.logging.warn(message3);
|
||||
return;
|
||||
}
|
||||
|
||||
return models.User.findOne({id: fixtures.models[4].entries[1].id}, localOptions)
|
||||
.then((ghostAuthor) => {
|
||||
if (ghostAuthor) {
|
||||
userId = ghostAuthor.id;
|
||||
return;
|
||||
}
|
||||
|
||||
return models.User.getOwnerUser(localOptions);
|
||||
})
|
||||
.then((ownerUser) => {
|
||||
if (!userId) {
|
||||
userId = ownerUser.id;
|
||||
}
|
||||
|
||||
demoPost.created_by = userId;
|
||||
demoPost.author_id = userId;
|
||||
|
||||
return models.Post.add(demoPost, localOptions);
|
||||
})
|
||||
.then(() => {
|
||||
common.logging.info(message2);
|
||||
});
|
||||
});
|
||||
};
|
File diff suppressed because one or more lines are too long
|
@ -98,7 +98,7 @@ fetchRelationData = function fetchRelationData(relation, options) {
|
|||
* @param {{name, entries}} modelFixture
|
||||
* @returns {Promise.<*>}
|
||||
*/
|
||||
addFixturesForModel = function addFixturesForModel(modelFixture, options) {
|
||||
addFixturesForModel = function addFixturesForModel(modelFixture, options = {}) {
|
||||
// Clone the fixtures as they get changed in this function.
|
||||
// The initial blog posts will be added a `published_at` property, which
|
||||
// would change the fixturesHash.
|
||||
|
@ -115,8 +115,22 @@ addFixturesForModel = function addFixturesForModel(modelFixture, options) {
|
|||
}
|
||||
|
||||
return Promise.mapSeries(modelFixture.entries, function (entry) {
|
||||
let data = {};
|
||||
|
||||
// CASE: if id is specified, only query by id
|
||||
return models[modelFixture.name].findOne(entry.id ? {id: entry.id} : entry, options).then(function (found) {
|
||||
if (entry.id) {
|
||||
data.id = entry.id;
|
||||
} else if (entry.slug) {
|
||||
data.slug = entry.slug;
|
||||
} else {
|
||||
data = _.cloneDeep(entry);
|
||||
}
|
||||
|
||||
if (modelFixture.name === 'Post') {
|
||||
data.status = 'all';
|
||||
}
|
||||
|
||||
return models[modelFixture.name].findOne(data, options).then(function (found) {
|
||||
if (!found) {
|
||||
return models[modelFixture.name].add(entry, options);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ ghostBookshelf.plugin(plugins.collision);
|
|||
|
||||
// Manages nested updates (relationships)
|
||||
ghostBookshelf.plugin('bookshelf-relations', {
|
||||
allowedOptions: ['context', 'importing'],
|
||||
allowedOptions: ['context', 'importing', 'migrating'],
|
||||
unsetRelations: true,
|
||||
hooks: {
|
||||
belongsToMany: {
|
||||
|
@ -124,10 +124,10 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
|||
if (!model.ghostEvents) {
|
||||
model.ghostEvents = [];
|
||||
|
||||
// CASE: when importing or deleting content, lot's of model queries are happening in one transaction
|
||||
// CASE: when importing, deleting or migrating content, lot's of model queries are happening in one transaction
|
||||
// lot's of model events will be triggered. we ensure we set the max listeners to infinity.
|
||||
// we are using `once` - we auto remove the listener afterwards
|
||||
if (options.importing || options.destroyAll) {
|
||||
if (options.importing || options.destroyAll || options.migrating) {
|
||||
options.transacting.setMaxListeners(0);
|
||||
}
|
||||
|
||||
|
@ -501,7 +501,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
|||
}
|
||||
|
||||
// terms to whitelist for all methods.
|
||||
return ['context', 'withRelated', 'transacting', 'importing', 'forUpdate'];
|
||||
return ['context', 'withRelated', 'transacting', 'importing', 'forUpdate', 'migrating'];
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -327,7 +327,7 @@ Post = ghostBookshelf.Model.extend({
|
|||
} else {
|
||||
// In any other case (except import), `published_by` should not be changed
|
||||
if (this.hasChanged('published_by') && !options.importing) {
|
||||
this.set('published_by', this.previous('published_by'));
|
||||
this.set('published_by', this.previous('published_by') || null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -291,7 +291,7 @@ describe('Post API', function () {
|
|||
var jsonResponse = res.body;
|
||||
should.exist(jsonResponse.posts);
|
||||
testUtils.API.checkResponse(jsonResponse, 'posts');
|
||||
jsonResponse.posts.should.have.length(1);
|
||||
jsonResponse.posts.should.have.length(2);
|
||||
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
|
||||
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
||||
done();
|
||||
|
|
|
@ -106,11 +106,11 @@ describe('Migration Fixture Utils', function () {
|
|||
fixtureUtils.addFixturesForModel(fixtures.models[5]).then(function (result) {
|
||||
should.exist(result);
|
||||
result.should.be.an.Object();
|
||||
result.should.have.property('expected', 7);
|
||||
result.should.have.property('done', 7);
|
||||
result.should.have.property('expected', 8);
|
||||
result.should.have.property('done', 8);
|
||||
|
||||
postOneStub.callCount.should.eql(7);
|
||||
postAddStub.callCount.should.eql(7);
|
||||
postOneStub.callCount.should.eql(8);
|
||||
postAddStub.callCount.should.eql(8);
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
|
@ -123,10 +123,10 @@ describe('Migration Fixture Utils', function () {
|
|||
fixtureUtils.addFixturesForModel(fixtures.models[5]).then(function (result) {
|
||||
should.exist(result);
|
||||
result.should.be.an.Object();
|
||||
result.should.have.property('expected', 7);
|
||||
result.should.have.property('expected', 8);
|
||||
result.should.have.property('done', 0);
|
||||
|
||||
postOneStub.callCount.should.eql(7);
|
||||
postOneStub.callCount.should.eql(8);
|
||||
postAddStub.callCount.should.eql(0);
|
||||
|
||||
done();
|
||||
|
|
|
@ -20,7 +20,7 @@ var should = require('should'),
|
|||
describe('DB version integrity', function () {
|
||||
// Only these variables should need updating
|
||||
var currentSchemaHash = '2073bee126f6e419ef86196f719caea6',
|
||||
currentFixturesHash = 'a7633cca0c3f73e2358aac8bb56c08db';
|
||||
currentFixturesHash = 'e4e64e97d509c61df818bf4d8e46c4c2';
|
||||
|
||||
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
|
||||
// and the values above will need updating as confirmation
|
||||
|
|
Loading…
Reference in New Issue