peixue-dev/Archive/[一次性]创建message表-2026-01-27.sql

43 lines
1.9 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.

-- ============================================
-- 创建 message 表
-- 创建时间: 2026-01-27
-- 说明: 修复账号密码登录问题 - 缺少message表
-- ============================================
-- 创建消息表
CREATE TABLE IF NOT EXISTS `message` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`tenant_id` bigint DEFAULT NULL COMMENT '租户ID',
`sender_id` bigint NOT NULL COMMENT '发送者ID',
`receiver_id` bigint NOT NULL COMMENT '接收者ID',
`message_type` int DEFAULT 1 COMMENT '消息类型1-文本2-图片3-语音4-视频',
`content` text COMMENT '消息内容',
`media_url` varchar(500) DEFAULT NULL COMMENT '媒体URL图片、语音、视频',
`is_read` int DEFAULT 0 COMMENT '是否已读0-未读1-已读',
`read_time` datetime DEFAULT NULL COMMENT '已读时间',
`order_id` bigint DEFAULT NULL COMMENT '关联订单ID可选',
`teacher_id` bigint DEFAULT NULL COMMENT '关联教师ID可选',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` int DEFAULT 0 COMMENT '逻辑删除0-未删除1-已删除',
PRIMARY KEY (`id`),
KEY `idx_sender_id` (`sender_id`),
KEY `idx_receiver_id` (`receiver_id`),
KEY `idx_order_id` (`order_id`),
KEY `idx_teacher_id` (`teacher_id`),
KEY `idx_is_read` (`is_read`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='消息表';
-- 验证表创建成功
SELECT '=== 验证message表创建成功 ===' AS step;
SHOW CREATE TABLE message;
-- 检查表结构
SELECT '=== 检查message表结构 ===' AS step;
DESCRIBE message;
-- 测试查询应该返回0条记录
SELECT '=== 测试查询 ===' AS step;
SELECT COUNT(*) as total_messages FROM message;