-- V65: 创建用户权限直接关联表
-- 用途: 支持为用户直接分配权限（不通过角色）

CREATE TABLE IF NOT EXISTS sys_user_permission (
    id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    user_id BIGINT NOT NULL,
    permission_id BIGINT NOT NULL,
    granted_by BIGINT,
    granted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT uk_user_permission UNIQUE (user_id, permission_id)
);

CREATE INDEX IF NOT EXISTS idx_sys_user_permission_user_id ON sys_user_permission(user_id);
CREATE INDEX IF NOT EXISTS idx_sys_user_permission_permission_id ON sys_user_permission(permission_id);
