Built motion from commit (unavailable).|2.5.30
[motion2.git] / server / migrations / 2.5.22.js
diff --git a/server/migrations/2.5.22.js b/server/migrations/2.5.22.js
new file mode 100644 (file)
index 0000000..1322dc0
--- /dev/null
@@ -0,0 +1,202 @@
+'use strict';\r
+\r
+var BPromise = require('bluebird');\r
+var util = require('util');\r
+\r
+var logger = require('../config/logger')('migration');\r
+\r
+var Sequence = function () { };\r
+\r
+Sequence.prototype.enqueue = function (fn) {\r
+  this.tail = this.tail ? this.tail.finally(fn) : fn();\r
+};\r
+\r
+var Migration = function (queryInterface) {\r
+  this.queryInterface = queryInterface;\r
+  this.sequence = new Sequence();\r
+};\r
+\r
+Migration.prototype.changeColumn = function (table, column, type) {\r
+  var _this = this;\r
+  this.sequence.enqueue(function () {\r
+    return _this.queryInterface\r
+      .changeColumn(table, column, type)\r
+      .then(function () {\r
+        logger.info('Changed column %s in table %s', column, table);\r
+      })\r
+      .catch(function (err) {\r
+        logger.info(JSON.stringify(err));\r
+      });\r
+  });\r
+};\r
+\r
+Migration.prototype.addColumn = function (table, column, type) {\r
+  var _this = this;\r
+  this.sequence.enqueue(function () {\r
+    return _this.queryInterface\r
+      .addColumn(table, column, type)\r
+      .then(function () {\r
+        logger.info('Added column %s to %s', column, table);\r
+      })\r
+      .catch(function (err) {\r
+        logger.info(JSON.stringify(err));\r
+      });\r
+  });\r
+};\r
+\r
+Migration.prototype.dropTable = function (table) {\r
+  var _this = this;\r
+  this.sequence.enqueue(function () {\r
+    return _this.queryInterface\r
+      .dropTable(table, {\r
+        force: true\r
+      })\r
+      .then(function () {\r
+        logger.info('table dropped %s', table);\r
+      })\r
+      .catch(function (err) {\r
+        logger.info(JSON.stringify(err));\r
+      });\r
+  });\r
+};\r
+\r
+Migration.prototype.addIndex = function (table, column, indexName) {\r
+  var _this = this;\r
+  this.sequence.enqueue(function () {\r
+    return _this.queryInterface\r
+      .addIndex(table, column, {\r
+        indexName: indexName\r
+      })\r
+      .then(function () {\r
+        logger.info('addIndex %s %s %s', table, column.join(','), indexName);\r
+      })\r
+      .catch(function (err) {\r
+        logger.info(JSON.stringify(err));\r
+      });\r
+  });\r
+};\r
+\r
+Migration.prototype.removeIndex = function (table, indexName) {\r
+  var _this = this;\r
+  this.sequence.enqueue(function () {\r
+    return _this.queryInterface\r
+      .removeIndex(table, indexName)\r
+      .then(function () {\r
+        logger.info('removeIndex %s %s', table, indexName);\r
+      })\r
+      .catch(function (err) {\r
+        logger.info(JSON.stringify(err));\r
+      });\r
+  });\r
+};\r
+\r
+Migration.prototype.query = function (sql) {\r
+  var _this = this;\r
+  this.sequence.enqueue(function () {\r
+    return _this.queryInterface.sequelize\r
+      .query(sql)\r
+      .then(function () {\r
+        logger.info('query %s', sql);\r
+      })\r
+      .catch(function (err) {\r
+        logger.info(JSON.stringify(err));\r
+      });\r
+  });\r
+};\r
+\r
+Migration.prototype.removeColumn = function (table, column) {\r
+  var _this = this;\r
+  this.sequence.enqueue(function () {\r
+    return _this.queryInterface\r
+      .removeColumn(table, column)\r
+      .then(function () {\r
+        logger.info('Removed column %s from %s', column, table);\r
+      })\r
+      .catch(function (err) {\r
+        logger.info(\r
+          util.inspect(err, {\r
+            showHidden: false,\r
+            depth: null\r
+          })\r
+        );\r
+      });\r
+  });\r
+};\r
+\r
+Migration.prototype.renameColumn = function (table, oldColumn, newColumn) {\r
+  var _this = this;\r
+  this.sequence.enqueue(function () {\r
+    return _this.queryInterface\r
+      .renameColumn(table, oldColumn, newColumn)\r
+      .then(function () {\r
+        logger.info('Renamed column from %s to %s on %s', oldColumn, newColumn, table);\r
+      })\r
+      .catch(function (err) {\r
+        logger.info(\r
+          util.inspect(err, {\r
+            showHidden: false,\r
+            depth: null\r
+          })\r
+        );\r
+      });\r
+  });\r
+};\r
+\r
+Migration.prototype.final = function (resolve) {\r
+  this.sequence.enqueue(function () {\r
+    return resolve();\r
+  });\r
+};\r
+\r
+module.exports = {\r
+  up: function (queryInterface, Sequelize) {\r
+    return new BPromise(function (resolve) {\r
+      var migration = new Migration(queryInterface);\r
+\r
+      // START chat_websites\r
+      migration.addColumn('chat_websites', 'openNewInteraction', {\r
+        type: Sequelize.BOOLEAN,\r
+        defaultValue: false,\r
+        allowNull: true\r
+      });\r
+\r
+      migration.addColumn('chat_websites', 'MailAccountId', {\r
+        type: Sequelize.INTEGER\r
+      });\r
+\r
+      migration.query('ALTER TABLE chat_websites ADD CONSTRAINT `chat_websites_ibfk_4` FOREIGN KEY (`MailAccountId`) REFERENCES `mail_accounts` (`id`) ON DELETE SET NULL ON UPDATE CASCADE');\r
+      // END chat_websites\r
+\r
+      // START mail_messages\r
+      migration.addColumn('mail_messages', 'ChatWebsiteId', {\r
+        type: Sequelize.INTEGER\r
+      });\r
+\r
+      migration.addColumn('mail_messages', 'originChannel', {\r
+        type: Sequelize.ENUM('Email', 'Chat'),\r
+        defaultValue: 'Email',\r
+        allowNull: true\r
+      });\r
+\r
+      migration.addColumn('mail_messages', 'ChatOfflineMessageId', {\r
+        type: Sequelize.INTEGER\r
+      });\r
+\r
+      migration.query('ALTER TABLE mail_messages ADD CONSTRAINT `mail_messages_ibfk_5` FOREIGN KEY (`ChatWebsiteId`) REFERENCES `chat_websites` (`id`) ON DELETE SET NULL ON UPDATE CASCADE');\r
+      migration.query('ALTER TABLE mail_messages ADD CONSTRAINT `mail_messages_ibfk_6` FOREIGN KEY (`ChatOfflineMessageId`) REFERENCES `chat_offline_messages` (`id`) ON DELETE SET NULL ON UPDATE CASCADE');\r
+      // END mail_messages\r
+\r
+      // START voice_voicemail_messages\r
+      migration.query('ALTER TABLE voice_voicemail_messages MODIFY stamp timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;');\r
+      // END voice_voicemail_messages\r
+\r
+      // START FINAL\r
+      migration.final(resolve);\r
+      // END FINAL\r
+    });\r
+  },\r
+\r
+  down: function (queryInterface, Sequelize) {\r
+    // var migration = new Migration(queryInterface);\r
+  }\r
+};\r