chg: [migration] minor fix for rerunability

pull/170/merge v1.22
iglocska 2024-08-24 15:47:53 +02:00
parent 93e1af2218
commit 25e55a620b
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 30 additions and 0 deletions

View File

@ -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();
}
}