diff --git a/database/migrations/2026_05_03_100600_refactor_songs_to_labels.php b/database/migrations/2026_05_03_100600_refactor_songs_to_labels.php new file mode 100644 index 0000000..29c5c20 --- /dev/null +++ b/database/migrations/2026_05_03_100600_refactor_songs_to_labels.php @@ -0,0 +1,38 @@ +dropUnique(['song_group_id', 'order']); + $table->dropIndex(['song_group_id']); + $table->dropForeign(['song_group_id']); + $table->dropColumn('song_group_id'); + }); + + Schema::table('song_slides', function (Blueprint $table) { + $table->foreignId('label_id')->nullable()->constrained('labels')->restrictOnDelete(); + }); + + Schema::dropIfExists('song_arrangement_groups'); + Schema::dropIfExists('song_groups'); + + Schema::create('song_arrangement_labels', function (Blueprint $table) { + $table->id(); + $table->foreignId('song_arrangement_id')->constrained()->cascadeOnDelete(); + $table->foreignId('label_id')->constrained('labels')->restrictOnDelete(); + $table->unsignedInteger('order'); + $table->timestamps(); + $table->index(['song_arrangement_id', 'order']); + }); + } + + public function down(): void + { + throw new \RuntimeException('Destructive migration: rollback not supported. Restore from backup.'); + } +}; diff --git a/tests/Feature/Migrations/SongsToLabelsRefactorTest.php b/tests/Feature/Migrations/SongsToLabelsRefactorTest.php new file mode 100644 index 0000000..78bcc7d --- /dev/null +++ b/tests/Feature/Migrations/SongsToLabelsRefactorTest.php @@ -0,0 +1,21 @@ +toBeTrue(); + expect(Schema::hasColumn('song_slides', 'song_group_id'))->toBeFalse(); +}); + +test('song_arrangement_groups table is dropped', function () { + expect(Schema::hasTable('song_arrangement_groups'))->toBeFalse(); +}); + +test('song_arrangement_labels table exists with expected columns', function () { + expect(Schema::hasTable('song_arrangement_labels'))->toBeTrue(); + expect(Schema::hasColumns('song_arrangement_labels', ['id', 'song_arrangement_id', 'label_id', 'order', 'created_at', 'updated_at']))->toBeTrue(); +}); + +test('song_groups table is dropped', function () { + expect(Schema::hasTable('song_groups'))->toBeFalse(); +});