54 lines
2.0 KiB
PHP
54 lines
2.0 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
/**
|
|
* Allowed reaction slugs → emoji mapping (authoritative list lives in ReactionType).
|
|
* Stored as VARCHAR to avoid MySQL ENUM emoji encoding issues.
|
|
*/
|
|
public function up(): void
|
|
{
|
|
Schema::create('artwork_reactions', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->unsignedBigInteger('artwork_id');
|
|
$table->unsignedBigInteger('user_id');
|
|
// slug: thumbs_up | heart | fire | laugh | clap | wow
|
|
$table->string('reaction', 20);
|
|
$table->timestamp('created_at')->useCurrent();
|
|
|
|
$table->unique(['artwork_id', 'user_id', 'reaction'], 'artwork_reactions_unique');
|
|
$table->index('artwork_id');
|
|
$table->index('user_id');
|
|
|
|
$table->foreign('artwork_id')->references('id')->on('artworks')->onDelete('cascade');
|
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
|
});
|
|
|
|
Schema::create('comment_reactions', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->unsignedBigInteger('comment_id');
|
|
$table->unsignedBigInteger('user_id');
|
|
// slug: thumbs_up | heart | fire | laugh | clap | wow
|
|
$table->string('reaction', 20);
|
|
$table->timestamp('created_at')->useCurrent();
|
|
|
|
$table->unique(['comment_id', 'user_id', 'reaction'], 'comment_reactions_unique');
|
|
$table->index('comment_id');
|
|
$table->index('user_id');
|
|
|
|
$table->foreign('comment_id')->references('id')->on('artwork_comments')->onDelete('cascade');
|
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('comment_reactions');
|
|
Schema::dropIfExists('artwork_reactions');
|
|
}
|
|
};
|