Correctly handle callback after blank automigration
This commit is contained in:
parent
d558dd6b70
commit
f3e80c28f7
|
@ -24,19 +24,20 @@ exports.initialize = function initializeSchema(schema, callback) {
|
||||||
s.port = parseInt(s.port || '27017', 10);
|
s.port = parseInt(s.port || '27017', 10);
|
||||||
s.database = s.database || 'test';
|
s.database = s.database || 'test';
|
||||||
|
|
||||||
|
schema.adapter = new MongoDB(s, schema, callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
function MongoDB(s, schema, callback) {
|
||||||
|
this._models = {};
|
||||||
|
this.collections = {};
|
||||||
|
|
||||||
var server = new mongodb.Server(s.host, s.port, {});
|
var server = new mongodb.Server(s.host, s.port, {});
|
||||||
new mongodb.Db(s.database, server, {}).open(function (err, client) {
|
new mongodb.Db(s.database, server, {}).open(function (err, client) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
schema.client = client;
|
|
||||||
schema.adapter = new MongoDB(client);
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function MongoDB(client) {
|
|
||||||
this._models = {};
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.collections = {};
|
schema.client = client;
|
||||||
|
callback();
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
MongoDB.prototype.define = function (descr) {
|
MongoDB.prototype.define = function (descr) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ exports.initialize = function initializeSchema(schema, callback) {
|
||||||
debug: s.debug
|
debug: s.debug
|
||||||
});
|
});
|
||||||
schema.adapter = new PG(schema.client);
|
schema.adapter = new PG(schema.client);
|
||||||
if (s.autoconnect === false) return callback();
|
|
||||||
|
|
||||||
schema.adapter.connect(callback);
|
schema.adapter.connect(callback);
|
||||||
};
|
};
|
||||||
|
|
|
@ -128,12 +128,15 @@ BaseSQL.prototype.automigrate = function (cb) {
|
||||||
Object.keys(this._models).forEach(function (model) {
|
Object.keys(this._models).forEach(function (model) {
|
||||||
wait += 1;
|
wait += 1;
|
||||||
self.dropTable(model, function () {
|
self.dropTable(model, function () {
|
||||||
|
// console.log('drop', model);
|
||||||
self.createTable(model, function (err) {
|
self.createTable(model, function (err) {
|
||||||
|
// console.log('create', model);
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if (wait === 0) cb();
|
||||||
|
|
||||||
function done() {
|
function done() {
|
||||||
if (--wait === 0 && cb) {
|
if (--wait === 0 && cb) {
|
||||||
|
|
|
@ -29,23 +29,15 @@ Object.keys(schemas).forEach(function (schemaName) {
|
||||||
if (process.env.ONLY && process.env.ONLY !== schemaName) return;
|
if (process.env.ONLY && process.env.ONLY !== schemaName) return;
|
||||||
if (process.env.EXCEPT && ~process.env.EXCEPT.indexOf(schemaName)) return;
|
if (process.env.EXCEPT && ~process.env.EXCEPT.indexOf(schemaName)) return;
|
||||||
context(schemaName, function () {
|
context(schemaName, function () {
|
||||||
schemas[schemaName].autoconnect = false;
|
|
||||||
var schema = new Schema(schemaName, schemas[schemaName]);
|
var schema = new Schema(schemaName, schemas[schemaName]);
|
||||||
|
|
||||||
it('should connect to database', function (test) {
|
it('should connect to database', function (test) {
|
||||||
console.log('Connecting:', schemaName);
|
if (schema.connected) return test.done();
|
||||||
if (schema.adapter && schema.adapter.connect) {
|
schema.on('connected', test.done);
|
||||||
schema.adapter.connect(function () {
|
|
||||||
test.done();
|
|
||||||
});
|
|
||||||
} else if (!schema.adapter) {
|
|
||||||
setTimeout(test.done, 1000);
|
|
||||||
} else {
|
|
||||||
test.done()
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
schema.log = function (a) {
|
schema.log = function (a) {
|
||||||
console.log(a);
|
// console.log(a);
|
||||||
};
|
};
|
||||||
testOrm(schema);
|
testOrm(schema);
|
||||||
if (specificTest[schemaName]) specificTest[schemaName](schema);
|
if (specificTest[schemaName]) specificTest[schemaName](schema);
|
||||||
|
|
Loading…
Reference in New Issue