Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed fixture data and default settings #9778

Merged
merged 1 commit into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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