Built motion from commit 4c579f6b.|2.5.32
[motion2.git] / server / migrations / 2.5.23.js
1 'use strict';\r
2 \r
3 var BPromise = require('bluebird');\r
4 var util = require('util');\r
5 \r
6 var logger = require('../config/logger')('migration');\r
7 \r
8 var Sequence = function() {};\r
9 \r
10 Sequence.prototype.enqueue = function(fn) {\r
11   this.tail = this.tail ? this.tail.finally(fn) : fn();\r
12 };\r
13 \r
14 var Migration = function(queryInterface) {\r
15   this.queryInterface = queryInterface;\r
16   this.sequence = new Sequence();\r
17 };\r
18 \r
19 Migration.prototype.changeColumn = function(table, column, type) {\r
20   var _this = this;\r
21   this.sequence.enqueue(function() {\r
22     return _this.queryInterface\r
23       .changeColumn(table, column, type)\r
24       .then(function() {\r
25         logger.info('Changed column %s in table %s', column, table);\r
26       })\r
27       .catch(function(err) {\r
28         logger.info(JSON.stringify(err));\r
29       });\r
30   });\r
31 };\r
32 \r
33 Migration.prototype.addColumn = function(table, column, type) {\r
34   var _this = this;\r
35   this.sequence.enqueue(function() {\r
36     return _this.queryInterface\r
37       .addColumn(table, column, type)\r
38       .then(function() {\r
39         logger.info('Added column %s to %s', column, table);\r
40       })\r
41       .catch(function(err) {\r
42         logger.info(JSON.stringify(err));\r
43       });\r
44   });\r
45 };\r
46 \r
47 Migration.prototype.dropTable = function(table) {\r
48   var _this = this;\r
49   this.sequence.enqueue(function() {\r
50     return _this.queryInterface\r
51       .dropTable(table, {\r
52         force: true\r
53       })\r
54       .then(function() {\r
55         logger.info('table dropped %s', table);\r
56       })\r
57       .catch(function(err) {\r
58         logger.info(JSON.stringify(err));\r
59       });\r
60   });\r
61 };\r
62 \r
63 Migration.prototype.addIndex = function(table, column, indexName) {\r
64   var _this = this;\r
65   this.sequence.enqueue(function() {\r
66     return _this.queryInterface\r
67       .addIndex(table, column, {\r
68         indexName: indexName\r
69       })\r
70       .then(function() {\r
71         logger.info('addIndex %s %s %s', table, column.join(','), indexName);\r
72       })\r
73       .catch(function(err) {\r
74         logger.info(JSON.stringify(err));\r
75       });\r
76   });\r
77 };\r
78 \r
79 Migration.prototype.removeIndex = function(table, indexName) {\r
80   var _this = this;\r
81   this.sequence.enqueue(function() {\r
82     return _this.queryInterface\r
83       .removeIndex(table, indexName)\r
84       .then(function() {\r
85         logger.info('removeIndex %s %s', table, indexName);\r
86       })\r
87       .catch(function(err) {\r
88         logger.info(JSON.stringify(err));\r
89       });\r
90   });\r
91 };\r
92 \r
93 Migration.prototype.query = function(sql) {\r
94   var _this = this;\r
95   this.sequence.enqueue(function() {\r
96     return _this.queryInterface.sequelize\r
97       .query(sql)\r
98       .then(function() {\r
99         logger.info('query %s', sql);\r
100       })\r
101       .catch(function(err) {\r
102         logger.info(JSON.stringify(err));\r
103       });\r
104   });\r
105 };\r
106 \r
107 Migration.prototype.removeColumn = function(table, column) {\r
108   var _this = this;\r
109   this.sequence.enqueue(function() {\r
110     return _this.queryInterface\r
111       .removeColumn(table, column)\r
112       .then(function() {\r
113         logger.info('Removed column %s from %s', column, table);\r
114       })\r
115       .catch(function(err) {\r
116         logger.info(\r
117           util.inspect(err, {\r
118             showHidden: false,\r
119             depth: null\r
120           })\r
121         );\r
122       });\r
123   });\r
124 };\r
125 \r
126 Migration.prototype.renameColumn = function(table, oldColumn, newColumn) {\r
127   var _this = this;\r
128   this.sequence.enqueue(function() {\r
129     return _this.queryInterface\r
130       .renameColumn(table, oldColumn, newColumn)\r
131       .then(function() {\r
132         logger.info('Renamed column from %s to %s on %s', oldColumn, newColumn, table);\r
133       })\r
134       .catch(function(err) {\r
135         logger.info(\r
136           util.inspect(err, {\r
137             showHidden: false,\r
138             depth: null\r
139           })\r
140         );\r
141       });\r
142   });\r
143 };\r
144 \r
145 Migration.prototype.final = function(resolve) {\r
146   this.sequence.enqueue(function() {\r
147     return resolve();\r
148   });\r
149 };\r
150 \r
151 module.exports = {\r
152   up: function(queryInterface, Sequelize) {\r
153     return new BPromise(function(resolve) {\r
154       var migration = new Migration(queryInterface);\r
155 \r
156       // START user_profiles\r
157       migration.addColumn('user_profiles', 'privacyEnabled', {\r
158         type: Sequelize.BOOLEAN,\r
159         defaultValue: false,\r
160         after: 'description'\r
161       });\r
162       // END user_profiles\r
163 \r
164       // START settings\r
165       migration.addColumn('settings', 'privacyPolicyNumber', {\r
166         type: Sequelize.INTEGER(2).UNSIGNED,\r
167         defaultValue: 0\r
168       });\r
169 \r
170       migration.addColumn('settings', 'privacyPolicyEmail', {\r
171         type: Sequelize.INTEGER(2).UNSIGNED,\r
172         defaultValue: 0\r
173       });\r
174 \r
175       migration.addColumn('settings', 'privacyPolicyName', {\r
176         type: Sequelize.INTEGER(2).UNSIGNED,\r
177         defaultValue: 0\r
178       });\r
179       // END settings\r
180 \r
181       // START integration fields\r
182       migration.changeColumn('int_desk_fields', 'type', {\r
183         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
184       });\r
185 \r
186       migration.changeColumn('int_dynamics365_fields', 'type', {\r
187         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
188       });\r
189 \r
190       migration.changeColumn('int_freshdesk_fields', 'type', {\r
191         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
192       });\r
193 \r
194       migration.changeColumn('int_freshsales_fields', 'type', {\r
195         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
196       });\r
197 \r
198       migration.changeColumn('int_salesforce_fields', 'type', {\r
199         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
200       });\r
201 \r
202       migration.changeColumn('int_servicenow_fields', 'type', {\r
203         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
204       });\r
205 \r
206       migration.changeColumn('int_sugarcrm_fields', 'type', {\r
207         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
208       });\r
209 \r
210       migration.changeColumn('int_vtiger_fields', 'type', {\r
211         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
212       });\r
213 \r
214       migration.changeColumn('int_zendesk_fields', 'type', {\r
215         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
216       });\r
217 \r
218       migration.changeColumn('int_zoho_fields', 'type', {\r
219         type: Sequelize.ENUM('string', 'variable', 'customVariable', 'keyValue', 'picklist')\r
220       });\r
221       // END integration fields\r
222 \r
223       // START int_salesforce_configurations\r
224       migration.addColumn('int_salesforce_configurations', 'leadId', {\r
225         type: Sequelize.STRING\r
226       });\r
227 \r
228       migration.query("ALTER TABLE int_salesforce_configurations MODIFY moduleSearch ENUM('contact_lead','contact','lead','account_contact_lead','account')");\r
229       migration.query("ALTER TABLE int_salesforce_configurations MODIFY moduleCreate ENUM('nothing','contact','lead','account')");\r
230 \r
231       migration.addColumn('int_salesforce_configurations', 'additionalSearchAccount', {\r
232         type: Sequelize.STRING\r
233       });\r
234 \r
235       migration.addColumn('int_salesforce_configurations', 'additionalSearchContact', {\r
236         type: Sequelize.STRING\r
237       });\r
238 \r
239       migration.addColumn('int_salesforce_configurations', 'additionalSearchLead', {\r
240         type: Sequelize.STRING\r
241       });\r
242       // END int_salesforce_configurations\r
243 \r
244       // START FINAL\r
245       migration.final(resolve);\r
246       // END FINAL\r
247     });\r
248   },\r
249 \r
250   down: function(queryInterface, Sequelize) {\r
251     // var migration = new Migration(queryInterface);\r
252   }\r
253 };