Skip to content

Commit 25e55a6

Browse files
committed
chg: [migration] minor fix for rerunability
1 parent 93e1af2 commit 25e55a6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Migrations\AbstractMigration;
5+
use Phinx\Db\Adapter\MysqlAdapter;
6+
7+
final class AdminPermissionSplit extends AbstractMigration
8+
{
9+
public $autoId = false; // turn off automatic `id` column create. We want it to be `int(10) unsigned`
10+
11+
public function change(): void
12+
{
13+
$exists = $this->table('roles')->hasColumn('perm_community_admin');
14+
if (!$exists) {
15+
$this->table('roles')
16+
->addColumn('perm_community_admin', 'boolean', [
17+
'default' => 0,
18+
'null' => false,
19+
])
20+
->addIndex('perm_community_admin')
21+
->update();
22+
}
23+
$builder = $this->getQueryBuilder();
24+
$builder
25+
->update('roles')
26+
->set('perm_community_admin', true)
27+
->where(['perm_admin' => true])
28+
->execute();
29+
}
30+
}

0 commit comments

Comments
 (0)