2011-01-31 19:38:04 +02:00
|
|
|
<?php defined('SYSPATH') or die('No direct script access.');
|
2010-12-24 17:52:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The base migration class, must be extended by all migration files
|
|
|
|
*
|
|
|
|
* Each migration file must implement an up() and a down() which are used to
|
|
|
|
* apply / remove this migration from the schema respectively
|
|
|
|
*
|
|
|
|
* @author Matt Button <matthew@sigswitch.com>
|
|
|
|
*/
|
|
|
|
abstract class Minion_Migration_Base {
|
|
|
|
|
2011-01-10 18:01:40 +02:00
|
|
|
/**
|
|
|
|
* Array of information about this migration
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $_info = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs the migration
|
|
|
|
*
|
|
|
|
* @param array Information about this migration
|
|
|
|
*/
|
|
|
|
public function __construct(array $info)
|
|
|
|
{
|
|
|
|
$this->_info = $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the name of the database connection group this migration should be run against
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_database_connection()
|
|
|
|
{
|
2011-06-27 22:57:21 +03:00
|
|
|
$config = Kohana::$config->load('minion/migration');
|
2011-02-17 22:43:04 +02:00
|
|
|
$group = $this->_info['group'];
|
2011-01-10 18:01:40 +02:00
|
|
|
|
2011-02-17 22:43:04 +02:00
|
|
|
if (isset($config->group_connection[$group]))
|
2011-01-10 18:01:40 +02:00
|
|
|
{
|
2011-02-17 22:43:04 +02:00
|
|
|
return $config->group_connection[$group];
|
2011-01-10 18:01:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Database::$default;
|
|
|
|
}
|
|
|
|
|
2010-12-24 17:52:03 +02:00
|
|
|
/**
|
|
|
|
* Runs any SQL queries necessary to bring the database up a migration version
|
|
|
|
*
|
2010-12-24 19:35:17 +02:00
|
|
|
* @param Kohana_Database The database connection to perform actions on
|
2010-12-24 17:52:03 +02:00
|
|
|
*/
|
2010-12-24 19:35:17 +02:00
|
|
|
abstract public function up(Kohana_Database $db);
|
2010-12-24 17:52:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs any SQL queries necessary to bring the database schema down a version
|
|
|
|
*
|
2010-12-24 19:35:17 +02:00
|
|
|
* @param Kohana_Database The database connection to perform actions on
|
2010-12-24 17:52:03 +02:00
|
|
|
*/
|
2010-12-24 19:35:17 +02:00
|
|
|
abstract public function down(Kohana_Database $db);
|
2010-12-24 17:52:03 +02:00
|
|
|
}
|