fix: [migration] userorg migration fixed

pull/92/head
iglocska 2021-11-24 23:36:24 +01:00
parent c7768921fb
commit 94457d3b97
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 10 additions and 13 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Phinx\Migration\AbstractMigration; use Migrations\AbstractMigration;
final class UserOrg extends AbstractMigration final class UserOrg extends AbstractMigration
{ {
@ -18,18 +18,15 @@ final class UserOrg extends AbstractMigration
*/ */
public function change(): void public function change(): void
{ {
$exists = $this->hasTable('users'); $alignments = $this->table('users')
if (!$exists) { ->addColumn('organisation_id', 'integer', [
$alignments = $this->table('users') 'default' => null,
->addColumn('organisation_id', 'integer', [ 'null' => true,
'default' => null, 'signed' => false,
'null' => true, 'length' => 10
'signed' => false, ])
'length' => 10 ->addIndex('org_id')
]) ->update();
->addIndex('org_id')
->update();
}
$q1 = $this->getQueryBuilder(); $q1 = $this->getQueryBuilder();
$org_id = $q1->select(['min(id)'])->from('organisations')->execute()->fetchAll()[0][0]; $org_id = $q1->select(['min(id)'])->from('organisations')->execute()->fetchAll()[0][0];
if (!empty($org_id)) { if (!empty($org_id)) {