In-app notification system with topbar bell icon, dropdown panel, mark-as-read/dismiss actions, and scheduled cleanup of old read notifications. Includes event listeners for user.created and user.deleted events, authorization policy, and full test coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
21 lines
1.0 KiB
SQL
21 lines
1.0 KiB
SQL
CREATE TABLE IF NOT EXISTS `user_notifications` (
|
|
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`recipient_user_id` INT UNSIGNED NOT NULL,
|
|
`tenant_id` INT UNSIGNED NULL,
|
|
`type` VARCHAR(60) NOT NULL,
|
|
`title` VARCHAR(255) NOT NULL,
|
|
`body` VARCHAR(500) NULL,
|
|
`link` VARCHAR(500) NULL,
|
|
`data` JSON NULL,
|
|
`is_read` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`read_at` DATETIME NULL DEFAULT NULL,
|
|
`created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_un_recipient_read_created` (`recipient_user_id`, `is_read`, `created` DESC),
|
|
KEY `idx_un_recipient_created` (`recipient_user_id`, `created` DESC),
|
|
KEY `idx_un_tenant_created` (`tenant_id`, `created` DESC),
|
|
KEY `idx_un_cleanup` (`is_read`, `read_at`),
|
|
CONSTRAINT `fk_un_recipient` FOREIGN KEY (`recipient_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
|
|
CONSTRAINT `fk_un_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|