Allow artworks to have one primary category and extra secondaries.
Keep artwork_category as membership, store a deterministic primary_category_id, and let upload plus studio pick up to five additional same-type categories without changing canonical URLs.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (Schema::hasTable('artworks') && ! Schema::hasColumn('artworks', 'primary_category_id')) {
|
||||
Schema::table('artworks', function (Blueprint $table): void {
|
||||
$table->unsignedBigInteger('primary_category_id')->nullable()->after('user_id');
|
||||
$table->index('primary_category_id');
|
||||
$table->foreign('primary_category_id')
|
||||
->references('id')
|
||||
->on('categories')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
if (Schema::hasTable('uploads') && ! Schema::hasColumn('uploads', 'secondary_category_ids')) {
|
||||
Schema::table('uploads', function (Blueprint $table): void {
|
||||
$table->json('secondary_category_ids')->nullable()->after('category_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (Schema::hasTable('artworks') && Schema::hasColumn('artworks', 'primary_category_id')) {
|
||||
Schema::table('artworks', function (Blueprint $table): void {
|
||||
$table->dropForeign(['primary_category_id']);
|
||||
$table->dropColumn('primary_category_id');
|
||||
});
|
||||
}
|
||||
|
||||
if (Schema::hasTable('uploads') && Schema::hasColumn('uploads', 'secondary_category_ids')) {
|
||||
Schema::table('uploads', function (Blueprint $table): void {
|
||||
$table->dropColumn('secondary_category_ids');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user