117 lines
4.5 KiB
PHP
117 lines
4.5 KiB
PHP
<?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::create('movies', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('provider')->nullable();
|
|
$table->string('provider_id')->nullable()->index();
|
|
$table->json('external_ids')->nullable();
|
|
$table->string('title');
|
|
$table->string('original_title')->nullable();
|
|
$table->text('description')->nullable();
|
|
$table->string('poster_url')->nullable();
|
|
$table->string('backdrop_url')->nullable();
|
|
$table->string('rating', 20)->nullable();
|
|
$table->date('release_date')->nullable();
|
|
$table->unsignedSmallInteger('year')->nullable();
|
|
$table->unsignedSmallInteger('runtime')->nullable(); // minutes
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('genres', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('name')->unique();
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('actors', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('name')->unique();
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('directors', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('name')->unique();
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('studios', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('name')->unique();
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('countries', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('name')->unique();
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('languages', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('name')->unique();
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('movie_genre', function (Blueprint $table) {
|
|
$table->foreignId('movie_id')->constrained('movies')->cascadeOnDelete();
|
|
$table->foreignId('genre_id')->constrained('genres')->cascadeOnDelete();
|
|
$table->primary(['movie_id','genre_id']);
|
|
});
|
|
|
|
Schema::create('movie_actor', function (Blueprint $table) {
|
|
$table->foreignId('movie_id')->constrained('movies')->cascadeOnDelete();
|
|
$table->foreignId('actor_id')->constrained('actors')->cascadeOnDelete();
|
|
$table->primary(['movie_id','actor_id']);
|
|
});
|
|
|
|
Schema::create('movie_director', function (Blueprint $table) {
|
|
$table->foreignId('movie_id')->constrained('movies')->cascadeOnDelete();
|
|
$table->foreignId('director_id')->constrained('directors')->cascadeOnDelete();
|
|
$table->primary(['movie_id','director_id']);
|
|
});
|
|
|
|
Schema::create('movie_studio', function (Blueprint $table) {
|
|
$table->foreignId('movie_id')->constrained('movies')->cascadeOnDelete();
|
|
$table->foreignId('studio_id')->constrained('studios')->cascadeOnDelete();
|
|
$table->primary(['movie_id','studio_id']);
|
|
});
|
|
|
|
Schema::create('movie_country', function (Blueprint $table) {
|
|
$table->foreignId('movie_id')->constrained('movies')->cascadeOnDelete();
|
|
$table->foreignId('country_id')->constrained('countries')->cascadeOnDelete();
|
|
$table->primary(['movie_id','country_id']);
|
|
});
|
|
|
|
Schema::create('movie_language', function (Blueprint $table) {
|
|
$table->foreignId('movie_id')->constrained('movies')->cascadeOnDelete();
|
|
$table->foreignId('language_id')->constrained('languages')->cascadeOnDelete();
|
|
$table->primary(['movie_id','language_id']);
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('movie_language');
|
|
Schema::dropIfExists('movie_country');
|
|
Schema::dropIfExists('movie_studio');
|
|
Schema::dropIfExists('movie_director');
|
|
Schema::dropIfExists('movie_actor');
|
|
Schema::dropIfExists('movie_genre');
|
|
Schema::dropIfExists('languages');
|
|
Schema::dropIfExists('countries');
|
|
Schema::dropIfExists('studios');
|
|
Schema::dropIfExists('directors');
|
|
Schema::dropIfExists('actors');
|
|
Schema::dropIfExists('genres');
|
|
Schema::dropIfExists('movies');
|
|
}
|
|
};
|