|
| 1 | +<?php |
| 2 | + |
| 3 | +use Illuminate\Database\Migrations\Migration; |
| 4 | +use Illuminate\Database\Schema\Blueprint; |
| 5 | +use Illuminate\Support\Facades\Schema; |
| 6 | + |
| 7 | +return new class extends Migration |
| 8 | +{ |
| 9 | + /** |
| 10 | + * Run the migrations. |
| 11 | + */ |
| 12 | + public function up(): void |
| 13 | + { |
| 14 | + if (Schema::hasTable('social_family_connections')) { |
| 15 | + Schema::table('social_family_connections', function (Blueprint $table) { |
| 16 | + // if an old default-named index made it into the database we need to |
| 17 | + // remove it before adding a properly named, shorter index. |
| 18 | + // Using dropIndex with the column list will generate the same long |
| 19 | + // identifier Laravel would have used originally, so it will be |
| 20 | + // dropped if present and ignored otherwise. |
| 21 | + $table->dropIndex(['connected_account_id', 'matched_social_id']); |
| 22 | + |
| 23 | + // add the newer short name; if it's already there this is a no-op |
| 24 | + $table->index( |
| 25 | + ['connected_account_id', 'matched_social_id'], |
| 26 | + 'sfc_account_social_id_idx' |
| 27 | + ); |
| 28 | + }); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Reverse the migrations. |
| 34 | + */ |
| 35 | + public function down(): void |
| 36 | + { |
| 37 | + if (Schema::hasTable('social_family_connections')) { |
| 38 | + Schema::table('social_family_connections', function (Blueprint $table) { |
| 39 | + $table->dropIndex('sfc_account_social_id_idx'); |
| 40 | + // restore the original index name (long) so the rollback restores |
| 41 | + // the previous state exactly; Laravel will recompute it for us. |
| 42 | + $table->index(['connected_account_id', 'matched_social_id']); |
| 43 | + }); |
| 44 | + } |
| 45 | + } |
| 46 | +}; |
0 commit comments