3 var BPromise = require('bluebird');
4 var fs = require('fs');
5 var util = require('util');
6 var _ = require('lodash');
8 var logger = require('../config/logger')('migration');
10 var Sequence = function() {};
12 Sequence.prototype.enqueue = function(fn) {
13 this.tail = this.tail ? this.tail.finally(fn) : fn();
16 var Migration = function(queryInterface) {
17 this.queryInterface = queryInterface;
18 this.sequence = new Sequence();
21 Migration.prototype.changeColumn = function(table, column, type) {
23 this.sequence.enqueue(function() {
24 return _this.queryInterface
25 .changeColumn(table, column, type)
27 logger.info('Changed column %s in table %s', column, table);
29 .catch(function(err) {
30 logger.info(JSON.stringify(err));
35 Migration.prototype.addColumn = function(table, column, type) {
37 this.sequence.enqueue(function() {
38 return _this.queryInterface
39 .addColumn(table, column, type)
41 logger.info('Added column %s to %s', column, table);
43 .catch(function(err) {
44 logger.info(JSON.stringify(err));
49 Migration.prototype.dropTable = function(table) {
51 this.sequence.enqueue(function() {
52 return _this.queryInterface
57 logger.info('table dropped %s', table);
59 .catch(function(err) {
60 logger.info(JSON.stringify(err));
65 Migration.prototype.addIndex = function(table, column, indexName) {
67 this.sequence.enqueue(function() {
68 return _this.queryInterface.addIndex(table, column, {
72 logger.info('addIndex %s %s %s', table, column.join(','), indexName);
74 .catch(function(err) {
75 logger.info(JSON.stringify(err));
80 Migration.prototype.query = function(sql) {
82 this.sequence.enqueue(function() {
83 return _this.queryInterface.sequelize.query(sql)
85 logger.info('query %s', sql);
87 .catch(function(err) {
88 logger.info(JSON.stringify(err));
93 Migration.prototype.removeColumn = function(table, column) {
95 this.sequence.enqueue(function() {
96 return _this.queryInterface.removeColumn(table, column)
98 logger.info('Removed column %s from %s', column, table);
100 .catch(function(err) {
101 logger.info(util.inspect(err, {
109 Migration.prototype.final = function(resolve) {
111 this.sequence.enqueue(function() {
117 up: function(queryInterface, Sequelize) {
118 return new BPromise(function(resolve, reject) {
120 var migration = new Migration(queryInterface);
123 migration.addColumn('sms_accounts', 'smsMethod', {
124 type: Sequelize.ENUM('basic', 'classic', 'classic+')
126 migration.addColumn('sms_accounts', 'username', {
127 type: Sequelize.STRING
129 migration.addColumn('sms_accounts', 'password', {
130 type: Sequelize.STRING
132 migration.addColumn('sms_accounts', 'senderString', {
133 type: Sequelize.STRING
135 migration.addColumn('sms_accounts', 'deliveryReport', {
136 type: Sequelize.BOOLEAN,
142 migration.addColumn('users', 'allowmessenger', {
143 type: Sequelize.BOOLEAN,
147 migration.addColumn('users', 'phoneBarOutboundProxy', {
148 type: Sequelize.STRING
153 migration.addColumn('chat_websites', 'offlineMessageSubject', {
154 type: Sequelize.STRING,
155 defaultValue: 'New offline message from websiteName'
158 migration.addColumn('chat_websites', 'offlineMessageBody', {
159 type: Sequelize.STRING,
160 defaultValue: 'You received a new offline message from websiteName. Here you can find the details of the request:'
165 migration.addColumn('voice_queues', 'dialQueueProject2', {
166 type: Sequelize.STRING
169 migration.addColumn('voice_queues', 'dialAgiAfterHangupClient', {
170 type: Sequelize.BOOLEAN,
174 migration.addColumn('voice_queues', 'dialAgiAfterHangupAgent', {
175 type: Sequelize.BOOLEAN,
179 migration.query("DELETE FROM `voice_extensions` WHERE `exten`='xcally-motion-dialer' AND `priority`= 11");
181 migration.query("INSERT INTO `voice_extensions` (`context`, `exten`, `priority`, `app`, `appdata`, `type`, `description`, `createdAt`, `updatedAt`) VALUES ('from-sip', 'xcally-motion-dialer', '11', 'Execif', '$[\"${XMD-AGIAFTER}\" != \"NONE\" ]?AGI(${XMD-AGIAFTER})', 'system', 'dialer extensions auto generated', NOW(), NOW());");
183 migration.query("INSERT INTO `voice_extensions` (`context`, `exten`, `priority`, `app`, `type`, `description`, `createdAt`, `updatedAt`) VALUES ('from-sip', 'xcally-motion-dialer', '12', 'Hangup', 'system', 'dialer extensions auto generated', NOW(), NOW());");
185 migration.query("DELETE FROM `voice_extensions` WHERE `exten`='xcally-motion-preview' AND `priority`= 4");
187 migration.query("DELETE FROM `voice_extensions` WHERE `exten`='xcally-motion-preview' AND `priority`= 5");
189 migration.query("INSERT INTO `voice_extensions` (`context`, `exten`, `priority`, `app`, `appdata`, `type`, `description`, `createdAt`, `updatedAt`) VALUES ('from-sip', 'xcally-motion-preview', '4', 'Execif', '$[\"${XMD-AGI}\" != \"NONE\" ]?AGI(${XMD-AGI})', 'system', 'dialer extensions auto generated', NOW(), NOW());");
191 migration.query("INSERT INTO `voice_extensions` (`context`, `exten`, `priority`, `app`, `appdata`, `type`, `description`, `createdAt`, `updatedAt`) VALUES ('from-sip', 'xcally-motion-preview', '5', 'dial', '${XMD-DIALCHANNEL},${XMD-DIALTIMEOUT},${XMD-DIALOPTIONS},${XMD-DIALURL}', 'system', 'dialer extensions auto generated', NOW(), NOW());");
193 migration.query("INSERT INTO `voice_extensions` (`context`, `exten`, `priority`, `app`, `type`, `description`, `createdAt`, `updatedAt`) VALUES ('from-sip', 'xcally-motion-preview', '6', 'hangup', 'system', 'dialer extensions auto generated', NOW(), NOW());");
195 migration.addColumn('cm_hopper_final', 'agiafterat', {
202 migration.final(resolve);
207 down: function(queryInterface, Sequelize) {
208 var migration = new Migration(queryInterface);