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

Open
opened 2026-03-13 12:56:06 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5987
Author: @uripg
Created: 11/14/2025
Status: 🔄 Open

Base: canaryHead: feat/add-row-level-security-support-to-drizzle-adapter


📝 Commits (4)

  • e1697f1 feat(drizzle): add Row Level Security (RLS) support for PostgreSQL in Drizzle schema generation
  • 6542bf0 feat(tests): add tests for PostgreSQL schema generation with RLS and passkey plugin
  • 0424554 chore: minor formatting
  • 5600ca1 feat(drizzle): add enableRLS option to DrizzleAdapterConfig for PostgreSQL support

📊 Changes

5 files changed (+309 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts (+7 -0)
📝 packages/cli/src/generators/drizzle.ts (+3 -1)
packages/cli/test/__snapshots__/auth-schema-pg-passkey-rls-enabled.txt (+103 -0)
packages/cli/test/__snapshots__/auth-schema-pg-rls-enabled.txt (+110 -0)
📝 packages/cli/test/generate-all-db.test.ts (+86 -0)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5987 **Author:** [@uripg](https://github.com/uripg) **Created:** 11/14/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/add-row-level-security-support-to-drizzle-adapter` --- ### 📝 Commits (4) - [`e1697f1`](https://github.com/better-auth/better-auth/commit/e1697f1eec6cabbf403294a6b8f30b8f91213811) feat(drizzle): add Row Level Security (RLS) support for PostgreSQL in Drizzle schema generation - [`6542bf0`](https://github.com/better-auth/better-auth/commit/6542bf03929f2b951ab41972cb082e589c486605) feat(tests): add tests for PostgreSQL schema generation with RLS and passkey plugin - [`0424554`](https://github.com/better-auth/better-auth/commit/0424554fd2824ea96997418b9bdf8c763c81aca7) chore: minor formatting - [`5600ca1`](https://github.com/better-auth/better-auth/commit/5600ca1725833c66f3b281d085151103aabe90f3) feat(drizzle): add enableRLS option to DrizzleAdapterConfig for PostgreSQL support ### 📊 Changes **5 files changed** (+309 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts` (+7 -0) 📝 `packages/cli/src/generators/drizzle.ts` (+3 -1) ➕ `packages/cli/test/__snapshots__/auth-schema-pg-passkey-rls-enabled.txt` (+103 -0) ➕ `packages/cli/test/__snapshots__/auth-schema-pg-rls-enabled.txt` (+110 -0) 📝 `packages/cli/test/generate-all-db.test.ts` (+86 -0) </details> ### 📄 Description ## 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. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:56:06 -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#6364