Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / migrations / 2.0.23.js
1 'use strict';
2 var BPromise = require('bluebird');
3
4 var logger = require('../config/logger')('migration');
5
6 var Migration = function(queryInterface) {
7   this.queryInterface = queryInterface;
8 };
9
10 Migration.prototype.addColumn = function(table, column, type) {
11   return this.queryInterface
12     .addColumn(table, column, type)
13     .then(function(res) {
14       logger.info('Added column %s to %s', column, table);
15     })
16     .catch(function(err) {
17       logger.info(JSON.stringify(err));
18     });
19
20 };
21
22 Migration.prototype.removeColumn = function(table, column) {
23   return this.queryInterface
24     .removeColumn(table, column)
25     .then(function(res) {
26       logger.info('Removed column %s from %s', column, table);
27     })
28     .catch(function(err) {
29       logger.info(JSON.stringify(err));
30     });
31
32 };
33
34 Migration.prototype.renameColumn = function(table, oldColumn, newColumn) {
35   return this.queryInterface
36     .renameColumn(table, oldColumn, newColumn)
37     .then(function(res) {
38       logger.info('Renamed column from %s to %s on %s', oldColumn, newColumn, table);
39     })
40     .catch(function(err) {
41       logger.info(JSON.stringify(err));
42     });
43 };
44
45 Migration.prototype.dropTable = function(table) {
46   return this.queryInterface
47     .dropTable(table)
48     .then(function(res) {
49       logger.info('table dropped %s', table);
50     })
51     .catch(function(err) {
52       logger.info(JSON.stringify(err));
53     });
54 };
55
56 module.exports = {
57
58   up: function(queryInterface, Sequelize) {
59     var migration = new Migration(queryInterface);
60
61     migration.addColumn('int_salesforce_accounts', 'type', {
62       type: Sequelize.ENUM('integrationTab', 'newTab'),
63       defaultValue: 'integrationTab'
64     });
65
66     migration.addColumn('int_zendesk_accounts', 'type', {
67       type: Sequelize.ENUM('integrationTab', 'newTab'),
68       defaultValue: 'integrationTab'
69     });
70
71     migration.dropTable('user_has_openchannel_rooms', {
72       force: true
73     });
74
75     migration.dropTable('openchannel_messages', {
76       force: true
77     });
78
79     migration.dropTable('openchannel_rooms', {
80       force: true
81     });
82
83     migration.dropTable('openchannel_applications', {
84       force: true
85     });
86
87     migration.dropTable('openchannel_accounts', {
88       force: true
89     });
90   },
91
92   down: function(queryInterface, Sequelize) {
93     var migration = new Migration(queryInterface);
94     migration.removeColumn('int_salesforce_accounts', 'type');
95     migration.removeColumn('int_zendesk_accounts', 'type');
96   }
97 };