Files
proton/migrations/20260913020000_create_notifications.php
rsgrinko 2f162a846f Уведомления: лента в приложении и письма по каналам
Notify рассылает по каналам database и mail, адресовать можно по праву.
Роутер теперь поднимается и вне запроса, появился Router::absolute для писем.
2026-09-13 00:57:21 +03:00

41 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Migrations;
use Rsgrinko\Proton\Database\Migration;
use Rsgrinko\Proton\Database\Schema\Blueprint;
/**
* Лента уведомлений пользователя.
*/
final class CreateNotifications extends Migration
{
public function up(): void
{
$this->create('notifications', function (Blueprint $table): void {
$table->id();
$table->foreignId('user_id');
// Тип — короткий код вроде webhook.disabled: по нему видно, о чём речь,
// и можно отличать уведомления друг от друга, не разбирая текст
$table->string('type', 64)->default('');
$table->string('title', 191);
$table->text('body')->nullable();
// Куда вести по нажатию; пусто — уведомление без перехода
$table->string('url', 500)->default('');
$table->dateTime('read_at')->nullable();
$table->dateTime('created_at');
// По этому индексу рисуется лента и считаются непрочитанные
$table->index('idx_notifications_user', ['user_id', 'read_at']);
$table->index('idx_notifications_created', 'created_at');
});
}
public function down(): void
{
$this->drop('notifications');
}
}