Migrations logic and custom configs

My migrations are failing with Error: Cannot load database configuration. I have my config setup like this... config.ini, development.ini & production.ini. Within config.ini I have a variable I can set to either "debelopment" or "production". Then in Bootstrap.php I have the following;

protected function config()
    $config = new \Phalcon\Config\Adapter\Ini(APP_PATH . '/app/common/config/config.ini');
    $this->_di->set('config', $config);
    if($this->config->app->env == 'development'){
        $dev = new \Phalcon\Config\Adapter\Ini(APP_PATH . '/app/common/config/development.ini');
        $prod = new \Phalcon\Config\Adapter\Ini(APP_PATH . '/app/common/config/production.ini');
    $this->_config = $config;

This is probably why migrations are failing. My development database and production database have different credentials. What ligic does devtools migrations use to find the database configurations?

edited Oct '15

Here's logic from the source: https://github.com/phalcon/phalcon-devtools/blob/c2e5aff43aa4fbf919abd13bb7d0ef80efb83f57/scripts/Phalcon/Commands/Command.php#L134

One more important thing to note is that the key should be named database and be on the first level of the config!


Thanks Lajos.