refactor: Consolidate user settings table creation by integrating all preference columns and enhancing the NotifStyle enum.
This commit is contained in:
parent
cd1b9b09ba
commit
22572bc6a3
@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Enums;
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use App\Traits\Enum\WithComment;
|
||||||
|
use App\Traits\Enum\WithValue;
|
||||||
use Filament\Support\Contracts\HasLabel;
|
use Filament\Support\Contracts\HasLabel;
|
||||||
|
|
||||||
enum NotifStyle: string implements HasLabel
|
enum NotifStyle: string implements HasLabel
|
||||||
{
|
{
|
||||||
|
use WithComment, WithValue;
|
||||||
|
|
||||||
case CHEERFUL = 'cheerful';
|
case CHEERFUL = 'cheerful';
|
||||||
case FORMAL = 'formal';
|
case FORMAL = 'formal';
|
||||||
|
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->string('notif_style')->default('cheerful')->after('email_verified_at');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
//
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\NotifStyle;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
@ -14,29 +14,15 @@ public function up(): void
|
|||||||
{
|
{
|
||||||
Schema::create('user_settings', function (Blueprint $table) {
|
Schema::create('user_settings', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('user_id')->unique()->constrained()->onDelete('cascade');
|
$table->foreignId('user_id')->unique()->constrained()->cascadeOnDelete();
|
||||||
$table->string('notif_style')->default('cheerful');
|
$table->enum('notif_style', NotifStyle::values())->default(NotifStyle::CHEERFUL->value)->comment(NotifStyle::comment());
|
||||||
$table->string('primary_color')->nullable(); // For future extension
|
$table->string('primary_color')->nullable();
|
||||||
|
$table->string('font')->default('Inter');
|
||||||
|
$table->string('content_width')->default('full');
|
||||||
|
$table->string('border_radius')->default('lg');
|
||||||
|
$table->boolean('top_navigation')->default(false);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Migrate existing data from users table (already has notif_style from earlier migration)
|
|
||||||
$users = DB::table('users')->get();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
DB::table('user_settings')->updateOrInsert(
|
|
||||||
['user_id' => $user->id],
|
|
||||||
[
|
|
||||||
'notif_style' => $user->notif_style ?? 'cheerful',
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now(),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drop the old column from users
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->dropColumn('notif_style');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,18 +30,6 @@ public function up(): void
|
|||||||
*/
|
*/
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->string('notif_style')->default('cheerful')->after('email_verified_at');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Revert data
|
|
||||||
$settings = DB::table('user_settings')->get();
|
|
||||||
foreach ($settings as $setting) {
|
|
||||||
DB::table('users')
|
|
||||||
->where('id', $setting->user_id)
|
|
||||||
->update(['notif_style' => $setting->notif_style]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Schema::dropIfExists('user_settings');
|
Schema::dropIfExists('user_settings');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::table('user_settings', function (Blueprint $table) {
|
|
||||||
$table->string('font')->default('Inter')->after('primary_color');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('user_settings', function (Blueprint $table) {
|
|
||||||
$table->dropColumn('font');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::table('user_settings', function (Blueprint $table) {
|
|
||||||
$table->string('content_width')->default('full')->after('font');
|
|
||||||
$table->string('border_radius')->default('lg')->after('content_width');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('user_settings', function (Blueprint $table) {
|
|
||||||
$table->dropColumn(['content_width', 'border_radius']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::table('user_settings', function (Blueprint $table) {
|
|
||||||
$table->boolean('top_navigation')->default(false)->after('border_radius');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('user_settings', function (Blueprint $table) {
|
|
||||||
$table->dropColumn('top_navigation');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue
Block a user