nest-boot-row-level-security

Installation
SKILL.md

nest-boot Row Level Security

概览

用简单实体策略表达稳定的归属规则,把例外查询流程放在范围很小的业务代码中。RLS 应描述长期成立的表访问边界,不要承载一次性 token、hash、邀请链接等临时流程。

Policy 设计

  • 优先为直接归属字段或关联使用 @Policy({ property, context, roles })。
  • 能加直接关联时优先加关联,例如 tenant!: Ref<Tenant>,避免在 RLS 里写复杂子查询。
  • 记住 command 默认是 PolicyCommand.ALL。如果表不应授予 insert、update 或 delete 权限,不要省略 command。
  • 多条 permissive policy 在 PostgreSQL 中按 OR 合并。restrictive policy 会与 permissive 结果按 AND 合并。
  • 只有真正需要约束所有匹配命令的护栏才使用 PolicyMode.RESTRICTIVE,例如软删除可见性。
  • 当命令意图重要,或稳定的迁移策略名有助于 review 时,优先使用具名 policy。
  • Entity 装饰器是 policy 的源定义。先修改 @Policy,再让 MikroORM 生成继承 RowLevelSecurityMigration 的迁移;不要只手改迁移 SQL。

可选上下文与类型转换

Installs
3
First Seen
Aug 27, 2026
nest-boot-row-level-security — nest-boot/skills