1
0
Fork 0
mirror of https://github.com/Oreolek/kohana-migrations.git synced 2024-06-30 21:55:05 +03:00

Migration model wasn't using correct target version when downgrading all locations. Adding a bugfix & test

This commit is contained in:
Matt Button 2010-12-28 17:40:40 +00:00
parent 5fd227becd
commit 14ac8a4047
2 changed files with 29 additions and 6 deletions

View file

@ -81,12 +81,14 @@ class Model_Minion_Migration extends Model
* @param string Target migration id * @param string Target migration id
* @param boolean Default direction of versionless migrations * @param boolean Default direction of versionless migrations
*/ */
public function fetch_required_migrations($locations = NULL, $target = TRUE, $default_direction = TRUE) public function fetch_required_migrations($locations = NULL, $target_version = TRUE, $default_direction = TRUE)
{ {
if( ! empty($locations) AND ! is_array($locations)) if( ! empty($locations) AND ! is_array($locations))
{ {
$locations = array( $locations = array(
$locations => is_array($target) ? $default_direction : $target $locations => is_array($target_version)
? $default_direction
: $target_version
); );
} }
@ -103,9 +105,9 @@ class Model_Minion_Migration extends Model
} }
// Merge locations with specified target versions // Merge locations with specified target versions
if( ! empty($target) AND is_array($target)) if( ! empty($target_version) AND is_array($target_version))
{ {
$locations = $target + $locations; $locations = $target_version + $locations;
} }
$migrations_to_apply = array(); $migrations_to_apply = array();
@ -134,7 +136,9 @@ class Model_Minion_Migration extends Model
// default migration direction // default migration direction
if($target === $location) if($target === $location)
{ {
$target = (bool) $default_direction; $target = is_bool($target_version)
? $target_version
: (bool) $default_direction;
} }
// If the user is rolling this location to either extreme up or // If the user is rolling this location to either extreme up or

View file

@ -134,8 +134,27 @@ class Minion_Migration_ModelTest extends Kohana_Unittest_Database_TestCase
), ),
) )
), ),
'dblogger' => array(
'direction' => FALSE,
'migrations' => array(
array(
'timestamp' => '1293544858',
'description' => 'remove-unique-index',
'location' => 'dblogger',
'applied' => '1',
'id' => '1293544858_remove-unique-index',
),
array(
'timestamp' => '1293543858',
'description' => 'create-table',
'location' => 'dblogger',
'applied' => '1',
'id' => '1293543858_create-table',
),
)
),
), ),
'app', NULL,
FALSE, FALSE,
TRUE TRUE
), ),