2 var BPromise = require('bluebird');
4 var logger = require('../config/logger')('migration');
5 var util = require('util');
7 var Sequence = function() {};
9 Sequence.prototype.enqueue = function(fn) {
10 this.tail = this.tail ? this.tail.finally(fn) : fn();
13 var Migration = function(queryInterface) {
14 this.queryInterface = queryInterface;
15 this.sequence = new Sequence();
18 Migration.prototype.changeColumn = function(table, column, type) {
20 this.sequence.enqueue(function() {
21 return _this.queryInterface
22 .changeColumn(table, column, type)
24 logger.info('Changed column %s in table %s', column, table);
26 .catch(function(err) {
27 logger.info(JSON.stringify(err));
32 Migration.prototype.addColumn = function(table, column, type) {
34 this.sequence.enqueue(function() {
35 return _this.queryInterface
36 .addColumn(table, column, type)
38 logger.info('Added column %s to %s', column, table);
40 .catch(function(err) {
41 logger.info(JSON.stringify(err));
46 Migration.prototype.dropTable = function(table) {
48 this.sequence.enqueue(function() {
49 return _this.queryInterface
54 logger.info('table dropped %s', table);
56 .catch(function(err) {
57 logger.info(JSON.stringify(err));
62 Migration.prototype.addIndex = function(table, column, indexName) {
64 this.sequence.enqueue(function() {
65 return _this.queryInterface.addIndex(table, column, {
69 logger.info('addIndex %s %s %s', table, column.join(','), indexName);
71 .catch(function(err) {
72 logger.info(JSON.stringify(err));
77 Migration.prototype.query = function(sql) {
79 this.sequence.enqueue(function() {
80 return _this.queryInterface.sequelize.query(sql)
82 logger.info('query %s', sql);
84 .catch(function(err) {
85 logger.info(JSON.stringify(err));
90 Migration.prototype.final = function(resolve) {
92 this.sequence.enqueue(function() {
99 up: function(queryInterface, Sequelize) {
100 return new BPromise(function(resolve, reject) {
102 var migration = new Migration(queryInterface);
105 migration.dropTable('user_has_chat_rooms');
106 migration.dropTable('chat_enquiries');
107 migration.dropTable('chat_messages');
108 migration.dropTable('chat_proactive_actions');
109 migration.dropTable('chat_dispositions');
110 migration.dropTable('chat_applications');
111 migration.dropTable('user_has_chat_interactions');
112 migration.dropTable('chat_interactions');
113 migration.dropTable('team_has_chat_queues');
114 migration.dropTable('user_has_chat_queues');
115 migration.dropTable('chat_queues');
116 migration.dropTable('chat_visitors');
117 migration.dropTable('chat_websites_fields');
118 migration.dropTable('chat_websites');
121 migration.changeColumn('voice_queues', 'dialQueueTimeout', {
122 type: Sequelize.INTEGER(3).UNSIGNED,
128 comment: 'Queue Timeout Seconds (min:1, max:999)'
131 migration.final(resolve);
138 down: function(queryInterface, Sequelize) {
139 var migration = new Migration(queryInterface);