From 22572bc6a31b6a86c4b2a62c6c636f5bab4992da Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 26 Mar 2026 16:01:45 +0700 Subject: [PATCH] refactor: Consolidate user settings table creation by integrating all preference columns and enhancing the NotifStyle enum. --- app/Enums/NotifStyle.php | 4 ++ ..._26_140819_add_ux_style_to_users_table.php | 28 ------------- ...3_26_144130_create_user_settings_table.php | 42 ++++--------------- ...151805_add_font_to_user_settings_table.php | 28 ------------- ..._ui_preferences_to_user_settings_table.php | 29 ------------- ..._top_navigation_to_user_settings_table.php | 28 ------------- 6 files changed, 12 insertions(+), 147 deletions(-) delete mode 100644 database/migrations/2026_03_26_140819_add_ux_style_to_users_table.php delete mode 100644 database/migrations/2026_03_26_151805_add_font_to_user_settings_table.php delete mode 100644 database/migrations/2026_03_26_152053_add_ui_preferences_to_user_settings_table.php delete mode 100644 database/migrations/2026_03_26_152631_add_top_navigation_to_user_settings_table.php diff --git a/app/Enums/NotifStyle.php b/app/Enums/NotifStyle.php index fd0f646..6f8b9e7 100644 --- a/app/Enums/NotifStyle.php +++ b/app/Enums/NotifStyle.php @@ -2,10 +2,14 @@ namespace App\Enums; +use App\Traits\Enum\WithComment; +use App\Traits\Enum\WithValue; use Filament\Support\Contracts\HasLabel; enum NotifStyle: string implements HasLabel { + use WithComment, WithValue; + case CHEERFUL = 'cheerful'; case FORMAL = 'formal'; diff --git a/database/migrations/2026_03_26_140819_add_ux_style_to_users_table.php b/database/migrations/2026_03_26_140819_add_ux_style_to_users_table.php deleted file mode 100644 index 3591858..0000000 --- a/database/migrations/2026_03_26_140819_add_ux_style_to_users_table.php +++ /dev/null @@ -1,28 +0,0 @@ -string('notif_style')->default('cheerful')->after('email_verified_at'); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - // - }); - } -}; diff --git a/database/migrations/2026_03_26_144130_create_user_settings_table.php b/database/migrations/2026_03_26_144130_create_user_settings_table.php index d50ad40..de6b2dc 100644 --- a/database/migrations/2026_03_26_144130_create_user_settings_table.php +++ b/database/migrations/2026_03_26_144130_create_user_settings_table.php @@ -1,8 +1,8 @@ id(); - $table->foreignId('user_id')->unique()->constrained()->onDelete('cascade'); - $table->string('notif_style')->default('cheerful'); - $table->string('primary_color')->nullable(); // For future extension + $table->foreignId('user_id')->unique()->constrained()->cascadeOnDelete(); + $table->enum('notif_style', NotifStyle::values())->default(NotifStyle::CHEERFUL->value)->comment(NotifStyle::comment()); + $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(); }); - - // 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 { - 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'); } }; diff --git a/database/migrations/2026_03_26_151805_add_font_to_user_settings_table.php b/database/migrations/2026_03_26_151805_add_font_to_user_settings_table.php deleted file mode 100644 index 50e6f18..0000000 --- a/database/migrations/2026_03_26_151805_add_font_to_user_settings_table.php +++ /dev/null @@ -1,28 +0,0 @@ -string('font')->default('Inter')->after('primary_color'); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('user_settings', function (Blueprint $table) { - $table->dropColumn('font'); - }); - } -}; diff --git a/database/migrations/2026_03_26_152053_add_ui_preferences_to_user_settings_table.php b/database/migrations/2026_03_26_152053_add_ui_preferences_to_user_settings_table.php deleted file mode 100644 index 94f3ccb..0000000 --- a/database/migrations/2026_03_26_152053_add_ui_preferences_to_user_settings_table.php +++ /dev/null @@ -1,29 +0,0 @@ -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']); - }); - } -}; diff --git a/database/migrations/2026_03_26_152631_add_top_navigation_to_user_settings_table.php b/database/migrations/2026_03_26_152631_add_top_navigation_to_user_settings_table.php deleted file mode 100644 index ed84a43..0000000 --- a/database/migrations/2026_03_26_152631_add_top_navigation_to_user_settings_table.php +++ /dev/null @@ -1,28 +0,0 @@ -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'); - }); - } -};