<?
php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateReferencesAndModifyResolutionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
// Create the 'references' table
Schema::create('references', function (Blueprint $table) {
$table->id(); // Auto-incrementing primary key
$table->string('title', 300); // Title column (not nullable)
$table->timestamps(); // Adds created_at and updated_at columns
});
// Modify the 'resolutions' table to add the 'reference_id' column
Schema::table('resolutions', function (Blueprint $table) {
// Add the reference_id column to the resolutions table
$table->unsignedBigInteger('reference_id')->nullable()-
>after('category_id');
// Add the foreign key constraint if necessary
$table->foreign('reference_id')->references('id')->on('references')-
>onDelete('set null');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
// Drop the foreign key constraint
Schema::table('resolutions', function (Blueprint $table) {
$table->dropForeign(['reference_id']);
$table->dropColumn('reference_id');
});
// Drop the 'references' table
Schema::dropIfExists('references');
}
}