Built motion from commit 639a1a7f.|2.6.19
[motion2.git] / server / migrations / 2.6.19.js
diff --git a/server/migrations/2.6.19.js b/server/migrations/2.6.19.js
new file mode 100644 (file)
index 0000000..4b7d9b5
--- /dev/null
@@ -0,0 +1,287 @@
+'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 change field canned answer to medium
+      migration.query('ALTER TABLE `tools_canned_answers` MODIFY COLUMN value mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL;');
+      // END change field canned answer to medium
+      // START chat_websites
+      migration.addColumn('chat_websites', 'waitForTheAssignedQueue', {
+        type: Sequelize.INTEGER,
+        validate: {
+          min: 1,
+          max: 2147483
+        },
+        defaultValue: 10
+      });
+      // END chat_websites
+
+      // START mail_accounts
+      migration.addColumn('mail_accounts', 'waitForTheAssignedQueue', {
+        type: Sequelize.INTEGER,
+        validate: {
+          min: 1,
+          max: 2147483
+        },
+        defaultValue: 10
+      });
+      // END mail_accounts
+
+      // START sms_accounts
+      migration.addColumn('sms_accounts', 'waitForTheAssignedQueue', {
+        type: Sequelize.INTEGER,
+        validate: {
+          min: 1,
+          max: 2147483
+        },
+        defaultValue: 10
+      });
+      // END sms_accounts
+
+      // START openchannel_accounts
+      migration.addColumn('openchannel_accounts', 'waitForTheAssignedQueue', {
+        type: Sequelize.INTEGER,
+        validate: {
+          min: 1,
+          max: 2147483
+        },
+        defaultValue: 10
+      });
+      // END openchannel_accounts
+
+      // START fax_accounts
+      migration.addColumn('fax_accounts', 'waitForTheAssignedQueue', {
+        type: Sequelize.INTEGER,
+        validate: {
+          min: 1,
+          max: 2147483
+        },
+        defaultValue: 10
+      });
+      // END fax_accounts
+
+      // START whatsapp_accounts
+      migration.addColumn('whatsapp_accounts', 'waitForTheAssignedQueue', {
+        type: Sequelize.INTEGER,
+        validate: {
+          min: 1,
+          max: 2147483
+        },
+        defaultValue: 10
+      });
+      // END whatsapp_accounts     
+
+      // START chat_interactions
+      migration.addColumn('chat_interactions', 'queueId', {
+        type: Sequelize.INTEGER,
+        allowNull: true
+      });
+      // END chat_interactions
+
+      // START mail_interactions
+      migration.addColumn('mail_interactions', 'queueId', {
+        type: Sequelize.INTEGER,
+        allowNull: true
+      });
+      // END mail_interactions           
+
+      // START sms_interactions
+      migration.addColumn('sms_interactions', 'queueId', {
+        type: Sequelize.INTEGER,
+        allowNull: true
+      });
+      // END sms_interactions  
+
+      // START openchannel_interactions
+      migration.addColumn('openchannel_interactions', 'queueId', {
+        type: Sequelize.INTEGER,
+        allowNull: true
+      });
+      // END openchannel_interactions  
+
+      // START fax_interactions
+      migration.addColumn('fax_interactions', 'queueId', {
+        type: Sequelize.INTEGER,
+        allowNull: true
+      });
+      // END fax_interactions  
+
+      // START whatsapp_interactions
+      migration.addColumn('whatsapp_interactions', 'queueId', {
+        type: Sequelize.INTEGER,
+        allowNull: true
+      });
+      // END whatsapp_interactions  
+
+      // START users
+      migration.addColumn('users', 'messengerSoundNotification', {
+        type: Sequelize.BOOLEAN,
+        defaultValue: false
+      });
+      // END users
+
+
+      // START FINAL
+      migration.final(resolve);
+      // END FINAL
+    });
+  },
+
+  down: function( /* queryInterface, Sequelize */ ) {
+    // var migration = new Migration(queryInterface);
+  },
+};
\ No newline at end of file