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

Merge remote branch 'minion/3.1/develop' into 3.2/develop

This commit is contained in:
Lorenzo Pisani 2011-07-01 20:33:25 -07:00
commit a6fd63a035
5 changed files with 49 additions and 11 deletions

View file

@ -61,9 +61,16 @@ class Minion_Migration_Util {
// path from the migrations folder to the migration file // path from the migrations folder to the migration file
$migration['group'] = dirname(substr($file, 11, -strlen(EXT))); $migration['group'] = dirname(substr($file, 11, -strlen(EXT)));
list($migration['timestamp'], $migration['description']) if(strpos(basename($file), "_"))
= explode('_', basename($file, EXT), 2); {
list($migration['timestamp'], $migration['description'])
= explode('_', basename($file, EXT), 2);
}
else
{
$migration['timestamp'] = basename($file, EXT);
$migration['description'] = "";
}
$migration['id'] = $migration['group'].':'.$migration['timestamp']; $migration['id'] = $migration['group'].':'.$migration['timestamp'];
return $migration; return $migration;
@ -79,7 +86,15 @@ class Minion_Migration_Util {
public static function get_filename_from_migration(array $migration) public static function get_filename_from_migration(array $migration)
{ {
$group = $migration['group']; $group = $migration['group'];
$migration = $migration['timestamp'].'_'.$migration['description'];
if(!empty($migration['description']))
{
$migration = $migration['timestamp'].'_'.$migration['description'];
}
else
{
$migration = $migration['timestamp'];
}
$group = ( ! empty($group)) ? (rtrim($group, '/').'/') : ''; $group = ( ! empty($group)) ? (rtrim($group, '/').'/') : '';

View file

@ -45,6 +45,20 @@ class Minion_Task_Db_Generate extends Minion_Task
* @param array Configuration * @param array Configuration
*/ */
public function execute(array $config) public function execute(array $config)
{
try
{
$file = $this->generate($config);
Minion_CLI::write('Migration generated: '.$file);
}
catch(ErrorException $e)
{
Minion_CLI::write($e->getMessage());
}
}
public function generate($config, $up = null, $down = null)
{ {
$defaults = array( $defaults = array(
'location' => APPPATH, 'location' => APPPATH,
@ -59,9 +73,7 @@ class Minion_Task_Db_Generate extends Minion_Task
if ( ! $this->_valid_group($config['group'])) if ( ! $this->_valid_group($config['group']))
{ {
Minion_CLI::write('Please provide a valid --group'); throw new ErrorException("Please provide a valid --group\nSee help for more info");
Minion_CLI::write('See help for more info');
return;
} }
$group = $config['group'].'/'; $group = $config['group'].'/';
@ -77,6 +89,8 @@ class Minion_Task_Db_Generate extends Minion_Task
$data = Kohana::FILE_SECURITY.View::factory('minion/task/db/generate/template') $data = Kohana::FILE_SECURITY.View::factory('minion/task/db/generate/template')
->set('class', $class) ->set('class', $class)
->set('description', $description) ->set('description', $description)
->set('up', $up)
->set('down', $down)
->render(); ->render();
if ( ! is_dir(dirname($file))) if ( ! is_dir(dirname($file)))
@ -86,8 +100,7 @@ class Minion_Task_Db_Generate extends Minion_Task
file_put_contents($file, $data); file_put_contents($file, $data);
Minion_CLI::write('Migration generated: '.$file); return $file;
return;
} }
/** /**

View file

@ -12,7 +12,12 @@ class <?php echo $class; ?> extends Minion_Migration_Base {
*/ */
public function up(Kohana_Database $db) public function up(Kohana_Database $db)
{ {
<?php if(!empty($up)): ?>
<?php echo $up; ?>
<?php else: ?>
// $db->query(NULL, 'CREATE TABLE ... '); // $db->query(NULL, 'CREATE TABLE ... ');
<?php endif; ?>
} }
/** /**
@ -22,6 +27,11 @@ class <?php echo $class; ?> extends Minion_Migration_Base {
*/ */
public function down(Kohana_Database $db) public function down(Kohana_Database $db)
{ {
<?php if(!empty($down)): ?>
<?php echo $down; ?>
<?php else: ?>
// $db->query(NULL, 'DROP TABLE ... '); // $db->query(NULL, 'DROP TABLE ... ');
<?php endif; ?>
} }
} }

View file

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

View file

@ -1,4 +1,4 @@
<?php foreach($groups as $group => $status): ?> <?php foreach($groups as $group => $status): ?>
* <?php echo $group ?> <?php echo ($status !== NULL ? $status['timestamp'].' ('.$status['description'].')' : 'Not installed'); ?> * <?php echo $group ?> <?php echo ($status !== NULL ? $status['timestamp'].' '.( !empty($status['description']) ? '('.$status['description'].')' : '' ) : 'Not installed'); ?>
<?php endforeach; ?> <?php endforeach; ?>