Total Complexity | 4 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | abstract class AddColumnMigration extends CDbMigration |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @return string |
||
15 | */ |
||
16 | abstract protected function getTableName(); |
||
17 | |||
18 | /** |
||
19 | * @return string |
||
20 | */ |
||
21 | abstract protected function getColumnName(); |
||
22 | |||
23 | /** |
||
24 | * @return string |
||
25 | */ |
||
26 | abstract protected function getColumnType(); |
||
27 | |||
28 | public function up() |
||
29 | { |
||
30 | $table = Yii::app()->db->schema->getTable($this->getTableName()); |
||
31 | |||
32 | if ($table === null) |
||
33 | return false; |
||
34 | |||
35 | // Check if column already exists |
||
36 | $columns = $table->getColumnNames(); |
||
37 | |||
38 | if (!in_array($this->getColumnName(), $columns)) |
||
39 | $this->addColumn($this->getTableName(), $this->getColumnName(), $this->getColumnType()); |
||
40 | } |
||
41 | |||
42 | public function down() |
||
48 | } |
||
49 | |||
51 |