mirror of
https://github.com/Oreolek/kohana-migrations.git
synced 2024-06-26 03:40:54 +03:00
Fixed a few bugs and added sensible funtionality:
* Fixed a bug where already appled migrations would be selected when asked to bring a location up to latest version * You can now use booleans to get migrations needed to migrate to one of two extremes (TRUE = latest, FALSE = undo everything) * If you're rolling back to a version then you don't want to execute the down() for that migration
This commit is contained in:
parent
8cadcbf309
commit
9e6cfc6a59
|
@ -74,7 +74,7 @@ class Model_Minion_Migration extends Model
|
||||||
* @param string Migration's location
|
* @param string Migration's location
|
||||||
* @param string Target migration id
|
* @param string Target migration id
|
||||||
*/
|
*/
|
||||||
public function fetch_required_migrations($locations = NULL, $target = NULL)
|
public function fetch_required_migrations($locations = NULL, $target = TRUE)
|
||||||
{
|
{
|
||||||
if( ! empty($locations) AND ! is_array($locations))
|
if( ! empty($locations) AND ! is_array($locations))
|
||||||
{
|
{
|
||||||
|
@ -112,7 +112,7 @@ class Model_Minion_Migration extends Model
|
||||||
$migrations_to_apply[$location]['direction'] = 1;
|
$migrations_to_apply[$location]['direction'] = 1;
|
||||||
$migrations_to_apply[$location]['migrations'] = array();
|
$migrations_to_apply[$location]['migrations'] = array();
|
||||||
|
|
||||||
$query = $this->_select()->and_where('location', '=', $location);
|
$query = $this->_select()->where('location', '=', $location);
|
||||||
|
|
||||||
// one of these conditions occurs if
|
// one of these conditions occurs if
|
||||||
// a) the user specified they want to bring this location up to date
|
// a) the user specified they want to bring this location up to date
|
||||||
|
@ -121,9 +121,24 @@ class Model_Minion_Migration extends Model
|
||||||
//
|
//
|
||||||
// Basically this checks that the user hasn't explicitly specified a version
|
// Basically this checks that the user hasn't explicitly specified a version
|
||||||
// to migrate to
|
// to migrate to
|
||||||
if($target === NULL OR $target === $location)
|
if(is_bool($target) OR $target === $location)
|
||||||
{
|
{
|
||||||
$query->order_by('timestamp', 'ASC');
|
// We're "undoing" all applied migrations, i.e. rolling back
|
||||||
|
if($target === FALSE)
|
||||||
|
{
|
||||||
|
$migrations_to_apply[$location]['direction'] = -1;
|
||||||
|
|
||||||
|
$query
|
||||||
|
->where('applied', '=', 1)
|
||||||
|
->order_by('timestamp', 'DESC');
|
||||||
|
}
|
||||||
|
// We're rolling forward
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$query
|
||||||
|
->where('applied', '=', 0)
|
||||||
|
->order_by('timestamp', 'ASC');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Else if the user explicitly specified a target version of some kind
|
// Else if the user explicitly specified a target version of some kind
|
||||||
else
|
else
|
||||||
|
@ -138,10 +153,10 @@ class Model_Minion_Migration extends Model
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query->and_where('location', '=', $location);
|
$query->where('location', '=', $location);
|
||||||
|
|
||||||
// If they haven't applied any migrations for this location
|
// If they haven't applied any migrations for this location
|
||||||
// yet and are just wanting to apply all migrations (i.e. roll forward)
|
// yet and are justwhere wanting to apply all migrations (i.e. roll forward)
|
||||||
if($current_timestamp === NULL)
|
if($current_timestamp === NULL)
|
||||||
{
|
{
|
||||||
$query
|
$query
|
||||||
|
@ -152,7 +167,7 @@ class Model_Minion_Migration extends Model
|
||||||
elseif($timestamp > $current_timestamp)
|
elseif($timestamp > $current_timestamp)
|
||||||
{
|
{
|
||||||
$query
|
$query
|
||||||
->and_where('timestamp', '<=', $timestamp)
|
->and_where('timestamp', '<=', $timestamp)
|
||||||
->and_where('applied', '=', 0)
|
->and_where('applied', '=', 0)
|
||||||
->order_by('timestamp', 'ASC');
|
->order_by('timestamp', 'ASC');
|
||||||
}
|
}
|
||||||
|
@ -161,7 +176,7 @@ class Model_Minion_Migration extends Model
|
||||||
{
|
{
|
||||||
$query
|
$query
|
||||||
->and_where('timestamp', '<', $current_timestamp)
|
->and_where('timestamp', '<', $current_timestamp)
|
||||||
->and_where('timestamp', '>=', $timestamp)
|
->and_where('timestamp', '>', $timestamp)
|
||||||
->and_where('applied', '=', 1)
|
->and_where('applied', '=', 1)
|
||||||
->order_by('timestamp', 'DESC');
|
->order_by('timestamp', 'DESC');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue