chore: snapshot notifications hardening and css/docs alignment
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
INSERT INTO `permissions` (`key`, `description`, `active`, `is_system`)
|
||||
VALUES ('notifications.view', 'Can view and manage own notifications', 1, 1)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`description` = VALUES(`description`),
|
||||
`active` = VALUES(`active`),
|
||||
`is_system` = VALUES(`is_system`);
|
||||
|
||||
INSERT INTO `role_permissions` (`role_id`, `permission_id`, `created`)
|
||||
SELECT r.id, p.id, NOW()
|
||||
FROM roles r
|
||||
JOIN permissions p ON p.`key` = 'notifications.view'
|
||||
WHERE r.active = 1
|
||||
ON DUPLICATE KEY UPDATE role_id = role_id;
|
||||
@@ -7,6 +7,9 @@ CREATE TABLE IF NOT EXISTS `user_notifications` (
|
||||
`body` VARCHAR(500) NULL,
|
||||
`link` VARCHAR(500) NULL,
|
||||
`data` JSON NULL,
|
||||
`dedupe_fingerprint` CHAR(64) NULL,
|
||||
`dedupe_bucket` INT UNSIGNED NULL,
|
||||
`dedupe_until` DATETIME NULL DEFAULT NULL,
|
||||
`is_read` TINYINT(1) NOT NULL DEFAULT 0,
|
||||
`read_at` DATETIME NULL DEFAULT NULL,
|
||||
`created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
@@ -15,6 +18,15 @@ CREATE TABLE IF NOT EXISTS `user_notifications` (
|
||||
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`),
|
||||
UNIQUE KEY `uniq_un_dedupe_bucket` (`recipient_user_id`, `dedupe_fingerprint`, `dedupe_bucket`),
|
||||
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;
|
||||
|
||||
ALTER TABLE `user_notifications`
|
||||
ADD COLUMN IF NOT EXISTS `dedupe_fingerprint` CHAR(64) NULL AFTER `data`,
|
||||
ADD COLUMN IF NOT EXISTS `dedupe_bucket` INT UNSIGNED NULL AFTER `dedupe_fingerprint`,
|
||||
ADD COLUMN IF NOT EXISTS `dedupe_until` DATETIME NULL DEFAULT NULL AFTER `dedupe_bucket`;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS `uniq_un_dedupe_bucket`
|
||||
ON `user_notifications` (`recipient_user_id`, `dedupe_fingerprint`, `dedupe_bucket`);
|
||||
|
||||
Reference in New Issue
Block a user