mirror of
https://github.com/Oreolek/kohana-migrations.git
synced 2024-05-18 17:08:18 +03:00
Renaming 'module' to 'location' in migration related code, makes more sense
This commit is contained in:
parent
9b0e6d7555
commit
8cadcbf309
|
@ -47,7 +47,7 @@ class Minion_Migration_Manager {
|
|||
*
|
||||
* migration_id => array(
|
||||
* 'file' => migration_file,
|
||||
* 'module' => migration_module
|
||||
* 'location' => migration_location
|
||||
* );
|
||||
*
|
||||
* @param return array
|
||||
|
|
|
@ -30,7 +30,7 @@ class Minion_Migration_Util {
|
|||
{
|
||||
$migration = Minion_Migration_Util::extract_migration_info_from_filename($file);
|
||||
|
||||
$migrations[$migration['id']] = array('file' => $file, 'module' => $migration['module']);
|
||||
$migrations[$migration['id']] = array('file' => $file, 'location' => $migration['location']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,9 +43,9 @@ class Minion_Migration_Util {
|
|||
* Returns an array like:
|
||||
*
|
||||
* array(
|
||||
* 'module' => 'mymodule',
|
||||
* 'location' => 'mylocation',
|
||||
* 'id' => '1293214439_initial-setup',
|
||||
* 'file' => 'migrations/mymodule/1293214439_initial-setup.php',
|
||||
* 'file' => 'migrations/mylocation/1293214439_initial-setup.php',
|
||||
* 'timestamp' => '1293214439',
|
||||
* 'description' => 'initial-setup',
|
||||
* );
|
||||
|
@ -58,9 +58,9 @@ class Minion_Migration_Util {
|
|||
$migration = array();
|
||||
|
||||
// Get rid of the file's "migrations/" prefix, the file extension and then
|
||||
// the filename itself. The "module" is essentially a slash delimited
|
||||
// the filename itself. The "location" is essentially a slash delimited
|
||||
// path from the migrations folder to the migration file
|
||||
$migration['module'] = dirname(substr($file, 11, -strlen(EXT)));
|
||||
$migration['location'] = dirname(substr($file, 11, -strlen(EXT)));
|
||||
$migration['id'] = basename($file, EXT);
|
||||
$migration['file'] = $file;
|
||||
|
||||
|
@ -71,21 +71,21 @@ class Minion_Migration_Util {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets a migration file from its timestamp, description and module
|
||||
* Gets a migration file from its timestamp, description and location
|
||||
*
|
||||
* @param integer|array The migration's ID or an array of timestamp, description
|
||||
* @param string The migration module
|
||||
* @param string The migration location
|
||||
* @return string Path to the migration file
|
||||
*/
|
||||
public static function convert_migration_to_filename($migration, $module)
|
||||
public static function convert_migration_to_filename($migration, $location)
|
||||
{
|
||||
if(is_array($migration))
|
||||
{
|
||||
$migration = implode('_', $migration);
|
||||
}
|
||||
|
||||
$module = ! empty($module) ? rtrim($module, '/').'/' : '';
|
||||
$location = ! empty($location) ? rtrim($location, '/').'/' : '';
|
||||
|
||||
return 'migrations/'.$module.$migration.EXT;
|
||||
return 'migrations/'.$location.$migration.EXT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,11 @@
|
|||
* The version to which the database should be migrated. If this is NULL then
|
||||
* it will be updated to the latest available version
|
||||
*
|
||||
* db:migrate:modules=module[,module2[,module3...]]
|
||||
* db:migrate:locations=location[,location2[,location3...]]
|
||||
*
|
||||
* A list of modules that will be used to source migration files. By default
|
||||
* migrations will be loaded from all enabled modules
|
||||
* A list of locations (under the migrations folder in the cascading
|
||||
* filesystem) that will be used to source migration files. By default
|
||||
* migrations will be loaded from all available locations
|
||||
*
|
||||
* @author Matt Button <matthew@sigswitch.com>
|
||||
*/
|
||||
|
@ -30,7 +31,7 @@ class Minion_Task_Db_Migrate extends Minion_Task
|
|||
{
|
||||
return array(
|
||||
'version',
|
||||
'modules',
|
||||
'locations',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,9 +52,9 @@ class Model_Minion_Migration extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Fetches the latest version for all installed modules
|
||||
* Fetches the latest version for all installed locations
|
||||
*
|
||||
* If a module does not have any applied migrations then no result will be
|
||||
* If a location does not have any applied migrations then no result will be
|
||||
* returned for it
|
||||
*
|
||||
* @return Kohana_Database_Result
|
||||
|
@ -63,7 +63,7 @@ class Model_Minion_Migration extends Model
|
|||
{
|
||||
return $this->_select()
|
||||
->where('applied', '>', 0)
|
||||
->group_by('module')
|
||||
->group_by('location')
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
@ -71,25 +71,25 @@ class Model_Minion_Migration extends Model
|
|||
* Fetch a list of migrations that need to be applied in order to reach the
|
||||
* required version
|
||||
*
|
||||
* @param string Migration's Module
|
||||
* @param string Migration's location
|
||||
* @param string Target migration id
|
||||
*/
|
||||
public function fetch_required_migrations($modules = NULL, $target = NULL)
|
||||
public function fetch_required_migrations($locations = NULL, $target = NULL)
|
||||
{
|
||||
if( ! empty($modules) AND ! is_array($modules))
|
||||
if( ! empty($locations) AND ! is_array($locations))
|
||||
{
|
||||
$modules = array($modules => $target);
|
||||
$locations = array($locations => $target);
|
||||
}
|
||||
|
||||
// Get an array of the latest migrations, with the module name as the
|
||||
// Get an array of the latest migrations, with the location name as the
|
||||
// array key
|
||||
$migrations = $this->fetch_current_versions()->as_array('module');
|
||||
$migrations = $this->fetch_current_versions()->as_array('location');
|
||||
|
||||
if(empty($modules))
|
||||
if(empty($locations))
|
||||
{
|
||||
$keys = array_keys($migrations);
|
||||
|
||||
$modules = array_combine($keys, $keys);
|
||||
$locations = array_combine($keys, $keys);
|
||||
}
|
||||
|
||||
$migrations_to_apply = array();
|
||||
|
@ -99,29 +99,29 @@ class Model_Minion_Migration extends Model
|
|||
// Basically we need to get a list of migrations that need to be performed, but
|
||||
// the ordering of the migrations varies depending on whether we're wanting to
|
||||
// migrate up or migrate down. As such, we can't just apply a generic "order by x"
|
||||
// condition, we have to run an individual query for each module
|
||||
// condition, we have to run an individual query for each location
|
||||
//
|
||||
// Again, icky, but this appears to be the only "sane" way of doing it with multiple
|
||||
// modules
|
||||
// locations
|
||||
//
|
||||
// If you have a better way of doing this, please let me know :)
|
||||
|
||||
foreach($modules as $module => $target)
|
||||
foreach($locations as $location => $target)
|
||||
{
|
||||
// By default all migrations go "up"
|
||||
$migrations_to_apply[$module]['direction'] = 1;
|
||||
$migrations_to_apply[$module]['migrations'] = array();
|
||||
$migrations_to_apply[$location]['direction'] = 1;
|
||||
$migrations_to_apply[$location]['migrations'] = array();
|
||||
|
||||
$query = $this->_select()->and_where('module', '=', $module);
|
||||
$query = $this->_select()->and_where('location', '=', $location);
|
||||
|
||||
// one of these conditions occurs if
|
||||
// a) the user specified they want to bring this module up to date
|
||||
// a) the user specified they want to bring this location up to date
|
||||
// or
|
||||
// b) if they just want to bring all modules up to date
|
||||
// b) if they just want to bring all locations up to date
|
||||
//
|
||||
// Basically this checks that the user hasn't explicitly specified a version
|
||||
// to migrate to
|
||||
if($target === NULL OR $target === $module)
|
||||
if($target === NULL OR $target === $location)
|
||||
{
|
||||
$query->order_by('timestamp', 'ASC');
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ class Model_Minion_Migration extends Model
|
|||
{
|
||||
list($timestamp, $description) = explode('_', $target, 2);
|
||||
|
||||
$current_timestamp = isset($migrations[$module]) ? $migrations[$module]['timestamp'] : NULL;
|
||||
$current_timestamp = isset($migrations[$location]) ? $migrations[$location]['timestamp'] : NULL;
|
||||
|
||||
// If the current version is the requested version then nothing needs to be done
|
||||
if($current_timestamp === $timestamp)
|
||||
|
@ -138,9 +138,9 @@ class Model_Minion_Migration extends Model
|
|||
continue;
|
||||
}
|
||||
|
||||
$query->and_where('module', '=', $module);
|
||||
$query->and_where('location', '=', $location);
|
||||
|
||||
// If they haven't applied any migrations for this module
|
||||
// If they haven't applied any migrations for this location
|
||||
// yet and are just wanting to apply all migrations (i.e. roll forward)
|
||||
if($current_timestamp === NULL)
|
||||
{
|
||||
|
@ -165,13 +165,13 @@ class Model_Minion_Migration extends Model
|
|||
->and_where('applied', '=', 1)
|
||||
->order_by('timestamp', 'DESC');
|
||||
|
||||
$migrations_to_apply[$module]['direction'] = -1;
|
||||
$migrations_to_apply[$location]['direction'] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($query->execute($this->_db) as $row)
|
||||
{
|
||||
$migrations_to_apply[$module]['migrations'][] = $row;
|
||||
$migrations_to_apply[$location]['migrations'][] = $row;
|
||||
}
|
||||
|
||||
unset($query);
|
||||
|
|
|
@ -17,15 +17,15 @@ class Minion_Migration_UtilTest extends Kohana_Unittest_TestCase {
|
|||
return array(
|
||||
array(
|
||||
array(
|
||||
'015151051_setup' => array('file' => 'migrations/myapp/015151051_setup.php', 'module' => 'myapp'),
|
||||
'015161051_add-comments' => array('file' => 'migrations/myapp/015161051_add-comments.php', 'module' => 'myapp'),
|
||||
'015151051_setup' => array('file' => 'migrations/myapp/015151051_setup.php', 'location' => 'myapp'),
|
||||
'015161051_add-comments' => array('file' => 'migrations/myapp/015161051_add-comments.php', 'location' => 'myapp'),
|
||||
),
|
||||
array(
|
||||
'migrations/myapp' => array(
|
||||
'migrations/myapp/015151051_setup.php'
|
||||
=> '/var/www/app/modules/myapp/migrations/myapp/015151051_setup.php',
|
||||
=> '/var/www/app/locations/myapp/migrations/myapp/015151051_setup.php',
|
||||
'migrations/myapp/015161051_add-comments.php'
|
||||
=> '/var/www/app/modules/myapp/migrations/myapp/015161051_add-comments.php',
|
||||
=> '/var/www/app/locations/myapp/migrations/myapp/015161051_add-comments.php',
|
||||
),
|
||||
)
|
||||
),
|
||||
|
@ -60,7 +60,7 @@ class Minion_Migration_UtilTest extends Kohana_Unittest_TestCase {
|
|||
return array(
|
||||
array(
|
||||
array(
|
||||
'module' => 'myapp',
|
||||
'location' => 'myapp',
|
||||
'id' => '1293214439_initial-setup',
|
||||
'file' => 'migrations/myapp/1293214439_initial-setup.php',
|
||||
'description' => 'initial-setup',
|
||||
|
@ -114,13 +114,13 @@ class Minion_Migration_UtilTest extends Kohana_Unittest_TestCase {
|
|||
* @dataProvider provider_convert_migration_to_filename
|
||||
* @param string Expected output
|
||||
* @param mixed Migration id
|
||||
* @param mixed Module
|
||||
* @param mixed location
|
||||
*/
|
||||
public function test_convert_migration_to_filename($expected, $migration, $module)
|
||||
public function test_convert_migration_to_filename($expected, $migration, $location)
|
||||
{
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
Minion_Migration_Util::convert_migration_to_filename($migration, $module)
|
||||
Minion_Migration_Util::convert_migration_to_filename($migration, $location)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue