1
0
Fork 0
mirror of https://github.com/Oreolek/kohana-migrations.git synced 2024-06-16 15:01:08 +03:00

Give more helpful error messages when a migration fails

This commit is contained in:
Matt Button 2011-01-21 00:45:35 +00:00
parent 95e450c43e
commit f47bce9bc8
4 changed files with 57 additions and 3 deletions

View file

@ -0,0 +1,33 @@
<?php
/**
* Minion exception, thrown during a migration error
*/
class Minion_Migration_Exception extends Kohana_Exception {
protected $_migration = array();
/**
* Constructor
*
*/
public function __construct($message, array $migration, array $variables = array(), $code = 0)
{
$variables[':migration-id'] = $migration['id'];
$variables[':migration-location'] = $migration['location'];
$this->_migration = $migration;
parent::__construct($message, $variables, $code);
}
/**
* Get the migration that caused this exception to be thrown
*
* @return array
*/
public function get_migration()
{
return $this->_migration;
}
}

View file

@ -182,7 +182,15 @@ class Minion_Migration_Manager {
$db = $this->_get_db_instance($instance->get_database_connection());
$instance->$method($db);
try
{
$instance->$method($db);
}
catch(Database_Exception $e)
{
throw new Minion_Migration_Exception($e->getMessage(), $migration);
}
if($this->_dry_run)
{

View file

@ -89,10 +89,20 @@ class Minion_Task_Db_Migrate extends Minion_Task
// Sync the available migrations with those in the db
->sync_migration_files()
->set_dry_run($dry_run)
->set_dry_run($dry_run);
try
{
// Run migrations for specified locations & versions
->run_migration($locations, $targets, $this->_default_direction);
$manager->run_migration($locations, $targets, $this->_default_direction);
}
catch(Minion_Migration_Exception $e)
{
return View::factory('minion/task/db/migrate/exception')
->set('migration', $e->get_migration())
->set('error', $e->getMessage());
}
$view = View::factory('minion/task/db/migrate')
->set('dry_run', $dry_run)

View file

@ -0,0 +1,3 @@
Minion encountered an error while executing migration `<?php echo $migration['id']; ?>` (<?php echo $migration['description'] ?>):
<?php echo $error; ?>