Skip to content

Commit ab584dc

Browse files
committed
Extract getTableStatus & autoupdate
1 parent b8c2b73 commit ab584dc

File tree

1 file changed

+0
-58
lines changed

1 file changed

+0
-58
lines changed

lib/migration.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -51,64 +51,6 @@ function mixinMigration(PostgreSQL) {
5151
});
5252
};
5353

54-
/*!
55-
* Discover the properties from a table
56-
* @param {String} model The model name
57-
* @param {Function} cb The callback function
58-
*/
59-
PostgreSQL.prototype.getTableStatus = function(model, cb) {
60-
var fields, indexes;
61-
var self = this;
62-
63-
this.showFields(model, function(err, data) {
64-
if (err) return cb(err);
65-
fields = data;
66-
67-
self.showIndexes(model, function(err, data) {
68-
if (err) return cb(err);
69-
indexes = data;
70-
71-
if (fields && indexes)
72-
return cb(null, fields, indexes);
73-
});
74-
});
75-
};
76-
77-
/**
78-
* Perform autoupdate for the given models
79-
* @param {String[]} [models] A model name or an array of model names. If not present, apply to all models
80-
* @callback {Function} [callback] The callback function
81-
* @param {String|Error} err The error string or object
82-
*/
83-
PostgreSQL.prototype.autoupdate = function(models, cb) {
84-
var self = this;
85-
if ((!cb) && ('function' === typeof models)) {
86-
cb = models;
87-
models = undefined;
88-
}
89-
// First argument is a model name
90-
if ('string' === typeof models) {
91-
models = [models];
92-
}
93-
94-
models = models || Object.keys(this._models);
95-
96-
async.each(models, function(model, done) {
97-
if (!(model in self._models)) {
98-
return process.nextTick(function() {
99-
done(new Error(g.f('Model not found: %s' + model)));
100-
});
101-
}
102-
self.getTableStatus(model, function(err, fields, indexes) {
103-
if (!err && fields.length) {
104-
self.alterTable(model, fields, indexes, done);
105-
} else {
106-
self.createTable(model, done);
107-
}
108-
});
109-
}, cb);
110-
};
111-
11254
/*!
11355
* Check if the models exist
11456
* @param {String[]} [models] A model name or an array of model names. If not present, apply to all models

0 commit comments

Comments
 (0)