Files
back-meditation/database/migrations/2025_11_24_130051_create_media_table.php
T
2025-11-24 18:59:26 +03:30

51 lines
1.5 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('media', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('image_id')->nullable();
$table->unsignedBigInteger('category_id')->nullable();
$table->unsignedBigInteger('user_id')->nullable(); // owner (optional)
$table->string('title');
$table->text('caption')->nullable();
// media type (audio / video)
$table->enum('type', ['audio', 'video']);
// File or URL
$table->string('file_path')->nullable(); // stored file
$table->string('external_url')->nullable(); // YouTube, etc.
$table->integer('duration')->nullable(); // seconds
// public/private
$table->enum('visibility', ['public', 'private'])->default('public');
$table->timestamps();
$table->foreign('image_id')->references('id')->on('images')->nullOnDelete();
$table->foreign('category_id')->references('id')->on('categories')->nullOnDelete();
$table->foreign('user_id')->references('id')->on('users')->nullOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('media');
}
};