Skip to content

Commit 12a81bb

Browse files
authored
Merge pull request #442 from GustavoPeixoto/cake4
fixed MysqlAdapter check in Utf8mb4Fix migration
2 parents 0d61cb1 + 30ac11c commit 12a81bb

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
use Cake\Error\Debugger;
4+
use Phinx\Db\Adapter\AdapterInterface;
5+
use Phinx\Db\Adapter\AdapterWrapper;
6+
use Phinx\Db\Adapter\MysqlAdapter;
7+
use Phinx\Migration\AbstractMigration;
8+
9+
class DataColumnLength extends AbstractMigration {
10+
11+
/**
12+
* Change Method.
13+
*
14+
* Write your reversible migrations using this method.
15+
*
16+
* More information on writing migrations is available here:
17+
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
18+
*
19+
* @return void
20+
*/
21+
public function change() {
22+
if ($this->getUnwrappedAdapter() instanceof MysqlAdapter) {
23+
try {
24+
$table = $this->table('queued_jobs');
25+
$table->changeColumn('data', 'text', [
26+
'limit' => MysqlAdapter::TEXT_MEDIUM,
27+
'null' => true,
28+
'default' => null,
29+
'encoding' => 'utf8mb4',
30+
'collation' => 'utf8mb4_unicode_ci',
31+
]);
32+
$table->changeColumn('failure_message', 'text', [
33+
'limit' => MysqlAdapter::TEXT_MEDIUM,
34+
'null' => true,
35+
'default' => null,
36+
'encoding' => 'utf8mb4',
37+
'collation' => 'utf8mb4_unicode_ci',
38+
]);
39+
$table->update();
40+
} catch (Exception $e) {
41+
Debugger::dump($e->getMessage());
42+
}
43+
}
44+
}
45+
46+
/**
47+
* Gets the unwrapped adapter
48+
*
49+
* @return \Phinx\Db\Adapter\AdapterInterface|null
50+
*/
51+
private function getUnwrappedAdapter(): ?AdapterInterface {
52+
$adapter = $this->adapter;
53+
54+
while ($adapter instanceof AdapterWrapper) {
55+
$adapter = $adapter->getAdapter();
56+
}
57+
58+
return $adapter;
59+
}
60+
61+
}

0 commit comments

Comments
 (0)