1
0
Fork 0
mirror of https://github.com/Oreolek/kohana-migrations.git synced 2024-06-28 20:55:08 +03:00

created possibility of writing generated code directly into migration

This commit is contained in:
Michał Matyas 2011-06-30 14:46:58 +02:00
parent f30cca150b
commit fca8ccdf77
2 changed files with 13 additions and 1 deletions

View file

@ -58,7 +58,7 @@ class Minion_Task_Db_Generate extends Minion_Task
} }
public function generate($config) public function generate($config, $up = null, $down = null)
{ {
$defaults = array( $defaults = array(
'location' => APPPATH, 'location' => APPPATH,
@ -89,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)))

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; ?>
} }
} }