linkage/doctrine-row-level-security

v2.0.0 2025-03-11 23:38 UTC

This package is auto-updated.

Last update: 2025-06-22 11:09:49 UTC


README

A package to provide projects with Doctrine ORM PostgreSQL's Row Level Security features.

Installation

  1. Install this package via composer.
composer require linkage/doctrine-row-level-security
  1. Add this package's EventSubscriber to your doctrine configuration

for Symfony:

# services.yaml
services:
    rls.subscriber:
        class: Linkage\DoctrineRowLevelSecurity\RowLevelSecurityListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }

for laravel-doctrine/orm:

// config/doctrine.php
            'events'        => [
                'listeners'   => [],
                'subscribers' => [
                    Linkage\DoctrineRowLevelSecurity\RowLevelSecurityListener::class,
                ],
            ],

Usage

Add "#[RowLevelSecurity]" attribute to your Entity associated with table under Row Level Security.

There are 3 required options for RowLevelSecurity attribute:

  • name: a name for policy which should be attached to the table
  • role: a name of role which should be attached to RowLevelSecurity users
  • using: a sql clause which describes the role's access condition

Then you can use doctrine:migrations:diff or doctrine:schema:create command as usual. SQL to enable Row Level Security will appear in your migration files or be executed on schema creation.