1
|
|
|
<?php defined('SYSPATH') OR die('No direct script access.'); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Generate a migration file |
5
|
|
|
* |
6
|
|
|
* Based on the name of the migration it will be populated with appropraite commands: |
7
|
|
|
* |
8
|
|
|
* - add_<column>_and_<column>_to_<table> |
9
|
|
|
* - remove_<column>_and_<column>_from_<table> |
10
|
|
|
* - drop_table_<table> |
11
|
|
|
* - rename_table_<table>_to_<new table> |
12
|
|
|
* - rename_<column>_to_<new column>_in_<table> |
13
|
|
|
* - change_<column>_in_<table> |
14
|
|
|
* |
15
|
|
|
* You can also chain those together with also: |
16
|
|
|
* |
17
|
|
|
* add_<column>_to_<table>_also_drop_table_<table> |
18
|
|
|
* |
19
|
|
|
* Additionally based on column names it will try to guess the type, using 'string' by default: |
20
|
|
|
* |
21
|
|
|
* - ..._id, ..._count, ..._width, ..._height, ..._x, ..._y, id or position - integer |
22
|
|
|
* - ..._at - datetime |
23
|
|
|
* - ..._on - date |
24
|
|
|
* - is_... - boolean |
25
|
|
|
* - description or text - text |
26
|
|
|
* |
27
|
|
|
* options: |
28
|
|
|
* - name: required paramter - the name of the migration |
29
|
|
|
*/ |
30
|
|
|
class Task_DB_Generate extends Minion_Task { |
31
|
|
|
|
32
|
|
|
protected $_options = array( |
33
|
|
|
'name' => NULL, |
34
|
|
|
'template' => NULL, |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
public function build_validation(Validation $validation) |
38
|
|
|
{ |
39
|
|
|
return parent::build_validation($validation) |
40
|
|
|
->rule('name', 'not_empty'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function _execute(array $options) |
44
|
|
|
{ |
45
|
|
|
$migrations = new Migrations(array('log' => 'Minion_CLI::write')); |
46
|
|
|
|
47
|
|
|
$migration = $migrations->generate_new_migration_file($options['name'], $options['template']); |
48
|
|
|
|
49
|
|
|
Minion_CLI::write(Minion_CLI::color($migration, 'green').Minion_CLI::color(' Migration File Generated', 'brown')); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|