-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chg: [migration] minor fix for rerunability
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Migrations\AbstractMigration; | ||
use Phinx\Db\Adapter\MysqlAdapter; | ||
|
||
final class AdminPermissionSplit extends AbstractMigration | ||
{ | ||
public $autoId = false; // turn off automatic `id` column create. We want it to be `int(10) unsigned` | ||
|
||
public function change(): void | ||
{ | ||
$exists = $this->table('roles')->hasColumn('perm_community_admin'); | ||
if (!$exists) { | ||
$this->table('roles') | ||
->addColumn('perm_community_admin', 'boolean', [ | ||
'default' => 0, | ||
'null' => false, | ||
]) | ||
->addIndex('perm_community_admin') | ||
->update(); | ||
} | ||
$builder = $this->getQueryBuilder(); | ||
$builder | ||
->update('roles') | ||
->set('perm_community_admin', true) | ||
->where(['perm_admin' => true]) | ||
->execute(); | ||
} | ||
} |