diff --git a/database/migrations/2022_08_01_093952_use_uuids_for_song_ids.php b/database/migrations/2022_08_01_093952_use_uuids_for_song_ids.php index 0cd66ee9..aa031231 100644 --- a/database/migrations/2022_08_01_093952_use_uuids_for_song_ids.php +++ b/database/migrations/2022_08_01_093952_use_uuids_for_song_ids.php @@ -11,27 +11,27 @@ return new class extends Migration { public function up(): void { + Schema::disableForeignKeyConstraints(); + + if (DB::getDriverName() !== 'sqlite') { + collect(['playlist_song', 'interactions'])->each(static function (string $table): void { + Schema::table($table, static function (Blueprint $table): void { + $table->dropForeign(['song_id']); + }); + }); + } + Schema::table('songs', static function (Blueprint $table): void { $table->string('id', 36)->change(); }); Schema::table('playlist_song', static function (Blueprint $table): void { $table->string('song_id', 36)->change(); - - if (DB::getDriverName() !== 'sqlite') { - $table->dropForeign('playlist_song_song_id_foreign'); - } - $table->foreign('song_id')->references('id')->on('songs')->cascadeOnDelete()->cascadeOnUpdate(); }); Schema::table('interactions', static function (Blueprint $table): void { $table->string('song_id', 36)->change(); - - if (DB::getDriverName() !== 'sqlite') { - $table->dropForeign('interactions_song_id_foreign'); - } - $table->foreign('song_id')->references('id')->on('songs')->cascadeOnDelete()->cascadeOnUpdate(); }); @@ -39,5 +39,7 @@ return new class extends Migration $song->id = Str::uuid(); $song->save(); }); + + Schema::enableForeignKeyConstraints(); } };