users menu listing
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (
|
||||
! Schema::hasTable('users')
|
||||
|| ! Schema::hasColumn('users', 'helpdesk_admin')
|
||||
|| ! Schema::hasColumn('users', 'helpdesk_agent')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do nothing when an administrator already exists.
|
||||
if (DB::table('users')->where('helpdesk_admin', true)->exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bootstrap the oldest account as the initial administrator.
|
||||
// From this point onward administrators are managed through User Management.
|
||||
$initialUserId = DB::table('users')->orderBy('id')->value('id');
|
||||
|
||||
if ($initialUserId === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('users')
|
||||
->where('id', $initialUserId)
|
||||
->update([
|
||||
'helpdesk_admin' => true,
|
||||
'helpdesk_agent' => true,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Intentionally non-destructive. Never silently remove an administrator.
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user