mirror of
https://github.com/strapi/strapi.git
synced 2025-08-05 15:29:04 +00:00
98 lines
3.0 KiB
Plaintext
Executable File
98 lines
3.0 KiB
Plaintext
Executable File
'use strict';
|
|
|
|
/**
|
|
* New migration information
|
|
*
|
|
* Warning: this migration has been automatically generated. We strongly advise
|
|
* you to manually verify those information.
|
|
*/
|
|
|
|
exports.up = function(connection, Promise) {
|
|
<% var dropped = false; var onlyDrop = true;
|
|
|
|
_.forEach(models, function (definition, model) {
|
|
if (!_.isEmpty(_.get(models[model], 'up.drop'))) {
|
|
dropped = true;
|
|
}
|
|
|
|
if (!_.isEmpty(_.get(models[model], 'up.others'))) {
|
|
onlyDrop = false;
|
|
}
|
|
});
|
|
|
|
if (dropped === true && onlyDrop === false) { %> return Promise.all([
|
|
<% _.forEach(models, function(definition, model) { %><%= _.get(models[model], 'up.drop') %><% }); %>
|
|
]).then(function() {
|
|
return Promise.all([
|
|
<% _.forEach(models, function(definition, model) { %><%= _.get(models[model], 'up.others') %><% }); %>
|
|
]);
|
|
});
|
|
<% } else if (dropped === true && onlyDrop === true) { %>
|
|
return Promise.all([
|
|
<% _.forEach(models, function(definition, model) { %><%= _.get(models[model], 'up.drop') %><% }); %>
|
|
]);
|
|
<% } else { %>
|
|
return Promise.all([
|
|
<% _.forEach(models, function(definition, model) { %><%= _.get(models[model], 'up.others') %><% }); %>
|
|
]);
|
|
<% } %>
|
|
};
|
|
|
|
/**
|
|
* How to rollback this migration
|
|
*
|
|
* Warning: this rollback has been automatically generated. We strongly advise
|
|
* you to manually verify those information.
|
|
*/
|
|
|
|
exports.down = function(connection, Promise) {
|
|
<% var dropped = false; var onlyDrop = true;
|
|
|
|
_.forEach(models, function (definition, model) {
|
|
if (!_.isEmpty(_.get(models[model], 'down.drop'))) {
|
|
dropped = true;
|
|
}
|
|
|
|
if (!_.isEmpty(_.get(models[model], 'down.others'))) {
|
|
onlyDrop = false;
|
|
}
|
|
});
|
|
|
|
if (dropped === true && onlyDrop === false) { %>
|
|
return Promise.all([
|
|
<% _.forEach(models, function(definition, model) { %><%= _.get(models[model], 'down.drop') %><% }); %>
|
|
]).then(function() {
|
|
return Promise.all([
|
|
<% _.forEach(models, function(definition, model) { %><%= _.get(models[model], 'down.others') %><% }); %>
|
|
]);
|
|
});
|
|
<% } else if (dropped === true && onlyDrop === true) { %>
|
|
return Promise.all([
|
|
<% _.forEach(models, function(definition, model) { %><%= _.get(models[model], 'down.drop') %><% }); %>
|
|
]);
|
|
<% } else { %>
|
|
return Promise.all([
|
|
<% _.forEach(models, function(definition, model) { %><%= _.get(models[model], 'down.others') %><% }); %>
|
|
]);
|
|
<% } %>
|
|
};
|
|
|
|
/**
|
|
* Migration's config
|
|
*/
|
|
|
|
exports.config = {
|
|
|
|
/**
|
|
* Transactions are an important feature of relational databases, as they allow
|
|
* correct recovery from failures and keep a database consistent even in cases of
|
|
* system failure. All queries within a transaction are executed on the same
|
|
* database connection, and run the entire set of queries as a single unit of work.
|
|
* Any failure will mean the database will rollback any queries executed on that
|
|
* connection to the pre-transaction state.
|
|
* By default, each migration is run inside a transaction.
|
|
*/
|
|
|
|
transaction: true
|
|
};
|