Permalink
Browse files

[databases] Enable support for databses with old info

  • Loading branch information...
1 parent f504fa0 commit bae3790ab5b5411932ff719fbc7590eecb2fa536 @cronopio cronopio committed Nov 9, 2012
Showing with 41 additions and 11 deletions.
  1. +41 −11 lib/jitsu/commands/databases.js
@@ -304,9 +304,18 @@ var printDatabase = function (database) {
switch (database.type) {
case 'couch':
printBase(database);
-
- var connUrl = 'http://' + database.metadata.host + ':5984',
- sslConnUrl = 'https://' + database.metadata.host + ':' + database.metadata.port;
+ var connUrl, sslConnUrl;
+
+ // We will need support the databases created using the old way
+ // So we check if
+ if (database.metadata.id.indexOf('/') !== -1) {
+ var subdomain = database.metadata.id.split('/')[1];
+ connUrl = 'http://' + subdomain + '.iriscouch.com:5984';
+ sslConnUrl = 'https://' + subdomain + '.iriscouch.com:6984';
+ } else {
+ connUrl = 'http://' + database.metadata.host + ':5984',
+ sslConnUrl = 'https://' + database.metadata.host + ':' + database.metadata.port;
+ }
jitsu.log.data('Connection url: ' + connUrl.grey);
jitsu.log.data('SSL connection url: ' + sslConnUrl.grey);
@@ -315,13 +324,17 @@ var printDatabase = function (database) {
case 'mongo':
case 'mongohq':
printBase(database);
- jitsu.log.data('Connection url: ' + database.metadata.uri.grey + '/'.grey + database.metadata.dbname.grey);
+ if (database.metadata.config && database.metadata.config.MONGOHQ_URL) {
+ jitsu.log.data('Connection url: ' + (database.metadata.config.MONGOHQ_URL).grey);
+ } else {
+ jitsu.log.data('Connection url: ' + database.metadata.uri.grey + '/'.grey + database.metadata.dbname.grey);
+ }
break;
case 'redis':
var port = database.metadata.port,
password = database.metadata.password,
- server = database.metadata.host;
+ server = (database.metadata.label) ? database.metadata.label.split('-')[0] + '.redistogo.com' : database.metadata.host;
printBase(database);
jitsu.log.data('Connection host: ' + server.grey);
@@ -337,10 +350,19 @@ var printDatabase = function (database) {
};
var printDbHelp = function (database) {
+
switch (database.type) {
case 'couch':
- var connUrl = 'http://' + database.metadata.host + ':5984',
- sslConnUrl = 'https://' + database.metadata.host + ':' + database.metadata.port;
+ var connUrl, sslConnUrl;
+
+ if (database.metadata.id.indexOf('/') !== -1) {
+ var subdomain = database.metadata.id.split('/')[1];
+ connUrl = 'http://' + subdomain + '.iriscouch.com:5984';
+ sslConnUrl = 'https://' + subdomain + '.iriscouch.com:6984';
+ } else {
+ connUrl = 'http://' + database.metadata.host + ':5984',
+ sslConnUrl = 'https://' + database.metadata.host + ':' + database.metadata.port;
+ }
// TODO: Only write this if in some "verbose" mode.
[
@@ -363,8 +385,16 @@ var printDbHelp = function (database) {
case 'mongo':
case 'mongohq':
- var parsed = require('url').parse(database.metadata.uri + '/' + database.metadata.dbname),
- auth = [database.metadata.username, database.metadata.password];
+ var parsed, auth, uri;
+ if (database.metadata.config && database.metadata.config.MONGOHQ_URL) {
+ parsed = require('url').parse(database.metadata.config.MONGOHQ_URL);
+ auth = parsed.auth.split(':');
+ uri = database.metadata.config.MONGOHQ_URL;
+ } else {
+ parsed = require('url').parse(database.metadata.uri + '/' + database.metadata.dbname);
+ auth = [database.metadata.username, database.metadata.password];
+ uri = database.metadata.uri + '/' + database.metadata.dbname;
+ }
// TODO: Only write this if in some "verbose" mode.
[
@@ -389,7 +419,7 @@ var printDbHelp = function (database) {
'Connect with the `' + 'mongoose'.magenta + '` module:',
'',
' var mongoose = require(\'mongoose\');',
- ' mongoose.connect(\'' + database.metadata.uri + '/' + database.metadata.dbname + '\');',
+ ' mongoose.connect(\'' + uri + '\');',
''
].forEach(printHelp);
@@ -399,7 +429,7 @@ var printDbHelp = function (database) {
case 'redistogo':
var port = database.metadata.port,
password = database.metadata.password,
- server = database.metadata.host;
+ server = (database.metadata.label) ? database.metadata.label.split('-')[0] + '.redistogo.com' : database.metadata.host;
[
'',

0 comments on commit bae3790

Please sign in to comment.