- Add notes migration with polymorphic columns (notable_type, notable_id) - Add foreign key to users table for author tracking - Add indexes on composite (notable_type, notable_id) and created_at - Create Note model with morphTo and belongsTo relationships
32 lines
824 B
PHP
32 lines
824 B
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('notes', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->morphs('notable'); // Creates notable_type, notable_id with composite index
|
|
$table->longText('content');
|
|
$table->foreignId('author_user_id')->constrained('users')->cascadeOnDelete();
|
|
$table->timestamps();
|
|
$table->index('created_at'); // For chronological sorting
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('notes');
|
|
}
|
|
};
|