var Sequence = function() {};
Sequence.prototype.enqueue = function(fn) {
- this.tail = this.tail ? this.tail.finally(fn) : fn();
+ this.tail = this.tail ? this.tail.finally(fn) : fn();
};
var Migration = function(queryInterface) {
- this.queryInterface = queryInterface;
- this.sequence = new Sequence();
+ 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(res) {
- logger.info('Changed column %s in table %s', column, table);
- })
- .catch(function(err) {
- logger.info(JSON.stringify(err));
- });
- });
+ var _this = this;
+ this.sequence.enqueue(function() {
+ return _this.queryInterface
+ .changeColumn(table, column, type)
+ .then(function(res) {
+ 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(res) {
- logger.info('Added column %s to %s', column, table);
- })
- .catch(function(err) {
- logger.info(JSON.stringify(err));
- });
- });
+ var _this = this;
+ this.sequence.enqueue(function() {
+ return _this.queryInterface
+ .addColumn(table, column, type)
+ .then(function(res) {
+ 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(res) {
- logger.info('table dropped %s', table);
- })
- .catch(function(err) {
- logger.info(JSON.stringify(err));
- });
- });
+ var _this = this;
+ this.sequence.enqueue(function() {
+ return _this.queryInterface
+ .dropTable(table, {
+ force: true
+ })
+ .then(function(res) {
+ 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(res) {
- logger.info('addIndex %s %s %s', table, column.join(','), indexName);
- })
- .catch(function(err) {
- logger.info(JSON.stringify(err));
- });
- });
+ var _this = this;
+ this.sequence.enqueue(function() {
+ return _this.queryInterface.addIndex(table, column, {
+ indexName: indexName
+ })
+ .then(function(res) {
+ logger.info('addIndex %s %s %s', table, column.join(','), 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(res) {
- logger.info('query %s', sql);
- })
- .catch(function(err) {
- logger.info(JSON.stringify(err));
- });
- });
+ var _this = this;
+ this.sequence.enqueue(function() {
+ return _this.queryInterface.sequelize.query(sql)
+ .then(function(res) {
+ 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(res) {
- logger.info('Removed column %s from %s', column, table);
- })
- .catch(function(err) {
- logger.info(util.inspect(err, {
- showHidden: false,
- depth: null
- }));
- });
- });
+ var _this = this;
+ this.sequence.enqueue(function() {
+ return _this.queryInterface.removeColumn(table, column)
+ .then(function(res) {
+ 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(res) {
- 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
- }));
- });
- });
+ var _this = this;
+ this.sequence.enqueue(function() {
+ return _this.queryInterface.renameColumn(table, oldColumn, newColumn)
+ .then(function(res) {
+ 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) {
- var _this = this;
- this.sequence.enqueue(function() {
- return resolve();
- });
+ var _this = this;
+ this.sequence.enqueue(function() {
+ return resolve();
+ });
};
module.exports = {
- up: function(queryInterface, Sequelize) {
- return new BPromise(function(resolve, reject) {
-
- var migration = new Migration(queryInterface);
-
- // START CHAT WEBSITES
- migration.addColumn('chat_websites', 'textColor', {
- type: Sequelize.STRING,
- allowNull: false,
- defaultValue: '#ffffff',
- validate: {
- notEmpty: true
- }
- });
- migration.addColumn('chat_websites', 'fontSize', {
- type: Sequelize.INTEGER,
- defaultValue: 15
- });
- migration.addColumn('chat_websites', 'timezone', {
- type: Sequelize.STRING
- });
- // END CHAT WEBSITES
-
- // START USERS
- migration.query('UPDATE users SET nat=\'force_rport,comedia\' WHERE nat IS NULL');
- migration.query('UPDATE users SET transport=\'udp\' WHERE avpf IS NULL AND transport IS NULL');
- migration.query('UPDATE users SET transport=\'wss\' WHERE avpf IS NOT NULL');
- // STOP USERS
-
- // START SCHEDULED REPORTS
- migration.changeColumn('tools_schedules', 'output', {
- type: Sequelize.ENUM('csv', 'pdf', 'xls', 'xlsx'),
- allowNull: false,
- defaultValue: 'csv'
- });
- migration.query('UPDATE tools_schedules SET output=\'xlsx\' WHERE output=\'xls\'');
- migration.changeColumn('tools_schedules', 'output', {
- type: Sequelize.ENUM('csv', 'pdf', 'xlsx'),
- allowNull: false,
- defaultValue: 'csv'
- });
- // END SCHEDULED REPORTS
-
- // START MAIL ACCOUNT
- migration.addColumn('mail_accounts', 'markAsUnread', {
- type: Sequelize.BOOLEAN,
- defaultValue: false
- });
-
- migration.addColumn('mail_accounts', 'fontFamily', {
- type: Sequelize.STRING,
- allowNull: false,
- defaultValue: 'Arial,Helvetica,sans-serif'
- });
-
- migration.addColumn('mail_accounts', 'fontSize', {
- type: Sequelize.INTEGER(2).UNSIGNED,
- defaultValue: 13,
- validate: {
- min: 8,
- max: 72
- }
- });
-
- migration.renameColumn('mail_accounts', 'signature', 'template');
- // END MAIL ACCOUNT
-
- // START FINAL
- migration.final(resolve);
- // END FINAL
- });
- },
-
- down: function(queryInterface, Sequelize) {
- var migration = new Migration(queryInterface);
- }
-};
\ No newline at end of file
+ up: function(queryInterface, Sequelize) {
+ return new BPromise(function(resolve, reject) {
+
+ var migration = new Migration(queryInterface);
+
+ // START CHAT WEBSITES
+ migration.addColumn('chat_websites', 'textColor', {
+ type: Sequelize.STRING,
+ allowNull: false,
+ defaultValue: '#ffffff',
+ validate: {
+ notEmpty: true
+ }
+ });
+ migration.addColumn('chat_websites', 'fontSize', {
+ type: Sequelize.INTEGER,
+ defaultValue: 15
+ });
+ migration.addColumn('chat_websites', 'timezone', {
+ type: Sequelize.STRING
+ });
+ // END CHAT WEBSITES
+
+ // START USERS
+ migration.query('UPDATE users SET nat=\'force_rport,comedia\' WHERE nat IS NULL');
+ migration.query('UPDATE users SET transport=\'udp\' WHERE avpf IS NULL AND transport IS NULL');
+ migration.query('UPDATE users SET transport=\'wss\' WHERE avpf IS NOT NULL');
+ // STOP USERS
+
+ // START SCHEDULED REPORTS
+ migration.changeColumn('tools_schedules', 'output', {
+ type: Sequelize.ENUM('csv', 'pdf', 'xls', 'xlsx'),
+ allowNull: false,
+ defaultValue: 'csv'
+ });
+ migration.query('UPDATE tools_schedules SET output=\'xlsx\' WHERE output=\'xls\'');
+ migration.changeColumn('tools_schedules', 'output', {
+ type: Sequelize.ENUM('csv', 'pdf', 'xlsx'),
+ allowNull: false,
+ defaultValue: 'csv'
+ });
+ // END SCHEDULED REPORTS
+
+ // START MAIL ACCOUNT
+ migration.addColumn('mail_accounts', 'markAsUnread', {
+ type: Sequelize.BOOLEAN,
+ defaultValue: false
+ });
+
+ migration.addColumn('mail_accounts', 'fontFamily', {
+ type: Sequelize.STRING,
+ allowNull: false,
+ defaultValue: 'Arial,Helvetica,sans-serif'
+ });
+
+ migration.addColumn('mail_accounts', 'fontSize', {
+ type: Sequelize.INTEGER(2).UNSIGNED,
+ defaultValue: 13,
+ validate: {
+ min: 8,
+ max: 72
+ }
+ });
+
+ migration.renameColumn('mail_accounts', 'signature', 'template');
+ // END MAIL ACCOUNT
+
+ // START FINAL
+ migration.final(resolve);
+ // END FINAL
+ });
+ },
+
+ down: function(queryInterface, Sequelize) {
+ var migration = new Migration(queryInterface);
+ }
+};