-- 公告/通知已读记录表
CREATE TABLE IF NOT EXISTS sys_notice_read (
    read_id BIGINT PRIMARY KEY,
    notice_id BIGINT NOT NULL,
    user_id BIGINT NOT NULL,
    read_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT uk_notice_user UNIQUE (notice_id, user_id)
);

COMMENT ON TABLE sys_notice_read IS '公告/通知已读记录表';
COMMENT ON COLUMN sys_notice_read.read_id IS '阅读ID';
COMMENT ON COLUMN sys_notice_read.notice_id IS '公告/通知ID';
COMMENT ON COLUMN sys_notice_read.user_id IS '用户ID';
COMMENT ON COLUMN sys_notice_read.read_time IS '阅读时间';

-- 创建序列
CREATE SEQUENCE IF NOT EXISTS sys_notice_read_read_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 99999999
START 200
CACHE 1;

-- 索引
CREATE INDEX IF NOT EXISTS idx_notice_read_notice_id ON sys_notice_read(notice_id);
CREATE INDEX IF NOT EXISTS idx_notice_read_user_id ON sys_notice_read(user_id);
