1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Phinx\Db\Adapter\MysqlAdapter; |
4
|
|
|
use Phinx\Migration\AbstractMigration; |
5
|
|
|
|
6
|
|
|
class ExpandTextColumnsToLongtext extends AbstractMigration { |
7
|
|
|
|
8
|
|
|
// Columns that change from text to longtext |
9
|
|
|
private $text_to_longtext = [ |
10
|
|
|
'annotations' => ['value'], |
11
|
|
|
'config' => ['value'], |
12
|
|
|
'groups_entity' => ['description'], |
13
|
|
|
'metadata' => ['value'], |
14
|
|
|
'objects_entity' => ['description'], |
15
|
|
|
'private_settings' => ['value'], |
16
|
|
|
'sites_entity' => ['description'], |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Expand certain columns from text to longtext |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
public function up() { |
|
|
|
|
23
|
|
|
|
24
|
|
|
foreach ($this->text_to_longtext as $table => $columns) { |
25
|
|
|
if (!$this->hasTable($table)) { |
26
|
|
|
continue; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$table = $this->table($table); |
30
|
|
|
|
31
|
|
|
foreach ($columns as $column) { |
32
|
|
|
if ($table->hasColumn($column)) { |
33
|
|
|
$table->changeColumn($column, 'text', [ |
34
|
|
|
'limit' => MysqlAdapter::TEXT_LONG, |
35
|
|
|
]); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$table->save(); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Shirnk certain columns from longtext to text |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public function down() { |
|
|
|
|
47
|
|
|
|
48
|
|
|
foreach ($this->text_to_longtext as $table => $columns) { |
49
|
|
|
if (!$this->hasTable($table)) { |
50
|
|
|
continue; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$table = $this->table($table); |
54
|
|
|
|
55
|
|
|
foreach ($columns as $column) { |
56
|
|
|
if ($table->hasColumn($column)) { |
57
|
|
|
$table->changeColumn($column, 'text', [ |
58
|
|
|
'limit' => MysqlAdapter::TEXT_REGULAR, |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$table->save(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.