-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
7 changed files
with
170 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
core/server/data/migrations/versions/2.0/6-replace-fixture-posts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.