3 var BPromise = require('bluebird');
4 var util = require('util');
6 var logger = require('../config/logger')('migration');
8 var Sequence = function() {};
10 Sequence.prototype.enqueue = function(fn) {
11 this.tail = this.tail ? this.tail.finally(fn) : fn();
14 var Migration = function(queryInterface) {
15 this.queryInterface = queryInterface;
16 this.sequence = new Sequence();
19 Migration.prototype.changeColumn = function(table, column, type) {
21 this.sequence.enqueue(function() {
22 return _this.queryInterface
23 .changeColumn(table, column, type)
25 logger.info('Changed column %s in table %s', column, table);
27 .catch(function(err) {
28 logger.info(JSON.stringify(err));
33 Migration.prototype.addColumn = function(table, column, type) {
35 this.sequence.enqueue(function() {
36 return _this.queryInterface
37 .addColumn(table, column, type)
39 logger.info('Added column %s to %s', column, table);
41 .catch(function(err) {
42 logger.info(JSON.stringify(err));
47 Migration.prototype.dropTable = function(table) {
49 this.sequence.enqueue(function() {
50 return _this.queryInterface
55 logger.info('table dropped %s', table);
57 .catch(function(err) {
58 logger.info(JSON.stringify(err));
63 Migration.prototype.addIndex = function(table, column, indexName) {
65 this.sequence.enqueue(function() {
66 return _this.queryInterface.addIndex(table, column, {
70 logger.info('addIndex %s %s %s', table, column.join(','), indexName);
72 .catch(function(err) {
73 logger.info(JSON.stringify(err));
78 Migration.prototype.removeIndex = function(table, indexName) {
80 this.sequence.enqueue(function() {
81 return _this.queryInterface.removeIndex(table, indexName)
83 logger.info('removeIndex %s %s', table, indexName);
85 .catch(function(err) {
86 logger.info(JSON.stringify(err));
91 Migration.prototype.query = function(sql) {
93 this.sequence.enqueue(function() {
94 return _this.queryInterface.sequelize.query(sql)
96 logger.info('query %s', sql);
98 .catch(function(err) {
99 logger.info(JSON.stringify(err));
104 Migration.prototype.removeColumn = function(table, column) {
106 this.sequence.enqueue(function() {
107 return _this.queryInterface.removeColumn(table, column)
109 logger.info('Removed column %s from %s', column, table);
111 .catch(function(err) {
112 logger.info(util.inspect(err, {
120 Migration.prototype.renameColumn = function(table, oldColumn, newColumn) {
122 this.sequence.enqueue(function() {
123 return _this.queryInterface.renameColumn(table, oldColumn, newColumn)
125 logger.info('Renamed column from %s to %s on %s', oldColumn, newColumn, table);
127 .catch(function(err) {
128 logger.info(util.inspect(err, {
136 Migration.prototype.final = function(resolve) {
137 this.sequence.enqueue(function() {
143 up: function(queryInterface, Sequelize) {
144 return new BPromise(function(resolve) {
145 var migration = new Migration(queryInterface);
148 migration.addColumn('chat_websites', 'queueTransfer', {
149 type: Sequelize.BOOLEAN,
152 migration.addColumn('chat_websites', 'enableCustomerCheckmarks', {
153 type: Sequelize.BOOLEAN,
156 migration.addColumn('chat_websites', 'queueTransferTimeout', {
157 type: Sequelize.INTEGER,
164 migration.addColumn('chat_websites', 'agentTransfer', {
165 type: Sequelize.BOOLEAN,
168 migration.addColumn('chat_websites', 'agentTransferTimeout', {
169 type: Sequelize.INTEGER,
176 migration.addColumn('chat_websites', 'systemAlias', {
177 type: Sequelize.STRING,
178 defaultValue: 'System'
180 migration.addColumn('chat_websites', 'systemAvatar', {
186 migration.addColumn('fax_accounts', 'queueTransfer', {
187 type: Sequelize.BOOLEAN,
190 migration.addColumn('fax_accounts', 'queueTransferTimeout', {
191 type: Sequelize.INTEGER,
198 migration.addColumn('fax_accounts', 'agentTransfer', {
199 type: Sequelize.BOOLEAN,
202 migration.addColumn('fax_accounts', 'agentTransferTimeout', {
203 type: Sequelize.INTEGER,
212 //START OPENCHANNEL_ACCOUNT
213 migration.addColumn('openchannel_accounts', 'queueTransfer', {
214 type: Sequelize.BOOLEAN,
217 migration.addColumn('openchannel_accounts', 'queueTransferTimeout', {
218 type: Sequelize.INTEGER,
225 migration.addColumn('openchannel_accounts', 'agentTransfer', {
226 type: Sequelize.BOOLEAN,
229 migration.addColumn('openchannel_accounts', 'agentTransferTimeout', {
230 type: Sequelize.INTEGER,
237 //END OPENCHANNEL_ACCOUNT
240 migration.addColumn('sms_accounts', 'queueTransfer', {
241 type: Sequelize.BOOLEAN,
244 migration.addColumn('sms_accounts', 'queueTransferTimeout', {
245 type: Sequelize.INTEGER,
252 migration.addColumn('sms_accounts', 'agentTransfer', {
253 type: Sequelize.BOOLEAN,
256 migration.addColumn('sms_accounts', 'agentTransferTimeout', {
257 type: Sequelize.INTEGER,
267 migration.addColumn('settings', 'chatTimeout', {
268 type: Sequelize.INTEGER,
271 migration.query('UPDATE settings SET chatTimeout = 0;');
272 migration.addColumn('settings', 'phoneBarRememberMeEnabled', {
273 type: Sequelize.BOOLEAN,
279 migration.addColumn('license', 'chatLicenseExceeded', {
280 type: Sequelize.INTEGER,
285 // START TOOLS_ACTIONS
286 migration.addColumn('tools_actions', 'data7', {
292 migration.final(resolve);
297 down: function(queryInterface, Sequelize) {
298 // var migration = new Migration(queryInterface);