Skip to content

Commit

Permalink
fix: Update add_username_to_users migration to use SafeMigration trait
Browse files Browse the repository at this point in the history
  • Loading branch information
sudoshi committed Feb 22, 2025
1 parent fa94f24 commit c15d533
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions database/migrations/2024_02_04_000000_add_username_to_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,33 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Traits\SafeMigration;

return new class extends Migration
{
use SafeMigration;

/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('prod.users', function (Blueprint $table) {
$table->string('username')->nullable()->unique()->after('name');
});
if (!Schema::hasColumn('prod.users', 'username')) {
Schema::table('prod.users', function (Blueprint $table) {
$table->string('username')->nullable()->unique()->after('name');
});
}
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('prod.users', function (Blueprint $table) {
$table->dropColumn('username');
});
if ($this->isLocalEnvironment()) {
Schema::table('prod.users', function (Blueprint $table) {
$table->dropColumn('username');
});
}
}
};

0 comments on commit c15d533

Please sign in to comment.