Skip to content

Commit b86a5ee

Browse files
committed
Allow ENV variable to define DB name
1 parent 24434b7 commit b86a5ee

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/db.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
var crypto = require('crypto'),
33
async = require('async'),
44
cloudant = require('./cloudant.js'),
5+
dbname = process.env.SSS_CLOUDANT_DATABASE || "seams",
56
schema = require('./schema.js'),
67
debug = require('debug')('seams'),
7-
settingsdb = cloudant.db.use('seams_settings'),
8-
seamsdb = cloudant.db.use('seams');
8+
settingsdb = cloudant.db.use(dbname + '_settings'),
9+
seamsdb = cloudant.db.use(dbname);
910

1011
var querylimit = 20;
1112

1213
var init = function() {
1314

1415
// ensure that the database exists
15-
cloudant.db.create("seams", function(err,data) {
16+
cloudant.db.create(dbname, function(err,data) {
1617
data = null;
1718
schema.load(function(err,data) {
1819
debug("SCHEMA", data);
1920
});
2021
});
21-
cloudant.db.create("seams_settings", function(err,data) {
22+
cloudant.db.create(dbname + '_settings', function(err,data) {
2223
err = null;
2324
data = null;
2425
//insert document with default values
@@ -224,9 +225,9 @@ var search = function(opts, envOpts, callback) {
224225
};
225226

226227
var deleteAndCreate = function(callback) {
227-
cloudant.db.destroy("seams", function(err,data) {
228+
cloudant.db.destroy(dbname, function(err,data) {
228229
console.log("DESTROY", err,data);
229-
cloudant.db.create("seams", callback);
230+
cloudant.db.create(dbname, callback);
230231
});
231232
};
232233

lib/import.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var couchimport = require('couchimport'),
33
request = require('request'),
44
latestStatus = null;
55

6+
var dbname = process.env.SSS_CLOUDANT_DATABASE || "seams"
7+
68
var clear = function() {
79
latestStatus= null;
810
};
@@ -14,7 +16,7 @@ var importFile = function(filename, theschema, cloudant, callback) {
1416
var opts = {
1517
COUCH_URL: cloudant.url,
1618
COUCH_DELIMITER: (filename.match(/\.csv/))?",":"\t",
17-
COUCH_DATABASE: "seams",
19+
COUCH_DATABASE: dbname,
1820
COUCH_TRANSFORM: require(__dirname+ "/transform.js"),
1921
COUCH_META: theschema,
2022
COUCH_PARALLELISM: 5

lib/schema.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var cloudant = require('./cloudant.js'),
22
couchmigrate = require('./couchmigrate'),
3-
seamsdb = cloudant.db.use('seams'),
3+
dbname = process.env.SSS_CLOUDANT_DATABASE || 'seams',
4+
seamsdb = cloudant.db.use(dbname),
45
defaultSchema = { _id: "schema", fields:[]},
56
_ = require('underscore');
67

@@ -57,7 +58,7 @@ var generateSearchIndex = function(schema, callback) {
5758
}
5859
}};
5960

60-
couchmigrate.migrate("seams", ddoc, callback);
61+
couchmigrate.migrate(dbname, ddoc, callback);
6162
};
6263

6364
var save = function(schema, callback) {

0 commit comments

Comments
 (0)