mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Use sequence for migrations instead of Promise.all
no issue - ensures that all migrations complete before the next one begins
This commit is contained in:
parent
092330134a
commit
b422d9d32c
1 changed files with 112 additions and 96 deletions
|
@ -178,132 +178,148 @@ to004 = function to004() {
|
||||||
logInfo('Upgrading fixtures to 004');
|
logInfo('Upgrading fixtures to 004');
|
||||||
|
|
||||||
// add jquery setting and privacy info
|
// add jquery setting and privacy info
|
||||||
upgradeOp = models.Settings.findOne('ghost_foot').then(function (setting) {
|
upgradeOp = function () {
|
||||||
if (setting) {
|
return models.Settings.findOne('ghost_foot').then(function (setting) {
|
||||||
value = setting.attributes.value;
|
if (setting) {
|
||||||
// Only add jQuery if it's not already in there
|
value = setting.attributes.value;
|
||||||
if (value.indexOf(jquery.join('')) === -1) {
|
// Only add jQuery if it's not already in there
|
||||||
logInfo('Adding jQuery link to ghost_foot');
|
if (value.indexOf(jquery.join('')) === -1) {
|
||||||
value = jquery.join('') + value;
|
logInfo('Adding jQuery link to ghost_foot');
|
||||||
return models.Settings.edit({key: 'ghost_foot', value: value}, options).then(function () {
|
value = jquery.join('') + value;
|
||||||
if (_.isEmpty(config.privacy)) {
|
return models.Settings.edit({key: 'ghost_foot', value: value}, options).then(function () {
|
||||||
return Promise.resolve();
|
if (_.isEmpty(config.privacy)) {
|
||||||
}
|
return Promise.resolve();
|
||||||
logInfo(privacyMessage.join(' ').replace(/<\/?strong>/g, ''));
|
}
|
||||||
return notifications.add({notifications: [{
|
logInfo(privacyMessage.join(' ').replace(/<\/?strong>/g, ''));
|
||||||
type: 'info',
|
return notifications.add({notifications: [{
|
||||||
message: privacyMessage.join(' ')
|
type: 'info',
|
||||||
}]}, options);
|
message: privacyMessage.join(' ')
|
||||||
});
|
}]}, options);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
};
|
||||||
ops.push(upgradeOp);
|
ops.push(upgradeOp);
|
||||||
|
|
||||||
// change `type` for protected blog `isPrivate` setting
|
// change `type` for protected blog `isPrivate` setting
|
||||||
upgradeOp = models.Settings.findOne('isPrivate').then(function (setting) {
|
upgradeOp = function () {
|
||||||
if (setting) {
|
return models.Settings.findOne('isPrivate').then(function (setting) {
|
||||||
logInfo('Update isPrivate setting');
|
if (setting) {
|
||||||
return models.Settings.edit({key: 'isPrivate', type: 'private'}, options);
|
logInfo('Update isPrivate setting');
|
||||||
}
|
return models.Settings.edit({key: 'isPrivate', type: 'private'}, options);
|
||||||
return Promise.resolve();
|
}
|
||||||
});
|
return Promise.resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
ops.push(upgradeOp);
|
ops.push(upgradeOp);
|
||||||
|
|
||||||
// change `type` for protected blog `password` setting
|
// change `type` for protected blog `password` setting
|
||||||
upgradeOp = models.Settings.findOne('password').then(function (setting) {
|
upgradeOp = function () {
|
||||||
if (setting) {
|
return models.Settings.findOne('password').then(function (setting) {
|
||||||
logInfo('Update password setting');
|
if (setting) {
|
||||||
return models.Settings.edit({key: 'password', type: 'private'}, options);
|
logInfo('Update password setting');
|
||||||
}
|
return models.Settings.edit({key: 'password', type: 'private'}, options);
|
||||||
return Promise.resolve();
|
}
|
||||||
});
|
return Promise.resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
ops.push(upgradeOp);
|
ops.push(upgradeOp);
|
||||||
|
|
||||||
// Update ghost-admin client fixture
|
// Update ghost-admin client fixture
|
||||||
// ghost-admin should exist from 003 version
|
// ghost-admin should exist from 003 version
|
||||||
upgradeOp = models.Client.findOne({slug: fixtures.clients[0].slug}).then(function (client) {
|
upgradeOp = function () {
|
||||||
if (client) {
|
return models.Client.findOne({slug: fixtures.clients[0].slug}).then(function (client) {
|
||||||
logInfo('Update ghost-admin client fixture');
|
if (client) {
|
||||||
var adminClient = fixtures.clients[0];
|
logInfo('Update ghost-admin client fixture');
|
||||||
adminClient.secret = crypto.randomBytes(6).toString('hex');
|
var adminClient = fixtures.clients[0];
|
||||||
return models.Client.edit(adminClient, _.extend({}, options, {id: client.id}));
|
adminClient.secret = crypto.randomBytes(6).toString('hex');
|
||||||
}
|
return models.Client.edit(adminClient, _.extend({}, options, {id: client.id}));
|
||||||
return Promise.resolve();
|
}
|
||||||
});
|
return Promise.resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
ops.push(upgradeOp);
|
ops.push(upgradeOp);
|
||||||
|
|
||||||
// add ghost-frontend client if missing
|
// add ghost-frontend client if missing
|
||||||
upgradeOp = models.Client.findOne({slug: fixtures.clients[1].slug}).then(function (client) {
|
upgradeOp = function () {
|
||||||
if (!client) {
|
return models.Client.findOne({slug: fixtures.clients[1].slug}).then(function (client) {
|
||||||
logInfo('Add ghost-frontend client fixture');
|
if (!client) {
|
||||||
var frontendClient = fixtures.clients[1];
|
logInfo('Add ghost-frontend client fixture');
|
||||||
frontendClient.secret = crypto.randomBytes(6).toString('hex');
|
var frontendClient = fixtures.clients[1];
|
||||||
return models.Client.add(frontendClient, options);
|
frontendClient.secret = crypto.randomBytes(6).toString('hex');
|
||||||
}
|
return models.Client.add(frontendClient, options);
|
||||||
return Promise.resolve();
|
}
|
||||||
});
|
return Promise.resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
ops.push(upgradeOp);
|
ops.push(upgradeOp);
|
||||||
|
|
||||||
// clean up broken tags
|
// clean up broken tags
|
||||||
upgradeOp = models.Tag.findAll(options).then(function (tags) {
|
upgradeOp = function () {
|
||||||
var tagOps = [];
|
return models.Tag.findAll(options).then(function (tags) {
|
||||||
if (tags) {
|
var tagOps = [];
|
||||||
tags.each(function (tag) {
|
if (tags) {
|
||||||
var name = tag.get('name'),
|
tags.each(function (tag) {
|
||||||
updated = name.replace(/^(,+)/, '').trim();
|
var name = tag.get('name'),
|
||||||
|
updated = name.replace(/^(,+)/, '').trim();
|
||||||
|
|
||||||
// If we've ended up with an empty string, default to just 'tag'
|
// If we've ended up with an empty string, default to just 'tag'
|
||||||
updated = updated === '' ? 'tag' : updated;
|
updated = updated === '' ? 'tag' : updated;
|
||||||
|
|
||||||
if (name !== updated) {
|
if (name !== updated) {
|
||||||
tagOps.push(tag.save({name: updated}, options));
|
tagOps.push(tag.save({name: updated}, options));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (tagOps.length > 0) {
|
||||||
|
logInfo('Cleaning ' + tagOps.length + ' malformed tags');
|
||||||
|
return Promise.all(tagOps);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
if (tagOps.length > 0) {
|
|
||||||
logInfo('Cleaning ' + tagOps.length + ' malformed tags');
|
|
||||||
return Promise.all(tagOps);
|
|
||||||
}
|
}
|
||||||
}
|
return Promise.resolve();
|
||||||
return Promise.resolve();
|
});
|
||||||
});
|
};
|
||||||
ops.push(upgradeOp);
|
ops.push(upgradeOp);
|
||||||
|
|
||||||
// Add post_tag order
|
// Add post_tag order
|
||||||
upgradeOp = models.Post.findAll(_.extend({}, options, {withRelated: ['tags']})).then(function (posts) {
|
upgradeOp = function () {
|
||||||
var tagOps = [];
|
return models.Post.findAll(_.extend({}, options, {withRelated: ['tags']})).then(function (posts) {
|
||||||
if (posts) {
|
var tagOps = [];
|
||||||
posts.each(function (post) {
|
if (posts) {
|
||||||
var order = 0;
|
posts.each(function (post) {
|
||||||
post.related('tags').each(function (tag) {
|
var order = 0;
|
||||||
tagOps.push(post.tags().updatePivot(
|
post.related('tags').each(function (tag) {
|
||||||
{sort_order: order}, _.extend({}, options, {query: {where: {tag_id: tag.id}}})
|
tagOps.push(post.tags().updatePivot(
|
||||||
));
|
{sort_order: order}, _.extend({}, options, {query: {where: {tag_id: tag.id}}})
|
||||||
order += 1;
|
));
|
||||||
|
order += 1;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
if (tagOps.length > 0) {
|
||||||
if (tagOps.length > 0) {
|
logInfo('Updating order on ' + tagOps.length + ' tags');
|
||||||
logInfo('Updating order on ' + tagOps.length + ' tags');
|
return Promise.all(tagOps);
|
||||||
return Promise.all(tagOps);
|
}
|
||||||
}
|
});
|
||||||
});
|
};
|
||||||
ops.push(upgradeOp);
|
ops.push(upgradeOp);
|
||||||
|
|
||||||
// Add a new draft post
|
// Add a new draft post
|
||||||
upgradeOp = models.Post.findOne({slug: fixtures.posts_0_7[0].slug, status: 'all'}, options).then(function (post) {
|
upgradeOp = function () {
|
||||||
if (!post) {
|
return models.Post.findOne({slug: fixtures.posts_0_7[0].slug, status: 'all'}, options).then(function (post) {
|
||||||
logInfo('Adding 0.7 upgrade post fixture');
|
if (!post) {
|
||||||
// Set the published_at timestamp, but keep the post as a draft so doesn't appear on the frontend
|
logInfo('Adding 0.7 upgrade post fixture');
|
||||||
// This is a hack to ensure that this post appears at the very top of the drafts list, because
|
// Set the published_at timestamp, but keep the post as a draft so doesn't appear on the frontend
|
||||||
// unpublished posts always appear first
|
// This is a hack to ensure that this post appears at the very top of the drafts list, because
|
||||||
fixtures.posts_0_7[0].published_at = Date.now();
|
// unpublished posts always appear first
|
||||||
return models.Post.add(fixtures.posts_0_7[0], options);
|
fixtures.posts_0_7[0].published_at = Date.now();
|
||||||
}
|
return models.Post.add(fixtures.posts_0_7[0], options);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
ops.push(upgradeOp);
|
ops.push(upgradeOp);
|
||||||
|
|
||||||
return Promise.all(ops);
|
return sequence(ops);
|
||||||
};
|
};
|
||||||
|
|
||||||
update = function update(fromVersion, toVersion) {
|
update = function update(fromVersion, toVersion) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue