Skip to content

Commit

Permalink
Merge 55b2109 into bd11229
Browse files Browse the repository at this point in the history
  • Loading branch information
okv committed Dec 27, 2019
2 parents bd11229 + 55b2109 commit 5595cad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 37 deletions.
53 changes: 21 additions & 32 deletions lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,36 @@ Adapter.prototype._setDbAndClient = function(dbOrClient) {
}
};

Adapter.prototype.connect = function(callback) {
var self = this;

MongoClient.connect(
self.params.url,
self.params.options || {},
function(err, dbOrClient) {
if (err) {
return callback(err);
}

self._setDbAndClient(dbOrClient);

self.collection = self.db.collection('_migrations');

callback(null, {
db: self.db,
dropIndexIfExists: self.helpers.dropIndexIfExists
});
}
);
Adapter.prototype.connect = function() {
return Promise.resolve()
.then(() => MongoClient.connect(this.params.url, this.params.options))
.then((dbOrClient) => {
this._setDbAndClient(dbOrClient);
this.collection = this.db.collection('_migrations');

return {
db: this.db,
dropIndexIfExists: this.helpers.dropIndexIfExists
};
});
};

Adapter.prototype.disconnect = function(callback) {
Adapter.prototype.disconnect = function() {
if (this.client) {
this.client.close(callback);
return this.client.close();
} else if (this.db) {
this.db.close(callback);
return this.db.close();
} else {
callback();
return Promise.resolve();
}
};

Adapter.prototype.getExecutedMigrationNames = function(callback) {
this.collection.find({}).toArray(function(err, docs) {
if (err) {
return callback(err);
}

callback(null, docs.map(function(doc) { return doc._id; }));
});
return Promise.resolve()
.then(() => this.collection.find({}).toArray())
.then((docs) => {
return docs.map((doc) => doc._id);
});
};

Adapter.prototype.markExecuted = function(name, callback) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@
},
"dependencies": {
"mongodb-uri": "0.9.7"
},
"engines": {
"node": ">=4.0.0"
}
}
5 changes: 0 additions & 5 deletions test/utils/createAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ module.exports = () => {

const adapter = new Adapter(defaultParams);

adapter.connect = promisify(adapter.connect.bind(adapter));
adapter.disconnect = promisify(adapter.disconnect.bind(adapter));
adapter.getExecutedMigrationNames = promisify(
adapter.getExecutedMigrationNames.bind(adapter)
);
adapter.helpers.dropIndexIfExists = promisify(
adapter.helpers.dropIndexIfExists
);
Expand Down

0 comments on commit 5595cad

Please sign in to comment.