Add role if missing on create users

This commit is contained in:
Jérémy Munsch 2023-09-04 17:21:06 +02:00
parent 8622dfd2bd
commit 262f742017
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC

View file

@ -1,5 +1,6 @@
<?php
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Types\SmallIntType;
use Doctrine\DBAL\Types\Type;
use Illuminate\Database\Migrations\Migration;
@ -17,8 +18,20 @@ return new class extends Migration
*/
public function up()
{
$columns = collect(
Schema::getConnection()
->getDoctrineSchemaManager()
->listTableColumns('users')
)->mapWithKeys(function (Column $column) {
return [$column->getName() => $column];
});
if (Schema::hasTable('users')) {
Log::debug('already has users');
if ($columns->has('role')) {
Log::debug('already has role column');
return;
}
Log::debug('adding role');
if (!Type::hasType('integer')) {
Type::addType('integer', SmallIntType::class);