X-Git-Url: http://repos.xcallymotion.com/?a=blobdiff_plain;f=server%2Fmigrations%2F2.5.19.js;h=c22bc2ad4d4971e350182493b64d32907f2a57fd;hb=6154c6759c55056c3b23ea2e885ab9e551bbdf0c;hp=92c836dddcdab8cc978599df323b9ff370359adf;hpb=180439628549c979093908f0b833833689fb8374;p=motion2.git diff --git a/server/migrations/2.5.19.js b/server/migrations/2.5.19.js index 92c836d..c22bc2a 100644 --- a/server/migrations/2.5.19.js +++ b/server/migrations/2.5.19.js @@ -1,165 +1,165 @@ -'use strict'; - -var BPromise = require('bluebird'); -var util = require('util'); - -var logger = require('../config/logger')('migration'); - -var Sequence = function () { }; - -Sequence.prototype.enqueue = function (fn) { - this.tail = this.tail ? this.tail.finally(fn) : fn(); -}; - -var Migration = function (queryInterface) { - this.queryInterface = queryInterface; - this.sequence = new Sequence(); -}; - -Migration.prototype.changeColumn = function (table, column, type) { - var _this = this; - this.sequence.enqueue(function () { - return _this.queryInterface - .changeColumn(table, column, type) - .then(function () { - logger.info('Changed column %s in table %s', column, table); - }) - .catch(function (err) { - logger.info(JSON.stringify(err)); - }); - }); -}; - -Migration.prototype.addColumn = function (table, column, type) { - var _this = this; - this.sequence.enqueue(function () { - return _this.queryInterface - .addColumn(table, column, type) - .then(function () { - logger.info('Added column %s to %s', column, table); - }) - .catch(function (err) { - logger.info(JSON.stringify(err)); - }); - }); -}; - -Migration.prototype.dropTable = function (table) { - var _this = this; - this.sequence.enqueue(function () { - return _this.queryInterface - .dropTable(table, { - force: true - }) - .then(function () { - logger.info('table dropped %s', table); - }) - .catch(function (err) { - logger.info(JSON.stringify(err)); - }); - }); -}; - -Migration.prototype.addIndex = function (table, column, indexName) { - var _this = this; - this.sequence.enqueue(function () { - return _this.queryInterface - .addIndex(table, column, { - indexName: indexName - }) - .then(function () { - logger.info('addIndex %s %s %s', table, column.join(','), indexName); - }) - .catch(function (err) { - logger.info(JSON.stringify(err)); - }); - }); -}; - -Migration.prototype.removeIndex = function (table, indexName) { - var _this = this; - this.sequence.enqueue(function () { - return _this.queryInterface - .removeIndex(table, indexName) - .then(function () { - logger.info('removeIndex %s %s', table, indexName); - }) - .catch(function (err) { - logger.info(JSON.stringify(err)); - }); - }); -}; - -Migration.prototype.query = function (sql) { - var _this = this; - this.sequence.enqueue(function () { - return _this.queryInterface.sequelize - .query(sql) - .then(function () { - logger.info('query %s', sql); - }) - .catch(function (err) { - logger.info(JSON.stringify(err)); - }); - }); -}; - -Migration.prototype.removeColumn = function (table, column) { - var _this = this; - this.sequence.enqueue(function () { - return _this.queryInterface - .removeColumn(table, column) - .then(function () { - logger.info('Removed column %s from %s', column, table); - }) - .catch(function (err) { - logger.info( - util.inspect(err, { - showHidden: false, - depth: null - }) - ); - }); - }); -}; - -Migration.prototype.renameColumn = function (table, oldColumn, newColumn) { - var _this = this; - this.sequence.enqueue(function () { - return _this.queryInterface - .renameColumn(table, oldColumn, newColumn) - .then(function () { - logger.info('Renamed column from %s to %s on %s', oldColumn, newColumn, table); - }) - .catch(function (err) { - logger.info( - util.inspect(err, { - showHidden: false, - depth: null - }) - ); - }); - }); -}; - -Migration.prototype.final = function (resolve) { - this.sequence.enqueue(function () { - return resolve(); - }); -}; - -module.exports = { - up: function (queryInterface, Sequelize) { - return new BPromise(function (resolve) { - var migration = new Migration(queryInterface); - - // START FINAL - migration.final(resolve); - // END FINAL - }); - }, - - down: function (queryInterface, Sequelize) { - // var migration = new Migration(queryInterface); - } -}; +'use strict'; + +var BPromise = require('bluebird'); +var util = require('util'); + +var logger = require('../config/logger')('migration'); + +var Sequence = function () { }; + +Sequence.prototype.enqueue = function (fn) { + this.tail = this.tail ? this.tail.finally(fn) : fn(); +}; + +var Migration = function (queryInterface) { + this.queryInterface = queryInterface; + this.sequence = new Sequence(); +}; + +Migration.prototype.changeColumn = function (table, column, type) { + var _this = this; + this.sequence.enqueue(function () { + return _this.queryInterface + .changeColumn(table, column, type) + .then(function () { + logger.info('Changed column %s in table %s', column, table); + }) + .catch(function (err) { + logger.info(JSON.stringify(err)); + }); + }); +}; + +Migration.prototype.addColumn = function (table, column, type) { + var _this = this; + this.sequence.enqueue(function () { + return _this.queryInterface + .addColumn(table, column, type) + .then(function () { + logger.info('Added column %s to %s', column, table); + }) + .catch(function (err) { + logger.info(JSON.stringify(err)); + }); + }); +}; + +Migration.prototype.dropTable = function (table) { + var _this = this; + this.sequence.enqueue(function () { + return _this.queryInterface + .dropTable(table, { + force: true + }) + .then(function () { + logger.info('table dropped %s', table); + }) + .catch(function (err) { + logger.info(JSON.stringify(err)); + }); + }); +}; + +Migration.prototype.addIndex = function (table, column, indexName) { + var _this = this; + this.sequence.enqueue(function () { + return _this.queryInterface + .addIndex(table, column, { + indexName: indexName + }) + .then(function () { + logger.info('addIndex %s %s %s', table, column.join(','), indexName); + }) + .catch(function (err) { + logger.info(JSON.stringify(err)); + }); + }); +}; + +Migration.prototype.removeIndex = function (table, indexName) { + var _this = this; + this.sequence.enqueue(function () { + return _this.queryInterface + .removeIndex(table, indexName) + .then(function () { + logger.info('removeIndex %s %s', table, indexName); + }) + .catch(function (err) { + logger.info(JSON.stringify(err)); + }); + }); +}; + +Migration.prototype.query = function (sql) { + var _this = this; + this.sequence.enqueue(function () { + return _this.queryInterface.sequelize + .query(sql) + .then(function () { + logger.info('query %s', sql); + }) + .catch(function (err) { + logger.info(JSON.stringify(err)); + }); + }); +}; + +Migration.prototype.removeColumn = function (table, column) { + var _this = this; + this.sequence.enqueue(function () { + return _this.queryInterface + .removeColumn(table, column) + .then(function () { + logger.info('Removed column %s from %s', column, table); + }) + .catch(function (err) { + logger.info( + util.inspect(err, { + showHidden: false, + depth: null + }) + ); + }); + }); +}; + +Migration.prototype.renameColumn = function (table, oldColumn, newColumn) { + var _this = this; + this.sequence.enqueue(function () { + return _this.queryInterface + .renameColumn(table, oldColumn, newColumn) + .then(function () { + logger.info('Renamed column from %s to %s on %s', oldColumn, newColumn, table); + }) + .catch(function (err) { + logger.info( + util.inspect(err, { + showHidden: false, + depth: null + }) + ); + }); + }); +}; + +Migration.prototype.final = function (resolve) { + this.sequence.enqueue(function () { + return resolve(); + }); +}; + +module.exports = { + up: function (queryInterface, Sequelize) { + return new BPromise(function (resolve) { + var migration = new Migration(queryInterface); + + // START FINAL + migration.final(resolve); + // END FINAL + }); + }, + + down: function (queryInterface, Sequelize) { + // var migration = new Migration(queryInterface); + } +};