[PR #5987] feat(drizzle): Add Row Level Security (RLS) support for PSQL when using drizzle #14611

Closed
opened 2026-04-13 09:32:30 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5987

State: closed
Merged: No


Add PostgreSQL Row Level Security (RLS) to Drizzle Schema Generator

Summary

Adds optional Row Level Security (RLS) support when generating Drizzle schemas for PostgreSQL. When enabled, generated tables automatically include .enableRLS().


Changes

Core

  • Added enableRLS option to DrizzleAdapterConfig (PostgreSQL only).
  • Schema generator now checks adapter.options?.enableRLS and appends .enableRLS() to each table definition.
  • RLS is only applied when the provider is PostgreSQL and the flag is enabled ( all other providers will simply ignore this flag )

Testing

  • Added tests for PostgreSQL with RLS enabled.
  • Added tests for PostgreSQL + passkey plugin with RLS.
  • Added snapshots for RLS-enabled schema generation.

Usage

const adapter = drizzleAdapter(db, {
  provider: "pg",
  schema: {},
  enableRLS: true, // Enable RLS
});

Technical Details

  • RLS applies only when:

    • databaseType === "pg"
    • adapter.options?.enableRLS === true
  • .enableRLS() is appended to every pgTable() call.



Summary by cubic

Adds optional PostgreSQL Row Level Security to Drizzle schema generation. When enableRLS is true in the adapter config, generated pgTable() definitions include .enableRLS().

  • New Features
    • Added enableRLS?: boolean to DrizzleAdapterConfig (PostgreSQL only).
    • Generator appends .enableRLS() to tables when provider === "pg" and enableRLS is true.
    • Other providers ignore this flag.
    • Added tests and snapshots for RLS (including passkey plugin).

Written for commit 5600ca1725. Summary will update automatically on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5987 **State:** closed **Merged:** No --- ## Add PostgreSQL Row Level Security (RLS) to Drizzle Schema Generator ### Summary Adds optional Row Level Security (RLS) support when generating Drizzle schemas for PostgreSQL. When enabled, generated tables automatically include `.enableRLS()`. --- ### Changes #### Core * Added `enableRLS` option to `DrizzleAdapterConfig` (PostgreSQL only). * Schema generator now checks `adapter.options?.enableRLS` and appends `.enableRLS()` to each table definition. * RLS is only applied when the provider is PostgreSQL and the flag is enabled ( all other providers will simply ignore this flag ) #### Testing * Added tests for PostgreSQL with RLS enabled. * Added tests for PostgreSQL + passkey plugin with RLS. * Added snapshots for RLS-enabled schema generation. --- ### Usage ```ts const adapter = drizzleAdapter(db, { provider: "pg", schema: {}, enableRLS: true, // Enable RLS }); ``` --- ### Technical Details * RLS applies only when: * `databaseType === "pg"` * `adapter.options?.enableRLS === true` * `.enableRLS()` is appended to every `pgTable()` call. --- <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds optional PostgreSQL Row Level Security to Drizzle schema generation. When enableRLS is true in the adapter config, generated pgTable() definitions include .enableRLS(). - New Features - Added enableRLS?: boolean to DrizzleAdapterConfig (PostgreSQL only). - Generator appends .enableRLS() to tables when provider === "pg" and enableRLS is true. - Other providers ignore this flag. - Added tests and snapshots for RLS (including passkey plugin). <sup>Written for commit 5600ca1725833c66f3b281d085151103aabe90f3. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:32:30 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#14611