46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class CreateNotificationsTable extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function up()
|
|
{
|
|
Schema::create('notifications', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->unsignedBigInteger('user_id');
|
|
$table->string('notification_code');
|
|
$table->string('title');
|
|
$table->text('message');
|
|
$table->string('link')->nullable();
|
|
$table->boolean('is_read')->default(false);
|
|
$table->timestamps();
|
|
|
|
// Foreign key constraint
|
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
|
|
|
// Indexes for better performance
|
|
$table->index(['user_id', 'is_read']);
|
|
$table->index('notification_code');
|
|
$table->index('created_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function down()
|
|
{
|
|
Schema::dropIfExists('notifications');
|
|
}
|
|
}
|