Files
NextEdu/drizzle/0016_message_reports_and_blocks.sql
SpecialX 365c36d97b feat(db): add migrations for RBAC, diagnostic, messaging, attendance, leave, invitation codes
- 0011: RBAC role flags and seed data

- 0012: diagnostic grade_id

- 0013: message recall

- 0014: message templates

- 0015: group messages and message reports/blocks

- 0016: invitation codes

- 0017: draft device sync

- 0018: attendance status reason

- 0019: attendance warning thresholds

- 0020: leave requests

- 0021: attendance period
2026-07-03 10:23:24 +08:00

36 lines
1.8 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- P2-5: 消息举报 + 用户屏蔽
-- 1. message_reports: 举报记录reporterId → messageId / reportedUserId
-- 2. user_blocks: 用户屏蔽关系blockerId → blockedId唯一约束防重复
CREATE TABLE `message_reports` (
`id` varchar(128) NOT NULL,
`reporter_id` varchar(128) NOT NULL,
`message_id` varchar(128) NOT NULL,
`reported_user_id` varchar(128) NOT NULL,
`reason` varchar(50) NOT NULL,
`description` text,
`status` varchar(20) NOT NULL DEFAULT 'pending',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `message_reports_reporter_idx` (`reporter_id`),
INDEX `message_reports_message_idx` (`message_id`),
INDEX `message_reports_reported_user_idx` (`reported_user_id`),
INDEX `message_reports_status_idx` (`status`),
CONSTRAINT `message_reports_reporter_id_users_id_fk` FOREIGN KEY (`reporter_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
CONSTRAINT `message_reports_message_id_messages_id_fk` FOREIGN KEY (`message_id`) REFERENCES `messages`(`id`) ON DELETE CASCADE,
CONSTRAINT `message_reports_reported_user_id_users_id_fk` FOREIGN KEY (`reported_user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
);
CREATE TABLE `user_blocks` (
`id` varchar(128) NOT NULL,
`blocker_id` varchar(128) NOT NULL,
`blocked_id` varchar(128) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE INDEX `user_blocks_blocker_blocked_uniq` (`blocker_id`, `blocked_id`),
INDEX `user_blocks_blocker_idx` (`blocker_id`),
CONSTRAINT `user_blocks_blocker_id_users_id_fk` FOREIGN KEY (`blocker_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
CONSTRAINT `user_blocks_blocked_id_users_id_fk` FOREIGN KEY (`blocked_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
);