Skip to content

Commit

Permalink
chg: [migration] minor fix for rerunability
Browse files Browse the repository at this point in the history
  • Loading branch information
iglocska committed Aug 24, 2024
1 parent 93e1af2 commit 25e55a6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions config/Migrations/20240719000003_AdminPermissionSplit.php
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();
}
}

0 comments on commit 25e55a6

Please sign in to comment.