Add missing role for users migration
This commit is contained in:
parent
f2258fc738
commit
5ea039ccfe
1 changed files with 21 additions and 1 deletions
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
|
||||
use Doctrine\DBAL\Types\SmallIntType;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
|
|
@ -16,8 +19,25 @@ return new class extends Migration
|
|||
{
|
||||
if (Schema::hasTable('users')) {
|
||||
Log::debug('already has users');
|
||||
Log::debug('adding role');
|
||||
if (!Type::hasType('integer')) {
|
||||
Type::addType('integer', SmallIntType::class);
|
||||
}
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->smallInteger('role')->nullable()->after('remember_token');
|
||||
});
|
||||
DB::table('users')->get()->each(function (object $user) {
|
||||
DB::table('users')->where('id', $user->id)
|
||||
->update(['role' => in_array($user->email, [
|
||||
'informatique.internet@ldc.fr',
|
||||
'equipe.web@ldc.fr'
|
||||
]) ? 1 : 2]);
|
||||
});
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->smallInteger('role')->change();
|
||||
});
|
||||
return;
|
||||
}
|
||||
} //end if
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name', 100)->default('0');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue