mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
🐛 Fixed migration from v1 to 2.2.1 (#9984)
closes #9983 - everything is described in the target issue - this PR fixes both problems described in the issue - TryGhost/Ghost-CLI#839 was raised to avoid this problem in the future
This commit is contained in:
parent
86e9c35c3c
commit
f8d244f060
3 changed files with 51 additions and 6 deletions
|
@ -30,7 +30,8 @@ module.exports.config = {
|
|||
module.exports.up = (options) => {
|
||||
let localOptions = _.merge({
|
||||
context: {internal: true},
|
||||
columns: ['id']
|
||||
columns: ['id'],
|
||||
migrating: true
|
||||
}, options);
|
||||
|
||||
return models.Post.findOne({slug: 'v2-demo-post', status: 'all'}, localOptions)
|
||||
|
@ -41,7 +42,18 @@ module.exports.up = (options) => {
|
|||
}
|
||||
|
||||
common.logging.info(message1);
|
||||
return models.Post.destroy(Object.assign({id: postModel.id}, localOptions));
|
||||
|
||||
// @NOTE: raw knex query, because of https://github.com/TryGhost/Ghost/issues/9983
|
||||
return options
|
||||
.transacting('posts_authors')
|
||||
.where('post_id', postModel.id)
|
||||
.del()
|
||||
.then(() => {
|
||||
return options
|
||||
.transacting('posts')
|
||||
.where('id', postModel.id)
|
||||
.del();
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
common.logging.info(message2);
|
||||
|
@ -51,7 +63,8 @@ module.exports.up = (options) => {
|
|||
module.exports.down = (options) => {
|
||||
let localOptions = _.merge({
|
||||
context: {internal: true},
|
||||
columns: ['id']
|
||||
columns: ['id'],
|
||||
migrating: true
|
||||
}, options);
|
||||
|
||||
return models.Post.findOne({slug: 'v2-demo-post', status: 'all'}, localOptions)
|
||||
|
|
|
@ -108,7 +108,23 @@ module.exports.up = (options) => {
|
|||
publishedAt = model.published_at;
|
||||
|
||||
// destroy the old published fixture post
|
||||
return models.Post.destroy(Object.assign({id: model.id}, localOptions));
|
||||
// @NOTE: raw knex query, because of https://github.com/TryGhost/Ghost/issues/9983
|
||||
return options
|
||||
.transacting('posts_authors')
|
||||
.where('post_id', model.id)
|
||||
.del()
|
||||
.then(() => {
|
||||
return options
|
||||
.transacting('posts_tags')
|
||||
.where('post_id', model.id)
|
||||
.del();
|
||||
})
|
||||
.then(() => {
|
||||
return options
|
||||
.transacting('posts')
|
||||
.where('id', model.id)
|
||||
.del();
|
||||
});
|
||||
});
|
||||
}).then(() => {
|
||||
// CASE: We only insert the new post fixtures if you had all old fixture posts in the database and they were published
|
||||
|
@ -181,7 +197,23 @@ module.exports.down = (options) => {
|
|||
return;
|
||||
}
|
||||
|
||||
return models.Post.destroy(Object.assign({id: model.id}, localOptions));
|
||||
// @NOTE: raw knex query, because of https://github.com/TryGhost/Ghost/issues/9983
|
||||
return options
|
||||
.connection('posts_authors')
|
||||
.where('post_id', model.id)
|
||||
.del()
|
||||
.then(() => {
|
||||
return options
|
||||
.connection('posts_tags')
|
||||
.where('post_id', model.id)
|
||||
.del();
|
||||
})
|
||||
.then(() => {
|
||||
return options
|
||||
.connection('posts')
|
||||
.where('id', model.id)
|
||||
.del();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -614,7 +614,7 @@ Post = ghostBookshelf.Model.extend({
|
|||
*/
|
||||
defaultRelations: function defaultRelations(methodName, options) {
|
||||
if (['edit', 'add'].indexOf(methodName) !== -1) {
|
||||
options.withRelated = _.union(this.prototype.relationships, options.withRelated || []);
|
||||
options.withRelated = _.union(['authors', 'tags'], options.withRelated || []);
|
||||
}
|
||||
|
||||
return options;
|
||||
|
|
Loading…
Add table
Reference in a new issue