Skip to content

Commit

Permalink
Changed fixture data and default settings (#9778)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kirrg001 committed Aug 10, 2018
1 parent ca201f3 commit a7106b6
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
102 changes: 102 additions & 0 deletions core/server/data/migrations/versions/2.0/6-replace-fixture-posts.js
Original file line number Diff line number Diff line change
@@ -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));
});
});
};
6 changes: 3 additions & 3 deletions core/server/data/schema/default-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\":\"\"}]"
Expand Down
Loading

0 comments on commit a7106b6

Please sign in to comment.