mirror of
https://github.com/Oreolek/kohana-migrations.git
synced 2024-05-24 11:58:11 +03:00
Merge remote branch 'minion/3.1/develop' into 3.2/develop
This commit is contained in:
commit
a6fd63a035
|
@ -61,9 +61,16 @@ class Minion_Migration_Util {
|
|||
// path from the migrations folder to the migration file
|
||||
$migration['group'] = dirname(substr($file, 11, -strlen(EXT)));
|
||||
|
||||
list($migration['timestamp'], $migration['description'])
|
||||
= explode('_', basename($file, EXT), 2);
|
||||
|
||||
if(strpos(basename($file), "_"))
|
||||
{
|
||||
list($migration['timestamp'], $migration['description'])
|
||||
= explode('_', basename($file, EXT), 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$migration['timestamp'] = basename($file, EXT);
|
||||
$migration['description'] = "";
|
||||
}
|
||||
$migration['id'] = $migration['group'].':'.$migration['timestamp'];
|
||||
|
||||
return $migration;
|
||||
|
@ -79,7 +86,15 @@ class Minion_Migration_Util {
|
|||
public static function get_filename_from_migration(array $migration)
|
||||
{
|
||||
$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, '/').'/') : '';
|
||||
|
||||
|
|
|
@ -45,6 +45,20 @@ class Minion_Task_Db_Generate extends Minion_Task
|
|||
* @param array Configuration
|
||||
*/
|
||||
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(
|
||||
'location' => APPPATH,
|
||||
|
@ -59,9 +73,7 @@ class Minion_Task_Db_Generate extends Minion_Task
|
|||
|
||||
if ( ! $this->_valid_group($config['group']))
|
||||
{
|
||||
Minion_CLI::write('Please provide a valid --group');
|
||||
Minion_CLI::write('See help for more info');
|
||||
return;
|
||||
throw new ErrorException("Please provide a valid --group\nSee help for more info");
|
||||
}
|
||||
|
||||
$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')
|
||||
->set('class', $class)
|
||||
->set('description', $description)
|
||||
->set('up', $up)
|
||||
->set('down', $down)
|
||||
->render();
|
||||
|
||||
if ( ! is_dir(dirname($file)))
|
||||
|
@ -86,8 +100,7 @@ class Minion_Task_Db_Generate extends Minion_Task
|
|||
|
||||
file_put_contents($file, $data);
|
||||
|
||||
Minion_CLI::write('Migration generated: '.$file);
|
||||
return;
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,12 @@ class <?php echo $class; ?> extends Minion_Migration_Base {
|
|||
*/
|
||||
public function up(Kohana_Database $db)
|
||||
{
|
||||
<?php if(!empty($up)): ?>
|
||||
<?php echo $up; ?>
|
||||
|
||||
<?php else: ?>
|
||||
// $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)
|
||||
{
|
||||
<?php if(!empty($down)): ?>
|
||||
<?php echo $down; ?>
|
||||
|
||||
<?php else: ?>
|
||||
// $db->query(NULL, 'DROP TABLE ... ');
|
||||
<?php endif; ?>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; ?>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?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; ?>
|
||||
|
|
Loading…
Reference in a new issue