Merge branch 'release/1.2.0' into production
This commit is contained in:
commit
34528808ee
|
@ -1,65 +1,24 @@
|
|||
|
||||
### Contributing ###
|
||||
|
||||
Thank you for your interest in `loopback`, an open source project
|
||||
Thank you for your interest in `loopback-connector`, an open source project
|
||||
administered by StrongLoop.
|
||||
|
||||
Contributing to loopback is easy. In a few simple steps:
|
||||
Contributing to `loopback-connector` is easy. In a few simple steps:
|
||||
|
||||
* Ensure that your effort is aligned with the project’s roadmap by
|
||||
* Ensure that your effort is aligned with the project's roadmap by
|
||||
talking to the maintainers, especially if you are going to spend a
|
||||
lot of time on it. This project is currently maintained by
|
||||
[@ritch](https://github.com/ritch), [@raymondfeng](https://github.com/raymondfeng),
|
||||
and [@bajtos](https://github.com/bajtos). The preferred channel of communication
|
||||
is [LoopBack Forum](https://groups.google.com/forum/#!forum/loopbackjs) or
|
||||
[Github Issues](https://github.com/strongloop/loopback/issues).
|
||||
lot of time on it.
|
||||
|
||||
* Make something better or fix a bug.
|
||||
|
||||
* Adhere to code style outlined in the
|
||||
* Adhere to code style outlined in the [Google C++ Style Guide][] and
|
||||
[Google Javascript Style Guide][].
|
||||
|
||||
* [Sign your patches](#signing-patches) to indicate that your are
|
||||
making your contribution available under the terms of the
|
||||
[Contributor License Agreement](#contributor-license-agreement).
|
||||
* Sign the [Contributor License Agreement](https://cla.strongloop.com/strongloop/loopback-connector)
|
||||
|
||||
* Submit a pull request through Github.
|
||||
|
||||
|
||||
### Signing patches ###
|
||||
|
||||
Like many open source projects, we need a contributor license agreement
|
||||
from you before we can merge in your changes.
|
||||
|
||||
In summary, by submitting your code, you are granting us a right to use
|
||||
that code under the terms of this Agreement, including providing it to
|
||||
others. You are also certifying that you wrote it, and that you are
|
||||
allowed to license it to us. You are not giving up your copyright in
|
||||
your work. The license does not change your rights to use your own
|
||||
contributions for any other purpose.
|
||||
|
||||
Contributor License Agreements are important because they define the
|
||||
chain of ownership of a piece of software. Some companies won't allow
|
||||
the use of free software without clear agreements around code ownership.
|
||||
That's why many open source projects collect similar agreements from
|
||||
contributors. The CLA here is based on the Apache CLA.
|
||||
|
||||
To signify your agreement to these terms, add the following line to the
|
||||
bottom of your commit message. Use your real name and an actual e-mail
|
||||
address.
|
||||
|
||||
```
|
||||
Signed-off-by: Random J Developer <random@developer.example.org>
|
||||
```
|
||||
|
||||
Alternatively you can use the git command line to automatically add this
|
||||
line, as follows:
|
||||
|
||||
```
|
||||
$ git commit -sm "Replace rainbows by unicorns"
|
||||
```
|
||||
|
||||
|
||||
### Contributor License Agreement ###
|
||||
|
||||
```
|
||||
|
@ -188,7 +147,5 @@ $ git commit -sm "Replace rainbows by unicorns"
|
|||
inaccurate in any respect. Email us at callback@strongloop.com.
|
||||
```
|
||||
|
||||
|
||||
[Google C++ Style Guide]: https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
|
||||
[Google Javascript Style Guide]: https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
|
||||
[license]: LICENSE
|
||||
|
||||
|
|
36
lib/sql.js
36
lib/sql.js
|
@ -371,22 +371,34 @@ SqlConnector.prototype.automigrate = function (models, cb) {
|
|||
}
|
||||
|
||||
models = models || Object.keys(self._models);
|
||||
async.each(models, function (model, callback) {
|
||||
if (model in self._models) {
|
||||
self.dropTable(model, function (err) {
|
||||
if (models.length === 0) {
|
||||
return process.nextTick(cb);
|
||||
}
|
||||
|
||||
var invalidModels = models.filter(function(m) {
|
||||
return !(m in self._models);
|
||||
});
|
||||
if (invalidModels.length) {
|
||||
return process.nextTick(function() {
|
||||
cb(new Error('Cannot migrate models not attached to this datasource: ' +
|
||||
invalidModels.join(' ')));
|
||||
});
|
||||
}
|
||||
|
||||
async.each(models, function(model, done) {
|
||||
self.dropTable(model, function(err) {
|
||||
if (err) {
|
||||
// TODO(bajtos) should we abort here and call cb(err)?
|
||||
// The original code in juggler ignored the error completely
|
||||
console.error(err);
|
||||
}
|
||||
self.createTable(model, function(err, result) {
|
||||
if (err) {
|
||||
// TODO(bajtos) should we abort here and call cb(err)?
|
||||
// The original code in juggler ignored the error completely
|
||||
console.error(err);
|
||||
}
|
||||
self.createTable(model, function (err, result) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
callback(err, result);
|
||||
});
|
||||
done(err, result);
|
||||
});
|
||||
}
|
||||
});
|
||||
}, cb);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "loopback-connector",
|
||||
"version": "1.1.1",
|
||||
"version": "1.2.0",
|
||||
"description": "Building blocks for LoopBack connectors",
|
||||
"keywords": [
|
||||
"StrongLoop",
|
||||
|
@ -24,6 +24,8 @@
|
|||
"async": "^0.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "~1.9.2",
|
||||
"loopback-datasource-juggler": "^2.0.0",
|
||||
"mocha": "^1.19.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
var expect = require('chai').expect;
|
||||
var testConnector = require('./connectors/test-sql-connector');
|
||||
|
||||
var juggler = require('loopback-datasource-juggler');
|
||||
var ds = new juggler.DataSource({
|
||||
connector: testConnector,
|
||||
debug: true
|
||||
});
|
||||
|
||||
describe('sql connector', function() {
|
||||
beforeEach(function() {
|
||||
ds.connector._tables = {};
|
||||
ds.connector._models = {};
|
||||
ds.createModel('m1', {});
|
||||
});
|
||||
|
||||
it('automigrate all models', function(done) {
|
||||
ds.automigrate(function(err) {
|
||||
expect(ds.connector._tables).have.property('m1');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('automigrate one model', function(done) {
|
||||
ds.automigrate('m1', function(err) {
|
||||
expect(ds.connector._tables).have.property('m1');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('automigrate one or more models in an array', function(done) {
|
||||
ds.automigrate(['m1'], function(err) {
|
||||
expect(ds.connector._tables).have.property('m1');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('automigrate reports errors for models not attached', function(done) {
|
||||
ds.automigrate(['m1', 'm2'], function(err) {
|
||||
expect(err).to.be.an.instanceOf(Error);
|
||||
expect(ds.connector._tables).to.not.have.property('m1');
|
||||
expect(ds.connector._tables).to.not.have.property('m2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* A mockup connector that extends SQL connector
|
||||
*/
|
||||
var util = require('util');
|
||||
var SqlConnector = require('../../lib/sql');
|
||||
|
||||
exports.initialize = function initializeDataSource(dataSource, callback) {
|
||||
process.nextTick(function() {
|
||||
if(callback) {
|
||||
var connector = new TestConnector();
|
||||
connector.dataSource = dataSource;
|
||||
dataSource.connector = connector;
|
||||
callback(null, connector);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function TestConnector() {
|
||||
SqlConnector.apply(this, [].slice.call(arguments));
|
||||
this._tables = {};
|
||||
}
|
||||
|
||||
util.inherits(TestConnector, SqlConnector);
|
||||
|
||||
TestConnector.prototype.dropTable = function(model, cb) {
|
||||
var err;
|
||||
var exists = model in this._tables;
|
||||
if (!exists) {
|
||||
err = new Error('Model doesn\'t exist: ' + model);
|
||||
} else {
|
||||
delete this._tables[model];
|
||||
}
|
||||
process.nextTick(function() {
|
||||
cb(err);
|
||||
});
|
||||
};
|
||||
|
||||
TestConnector.prototype.createTable = function(model, cb) {
|
||||
var err;
|
||||
var exists = model in this._tables;
|
||||
if (exists) {
|
||||
err = new Error('Model already exists: ' + model);
|
||||
} else {
|
||||
this._tables[model] = model;
|
||||
}
|
||||
process.nextTick(function() {
|
||||
cb(err);
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue