2024-04-01 11:03:43 -05:00
|
|
|
<?php
|
|
|
|
|
2024-04-02 00:47:24 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-04-01 11:03:43 -05:00
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
use Illuminate\Database\QueryException;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
|
2024-04-02 00:47:24 -05:00
|
|
|
return new class () extends Migration {
|
2024-04-01 11:03:43 -05:00
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*/
|
|
|
|
public function up(): void
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
Schema::table(
|
|
|
|
'preferences',
|
|
|
|
static function (Blueprint $table): void {
|
|
|
|
if (!Schema::hasColumn('preferences', 'user_group_id')) {
|
|
|
|
$table->bigInteger('user_group_id', false, true)->nullable()->after('user_id');
|
|
|
|
$table->foreign('user_group_id', 'preferences_to_ugi')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (QueryException $e) {
|
|
|
|
app('log')->error(sprintf('Could not execute query: %s', $e->getMessage()));
|
|
|
|
app('log')->error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*/
|
2024-04-02 00:47:24 -05:00
|
|
|
public function down(): void {}
|
2024-04-01 11:03:43 -05:00
|
|
|
};
|