-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from redgeoff/initial
feat(initial)
- Loading branch information
Showing
9 changed files
with
323 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
# Doesn't actually work! | ||
# node: | ||
# version: 7.10.0 | ||
# version: 8.1.4 | ||
|
||
# Uncomment to test with CouchDB 2 | ||
machine: | ||
services: | ||
- docker | ||
|
||
dependencies: | ||
pre: | ||
- nvm install 7.10.0 | ||
- nvm use 7.10.0 && npm install -g npm | ||
- nvm install 8.1.4 | ||
- nvm use 8.1.4 && npm install -g npm | ||
|
||
# Install CouchDB 2 | ||
- docker run -d --name couchdb --restart always -p 5984:5984 -e COUCHDB_USER='admin' -e COUCHDB_PASSWORD='admin' redgeoff/couchdb | ||
# Wait for DB to be ready | ||
- sleep 15 | ||
# Create system DBs | ||
- curl -X PUT http://admin:[email protected]:5984/_users | ||
- curl -X PUT http://admin:[email protected]:5984/_replicator | ||
- curl -X PUT http://admin:[email protected]:5984/_global_changes | ||
|
||
# Enable CORS | ||
- nvm use 8.1.4 && npm install -g add-cors-to-couchdb | ||
- nvm use 8.1.4 && add-cors-to-couchdb http://localhost:5984 -u admin -p admin | ||
|
||
override: | ||
- nvm use 7.10.0 && npm install | ||
- nvm use 8.1.4 && npm install | ||
|
||
test: | ||
pre: | ||
- nvm use 7.10.0 && npm run assert-beautified | ||
- nvm use 7.10.0 && npm run jshint | ||
- nvm use 8.1.4 && npm run assert-beautified | ||
- nvm use 8.1.4 && npm run jshint | ||
|
||
override: | ||
- nvm use 7.10.0 && npm run node-full-test | ||
- nvm use 7.10.0 && npm run browser-test-phantomjs | ||
- nvm use 7.10.0 && npm run browser-coverage-full-test | ||
# Test on CouchDB 2 | ||
- nvm use 8.1.4 && npm run node-full-test | ||
- nvm use 8.1.4 && npm run browser-test-phantomjs | ||
- nvm use 8.1.4 && npm run browser-coverage-full-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,8 @@ | |
] | ||
}, | ||
"dependencies": { | ||
"sporks": "0.0.1" | ||
"couch-slouch": "0.0.3", | ||
"sporks": "0.0.1", | ||
"squadron": "0.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use strict'; | ||
|
||
var Slouch = require('couch-slouch'), | ||
squadron = require('squadron'); | ||
|
||
// params | ||
// source | ||
// target | ||
// concurrency | ||
// skip | ||
var Cluster = function (params) { | ||
this._params = params; | ||
|
||
this._sourceSlouch = new Slouch(params.source); | ||
this._targetSlouch = new Slouch(params.target); | ||
|
||
if (this._params.concurrency === 1) { | ||
// Don't use a throttler | ||
this._throttler = undefined; | ||
} else { | ||
// Create a throttler with the specified or default concurrency | ||
var concurrency = this._params.concurrency ? this._params.concurrency : null; | ||
this._throttler = new squadron.Throttler(concurrency); | ||
} | ||
}; | ||
|
||
Cluster.prototype.replicate = function () { | ||
var self = this; | ||
return self._sourceSlouch.db.all().each(function (db) { | ||
if (!self._params.skip || self._params.skip.indexOf(db) === -1) { | ||
return self._replicateDB(db, db); | ||
} | ||
}, self._throttler); | ||
}; | ||
|
||
Cluster.prototype._createDBIfMissing = function (db) { | ||
var self = this; | ||
return self._targetSlouch.db.exists(db).then(function (exists) { | ||
if (!exists) { | ||
return self._targetSlouch.db.create(db); | ||
} | ||
}); | ||
}; | ||
|
||
Cluster.prototype._replicateSecurity = function (sourceDB, targetDB) { | ||
var self = this; | ||
return self._sourceSlouch.security.get(sourceDB).then(function (security) { | ||
return self._targetSlouch.security.set(targetDB, security); | ||
}); | ||
}; | ||
|
||
Cluster.prototype._replicateRawDB = function (sourceDB, targetDB) { | ||
return this._sourceSlouch.db.replicate({ | ||
source: this._params.source + '/' + sourceDB, | ||
target: this._params.target + '/' + targetDB | ||
}); | ||
}; | ||
|
||
Cluster.prototype._replicateDB = function (sourceDB, targetDB) { | ||
var self = this; | ||
return self._createDBIfMissing(targetDB).then(function () { | ||
// Replicate security first so that security is put in place before data is copied over | ||
return self._replicateSecurity(sourceDB, targetDB); | ||
}).then(function () { | ||
return self._replicateRawDB(sourceDB, targetDB); | ||
}); | ||
}; | ||
|
||
module.exports = Cluster; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('./cluster'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.