feat(db)!: drop song_groups, introduce label_id on song_slides, add song_arrangement_labels (BREAKING)
This commit is contained in:
parent
a65bf3d595
commit
2b27aa50d5
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class () extends Migration {
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('song_slides', function (Blueprint $table) {
|
||||||
|
$table->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.');
|
||||||
|
}
|
||||||
|
};
|
||||||
21
tests/Feature/Migrations/SongsToLabelsRefactorTest.php
Normal file
21
tests/Feature/Migrations/SongsToLabelsRefactorTest.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
test('song_slides has label_id column after migration', function () {
|
||||||
|
expect(Schema::hasColumn('song_slides', 'label_id'))->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();
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue