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

Merge pull request #5799 from ErisDS/improve-migrations

Use sequence for migrations instead of Promise.all
This commit is contained in:
Sebastian Gierlinger 2015-09-03 13:20:39 +02:00
commit 7b3d60b727

View file

@ -178,7 +178,8 @@ to004 = function to004() {
logInfo('Upgrading fixtures to 004');
// add jquery setting and privacy info
upgradeOp = models.Settings.findOne('ghost_foot').then(function (setting) {
upgradeOp = function () {
return models.Settings.findOne('ghost_foot').then(function (setting) {
if (setting) {
value = setting.attributes.value;
// Only add jQuery if it's not already in there
@ -198,31 +199,37 @@ to004 = function to004() {
}
}
});
};
ops.push(upgradeOp);
// change `type` for protected blog `isPrivate` setting
upgradeOp = models.Settings.findOne('isPrivate').then(function (setting) {
upgradeOp = function () {
return models.Settings.findOne('isPrivate').then(function (setting) {
if (setting) {
logInfo('Update isPrivate setting');
return models.Settings.edit({key: 'isPrivate', type: 'private'}, options);
}
return Promise.resolve();
});
};
ops.push(upgradeOp);
// change `type` for protected blog `password` setting
upgradeOp = models.Settings.findOne('password').then(function (setting) {
upgradeOp = function () {
return models.Settings.findOne('password').then(function (setting) {
if (setting) {
logInfo('Update password setting');
return models.Settings.edit({key: 'password', type: 'private'}, options);
}
return Promise.resolve();
});
};
ops.push(upgradeOp);
// Update ghost-admin client fixture
// ghost-admin should exist from 003 version
upgradeOp = models.Client.findOne({slug: fixtures.clients[0].slug}).then(function (client) {
upgradeOp = function () {
return models.Client.findOne({slug: fixtures.clients[0].slug}).then(function (client) {
if (client) {
logInfo('Update ghost-admin client fixture');
var adminClient = fixtures.clients[0];
@ -231,10 +238,12 @@ to004 = function to004() {
}
return Promise.resolve();
});
};
ops.push(upgradeOp);
// add ghost-frontend client if missing
upgradeOp = models.Client.findOne({slug: fixtures.clients[1].slug}).then(function (client) {
upgradeOp = function () {
return models.Client.findOne({slug: fixtures.clients[1].slug}).then(function (client) {
if (!client) {
logInfo('Add ghost-frontend client fixture');
var frontendClient = fixtures.clients[1];
@ -243,10 +252,12 @@ to004 = function to004() {
}
return Promise.resolve();
});
};
ops.push(upgradeOp);
// clean up broken tags
upgradeOp = models.Tag.findAll(options).then(function (tags) {
upgradeOp = function () {
return models.Tag.findAll(options).then(function (tags) {
var tagOps = [];
if (tags) {
tags.each(function (tag) {
@ -267,10 +278,12 @@ to004 = function to004() {
}
return Promise.resolve();
});
};
ops.push(upgradeOp);
// Add post_tag order
upgradeOp = models.Post.findAll(_.extend({}, options, {withRelated: ['tags']})).then(function (posts) {
upgradeOp = function () {
return models.Post.findAll(_.extend({}, options, {withRelated: ['tags']})).then(function (posts) {
var tagOps = [];
if (posts) {
posts.each(function (post) {
@ -288,10 +301,12 @@ to004 = function to004() {
return Promise.all(tagOps);
}
});
};
ops.push(upgradeOp);
// Add a new draft post
upgradeOp = models.Post.findOne({slug: fixtures.posts_0_7[0].slug, status: 'all'}, options).then(function (post) {
upgradeOp = function () {
return models.Post.findOne({slug: fixtures.posts_0_7[0].slug, status: 'all'}, options).then(function (post) {
if (!post) {
logInfo('Adding 0.7 upgrade post fixture');
// Set the published_at timestamp, but keep the post as a draft so doesn't appear on the frontend
@ -301,9 +316,10 @@ to004 = function to004() {
return models.Post.add(fixtures.posts_0_7[0], options);
}
});
};
ops.push(upgradeOp);
return Promise.all(ops);
return sequence(ops);
};
update = function update(fromVersion, toVersion) {