fix(migration): make add_waitlist_columns migration idempotent (#200)
## Summary - The `2026_03_04_085843_add_waitlist_columns_to_user_leads_table` migration was failing on deploy because the `position`, `referral_code`, and `referred_by_id` columns already existed in the production database. - Wrapped each column addition with a `Schema::hasColumn()` guard so the migration skips columns that already exist, making it safe to run regardless of the current schema state.
This commit is contained in:
parent
4d0d203fd3
commit
cf9071c11b
|
|
@ -12,11 +12,18 @@ return new class extends Migration
|
|||
public function up(): void
|
||||
{
|
||||
Schema::table('user_leads', function (Blueprint $table) {
|
||||
$table->unsignedInteger('position')->after('email');
|
||||
$table->string('referral_code', 12)->unique()->after('position');
|
||||
$table->char('referred_by_id', 36)->nullable()->after('referral_code');
|
||||
if (! Schema::hasColumn('user_leads', 'position')) {
|
||||
$table->unsignedInteger('position')->after('email');
|
||||
}
|
||||
|
||||
$table->foreign('referred_by_id')->references('id')->on('user_leads')->nullOnDelete();
|
||||
if (! Schema::hasColumn('user_leads', 'referral_code')) {
|
||||
$table->string('referral_code', 12)->unique()->after('position');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('user_leads', 'referred_by_id')) {
|
||||
$table->char('referred_by_id', 36)->nullable()->after('referral_code');
|
||||
$table->foreign('referred_by_id')->references('id')->on('user_leads')->nullOnDelete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue