Sequelize = require('sequelize')
dbConfig = require('../database.json')['staging']
pg = require('pg').native;

var db;

if (process.env.DATABASE_URL) {
  var match = process.env.DATABASE_URL.match(/postgres:\/\/([^:]+):([^@]+)@([^:]+):(\d+)\/(.+)/);
  var db = new Sequelize(match[5], match[1], match[2], {
    dialect: 'postgres',
    protocol: 'postgres',
    port: match[4],
    host: match[3],
    logging: true,
    native: true
  });
} else {
  var db = new Sequelize(dbConfig.database, dbConfig.user, dbConfig.password, {
    dialect: "postgres",
    host: dbConfig.host,
    port: 5432,
    omitNull: true,
    native: true,
    protocol: 'postgres'
  });
}

module.exports = db;

@@ -26,23 +26,17 @@
 elize')%0A
-dbConfi
+p
 g = requ
@@ -44,145 +44,197 @@
 re('
-../database.json')%5B'staging'%5D%0Apg = require('pg').native;%0A%0Avar db;%0A%0Aif (process.env.DATABASE_URL) %7B%0A  var match = process.env.DATABASE_URL
+pg').native;%0A%0Avar nconf = require('./../nconf.js');%0Avar db;%0A%0Avar databaseUrl = nconf.get('DATABASE_URL');%0Aconsole.log('sequelize', databaseUrl);%0Aif (databaseUrl) %7B%0A  var match = databaseUrl
 .mat
@@ -494,218 +494,63 @@
 %7B%0A  
-var db = new Sequelize(dbConfig.database, dbConfig.user, dbConfig.password, %7B%0A    d
+throw new Error('DATABASE_URL env var
 ia
+b
 le
-ct: %22postgres%22,%0A    host: dbConfig.host,%0A    port: 5432,%0A    omitNull: true,%0A    native: true,%0A    protocol: 'postgres'%0A  %7D
+ is required'
 );%0A%7D

Configure sequelize to use nconf.