3 var BPromise = require('bluebird');
\r
4 var util = require('util');
\r
6 var logger = require('../config/logger')('migration');
\r
8 var Sequence = function() {};
\r
10 Sequence.prototype.enqueue = function(fn) {
\r
11 this.tail = this.tail ? this.tail.finally(fn) : fn();
\r
14 var Migration = function(queryInterface) {
\r
15 this.queryInterface = queryInterface;
\r
16 this.sequence = new Sequence();
\r
19 Migration.prototype.changeColumn = function(table, column, type) {
\r
21 this.sequence.enqueue(function() {
\r
22 return _this.queryInterface
\r
23 .changeColumn(table, column, type)
\r
25 logger.info('Changed column %s in table %s', column, table);
\r
27 .catch(function(err) {
\r
28 logger.info(JSON.stringify(err));
\r
33 Migration.prototype.addColumn = function(table, column, type) {
\r
35 this.sequence.enqueue(function() {
\r
36 return _this.queryInterface
\r
37 .addColumn(table, column, type)
\r
39 logger.info('Added column %s to %s', column, table);
\r
41 .catch(function(err) {
\r
42 logger.info(JSON.stringify(err));
\r
47 Migration.prototype.dropTable = function(table) {
\r
49 this.sequence.enqueue(function() {
\r
50 return _this.queryInterface
\r
55 logger.info('table dropped %s', table);
\r
57 .catch(function(err) {
\r
58 logger.info(JSON.stringify(err));
\r
63 Migration.prototype.addIndex = function(table, column, indexName) {
\r
65 this.sequence.enqueue(function() {
\r
66 return _this.queryInterface
\r
67 .addIndex(table, column, {
\r
68 indexName: indexName
\r
71 logger.info('addIndex %s %s %s', table, column.join(','), indexName);
\r
73 .catch(function(err) {
\r
74 logger.info(JSON.stringify(err));
\r
79 Migration.prototype.removeIndex = function(table, indexName) {
\r
81 this.sequence.enqueue(function() {
\r
82 return _this.queryInterface
\r
83 .removeIndex(table, indexName)
\r
85 logger.info('removeIndex %s %s', table, indexName);
\r
87 .catch(function(err) {
\r
88 logger.info(JSON.stringify(err));
\r
93 Migration.prototype.query = function(sql) {
\r
95 this.sequence.enqueue(function() {
\r
96 return _this.queryInterface.sequelize
\r
99 logger.info('query %s', sql);
\r
101 .catch(function(err) {
\r
102 logger.info(JSON.stringify(err));
\r
107 Migration.prototype.removeColumn = function(table, column) {
\r
109 this.sequence.enqueue(function() {
\r
110 return _this.queryInterface
\r
111 .removeColumn(table, column)
\r
113 logger.info('Removed column %s from %s', column, table);
\r
115 .catch(function(err) {
\r
117 util.inspect(err, {
\r
126 Migration.prototype.renameColumn = function(table, oldColumn, newColumn) {
\r
128 this.sequence.enqueue(function() {
\r
129 return _this.queryInterface
\r
130 .renameColumn(table, oldColumn, newColumn)
\r
132 logger.info('Renamed column from %s to %s on %s', oldColumn, newColumn, table);
\r
134 .catch(function(err) {
\r
136 util.inspect(err, {
\r
145 Migration.prototype.final = function(resolve) {
\r
146 this.sequence.enqueue(function() {
\r
152 up: function(queryInterface, Sequelize) {
\r
153 return new BPromise(function(resolve) {
\r
154 var migration = new Migration(queryInterface);
\r
156 // START team_has_voice_queues
\r
157 migration.query('ALTER TABLE team_has_voice_queues ADD COLUMN penalty SMALLINT(3) UNSIGNED DEFAULT 0 FIRST;');
\r
158 // END team_has_voice_queues
\r
161 migration.final(resolve);
\r
166 down: function(queryInterface, Sequelize) {
\r
167 // var migration = new Migration(queryInterface);
\r