本目录包含通知模块所需的所有数据库迁移文件。
创建通知模板表
Schema::create('notification_templates', function (Blueprint $table) {
$table->id();
$table->string('name', 100)->comment('模板名称');
$table->string('type', 20)->comment('通知类型');
$table->string('channel', 20)->comment('通知渠道');
$table->string('title', 255)->comment('通知标题');
$table->text('content')->comment('通知内容');
$table->json('variables')->nullable()->comment('变量定义');
$table->tinyInteger('status')->default(1)->comment('状态:0禁用 1启用');
$table->timestamps();
});
创建通知记录表
Schema::create('notifications', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('template_id')->comment('模板ID');
$table->string('type', 20)->comment('通知类型');
$table->string('channel', 20)->comment('通知渠道');
$table->string('title', 255)->comment('通知标题');
$table->text('content')->comment('通知内容');
$table->json('data')->nullable()->comment('通知数据');
$table->tinyInteger('priority')->default(2)->comment('优先级');
$table->string('status', 20)->default('pending')->comment('状态');
$table->integer('retry_count')->default(0)->comment('重试次数');
$table->timestamp('sent_at')->nullable()->comment('发送时间');
$table->timestamps();
});
创建通知接收者表
Schema::create('notification_recipients', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('notification_id')->comment('通知ID');
$table->unsignedBigInteger('user_id')->comment('用户ID');
$table->timestamp('read_at')->nullable()->comment('阅读时间');
$table->timestamps();
});
$table->foreign('template_id')
->references('id')
->on('notification_templates')
->onDelete('cascade');
$table->foreign('notification_id')
->references('id')
->on('notifications')
->onDelete('cascade');
本模块包含以下数据填充文件:
填充通知类型数据
填充通知渠道数据
填充通知优先级数据
填充通知状态数据
运行迁移:
php artisan migrate
回滚迁移:
php artisan migrate:rollback
重置迁移:
php artisan migrate:refresh
运行数据填充:
php artisan db:seed --class=NotificationTypeSeeder
php artisan db:seed --class=NotificationChannelSeeder
php artisan db:seed --class=NotificationPrioritySeeder
php artisan db:seed --class=NotificationStatusSeeder