HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/www/migrations/upgrades/20191202164203_convert_user_roles.php
<?php

use Phinx\Migration\AbstractMigration;

class ConvertUserRoles extends AbstractMigration
{
  public function change() {
    $usersTable = $this->table('directus_users');

    // -------------------------------------------------------------------------
    // Add role column to directus_users
    // -------------------------------------------------------------------------
    if ($usersTable->hasColumn('role') == false) {
        $usersTable->addColumn('role', 'integer', [
            'null' => true,
            'default' => null
        ]);
        $usersTable->save();
    }

    // -------------------------------------------------------------------------
    // Add users' roles to directus_roles
    // It does this by retrieving the role ID from directus_user_roles and adding
    // that role to the role column in directus_users
    // -------------------------------------------------------------------------
    if ($this->hasTable('directus_user_roles')) {
        $stmt = $this->query("SELECT * FROM `directus_user_roles`");
        while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
            $this->execute('UPDATE `directus_users` SET `role` = '.$row['role'].' where id = '.$row['user'].';');
        }
    }

    // -------------------------------------------------------------------------
    // Remove directus_user_roles table
    // -------------------------------------------------------------------------
    if ($this->hasTable('directus_user_roles')) {
      $this->table('directus_user_roles')->drop();
    }
  }
}