0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🎨 Changed fixture data and default settings (#9778)

closes #9774, refs #9742

- added new fixture posts for Ghost 2.0
- added migration file to remove old fixture posts
  - only remove them if they are owned by the Ghost author and if they are tagged with getting-started
  - added new fixture posts if you had all (!) old fixture posts
  - ensure on rollback we remove the new fixture posts again
- updated default settings
This commit is contained in:
Katharina Irrgang 2018-08-10 13:55:03 +02:00
parent ef9b116856
commit 220d0456b4
7 changed files with 170 additions and 47 deletions

View file

@ -26,6 +26,15 @@ module.exports.up = () => {
if (content.match(/globals\.permalinks/)) {
return models.Settings.findOne({key: 'permalinks'}, localOptions)
.then((model) => {
// CASE: the permalinks setting get's inserted when you first start Ghost
if (!model) {
model = {
get: () => {
return '/:slug/';
}
};
}
settingsModel = model;
// CASE: create a backup

View file

@ -0,0 +1,102 @@
const Promise = require('bluebird');
const _ = require('lodash');
const models = require('../../../../models');
const fixtures = require('../../../../data/schema/fixtures');
const common = require('../../../../lib/common');
const message1 = 'Replacing fixture posts.';
const message2 = 'Replaced fixture posts.';
const message3 = 'Rollback: Fixture posts.';
const oldFixtureSlugs = ['welcome', 'the-editor', 'using-tags', 'managing-users', 'private-sites', 'advanced-markdown', 'themes'];
const newFixtureSlugs = _.map(_.find(fixtures.models, {name: 'Post'}).entries, 'slug');
module.exports.config = {
transaction: true
};
module.exports.up = (options) => {
let localOptions = _.merge({
context: {internal: true},
columns: ['id'],
withRelated: ['authors', 'tags'],
migrating: true
}, options);
common.logging.info(message1);
let oldFixturePostsCount = 0;
return Promise.each(oldFixtureSlugs, (slug) => {
return models.Post.findOne({slug: slug, status: 'all'}, localOptions)
.then((model) => {
// CASE: fixture post doesn't exist
if (!model) {
return;
}
model = model.toJSON();
// CASE: the old fixture post is NOT owned by the ghost author, could be your own post
if (!_.find(model.authors, {slug: 'ghost'})) {
return;
}
// CASE: the old fixture post is NOT tagged with getting started
if (!_.find(model.tags, {slug: 'getting-started'})) {
return;
}
oldFixturePostsCount = oldFixturePostsCount + 1;
return models.Post.destroy(Object.assign({id: model.id}, localOptions));
});
}).then(() => {
// We only insert the new post fixtures if you had ALL old fixure posts in the database
if (oldFixturePostsCount !== 7) {
return;
}
const newPostFixtures = fixtures.utils.findModelFixtures('Post');
const newPostRelationFixtures = fixtures.utils.findRelationFixture('Post', 'Tag');
return fixtures.utils.addFixturesForModel(newPostFixtures, _.omit(localOptions, ['withRelated', 'columns']))
.then(() => {
return fixtures.utils.addFixturesForRelation(newPostRelationFixtures, _.omit(localOptions, ['withRelated', 'columns']));
});
}).then(() => {
common.logging.info(message2);
});
};
module.exports.down = (options) => {
let localOptions = _.merge({
context: {internal: true},
columns: ['id'],
withRelated: ['authors', 'tags'],
migrating: true
}, options);
common.logging.info(message3);
return Promise.each(newFixtureSlugs, (slug) => {
return models.Post.findOne({slug: slug, status: 'all'}, localOptions)
.then((model) => {
// CASE: fixture post doesn't exist
if (!model) {
return;
}
model = model.toJSON();
// CASE: the old fixture post is NOT owned by the ghost author, could be your own post
if (!_.find(model.authors, {slug: 'ghost'})) {
return;
}
// CASE: the old fixture post is NOT tagged with getting started
if (!_.find(model.tags, {slug: 'getting-started'})) {
return;
}
return models.Post.destroy(Object.assign({id: model.id}, localOptions));
});
});
};

View file

@ -74,16 +74,16 @@
"defaultValue" : ""
},
"facebook": {
"defaultValue" : ""
"defaultValue" : "ghost"
},
"twitter": {
"defaultValue" : ""
"defaultValue" : "tryghost"
},
"labs": {
"defaultValue": "{\"publicAPI\": true}"
},
"navigation": {
"defaultValue": "[{\"label\":\"Home\", \"url\":\"/\"}]"
"defaultValue": "[{\"label\":\"Home\", \"url\":\"/\"},{\"label\":\"Tag\", \"url\":\"/tag/getting-started/\"}, {\"label\":\"Author\", \"url\":\"/author/ghost/\"},{\"label\":\"Help\", \"url\":\"https://help.ghost.org\"}]"
},
"slack": {
"defaultValue": "[{\"url\":\"\"}]"

File diff suppressed because one or more lines are too long

View file

@ -534,7 +534,7 @@ describe('Public API', function () {
var post = res.body.posts[0],
publishedAt = moment(post.published_at).format('YYYY-MM-DD HH:mm:ss');
post.title.should.eql('Using the Ghost editor');
post.title.should.eql('Writing posts with Ghost ✍️');
return request
.get(testUtils.API.getApiQuery(

View file

@ -188,7 +188,7 @@ describe('Database Migration (special functions)', function () {
// Post
should.exist(result.posts);
result.posts.length.should.eql(7);
result.posts.at(0).get('title').should.eql('Setting up your own Ghost theme');
result.posts.at(0).get('title').should.eql('Creating a custom theme');
// Tag
should.exist(result.tags);

View file

@ -20,7 +20,7 @@ var should = require('should'),
describe('DB version integrity', function () {
// Only these variables should need updating
var currentSchemaHash = '22d24b1de23d118b90e9547fefae5ad7',
currentFixturesHash = '13417e5bd47bcadd5b806de028fdd7dc';
currentFixturesHash = '9acae8a4762c3bc2ee8171198f3fc9a1';
// 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