Repository navigation
feat(backend): add PostgreSQL Row-Level Security POLICY DDL expressions - #52
Merged
Merged
Conversation
Add PostgresCreatePolicyExpression, PostgresAlterPolicyExpression, and PostgresDropPolicyExpression (plus PolicyType/PolicyCommand/AlterPolicyMode enums) so RLS policies can be administered through the Expression-Dialect pipeline. The new PostgresPolicyMixin provides version-gated formatters (PG 9.5+ for basic CREATE/ALTER/DROP, 10+ for AS RESTRICTIVE and explicit AS PERMISSIVE, 15+ for the CURRENT_ROLE role keyword) and capability switches; PostgresPolicySupport is the matching @runtime_checkable Protocol. POLICY is a PostgreSQL extension, not SQL-standard, so it is implemented in the postgres backend package only; the core library is untouched. Note: changelog.d/0.added.md is a placeholder fragment — rename it to the actual PR number once assigned before merging.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release/v1.0.0.dev16 #52 +/- ##
========================================================
+ Coverage 73.24% 73.58% +0.34%
========================================================
Files 278 281 +3
Lines 11364 11590 +226
Branches 1841 1879 +38
========================================================
+ Hits 8323 8529 +206
- Misses 2441 2456 +15
- Partials 600 605 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
8 of 12 tasks
vistart
added a commit
that referenced
this pull request
Aug 15, 2026
…ns (#52) * feat(backend): add PostgreSQL Row-Level Security POLICY DDL expressions Add PostgresCreatePolicyExpression, PostgresAlterPolicyExpression, and PostgresDropPolicyExpression (plus PolicyType/PolicyCommand/AlterPolicyMode enums) so RLS policies can be administered through the Expression-Dialect pipeline. The new PostgresPolicyMixin provides version-gated formatters (PG 9.5+ for basic CREATE/ALTER/DROP, 10+ for AS RESTRICTIVE and explicit AS PERMISSIVE, 15+ for the CURRENT_ROLE role keyword) and capability switches; PostgresPolicySupport is the matching @runtime_checkable Protocol. POLICY is a PostgreSQL extension, not SQL-standard, so it is implemented in the postgres backend package only; the core library is untouched. Note: changelog.d/0.added.md is a placeholder fragment — rename it to the actual PR number once assigned before merging. * ci: bump postgres 19 job from 19beta1 to 19beta2 (PGQ) * chore: add changelog fragment for PR #52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Adds PostgreSQL Row-Level Security (RLS)
POLICYDDL expressions so policies can be administered through the Expression-Dialect pipeline. New expressions:PostgresCreatePolicyExpression—CREATE POLICY ... ON ... AS ... FOR ... TO ... USING ... WITH CHECK ...PostgresAlterPolicyExpression—ALTER POLICY ... RENAME TO .../ALTER POLICY ... TO ... USING ... WITH CHECK ...PostgresDropPolicyExpression—DROP POLICY ... [CASCADE | RESTRICT]plus
PolicyType,PolicyCommand,AlterPolicyModeenums inexpression/ddl/policy.py.The new
PostgresPolicyMixinprovides version-gatedformat_*methods and capability switches:CREATE/ALTER/DROP POLICYAS RESTRICTIVEand explicitAS PERMISSIVEkeyword (AS PERMISSIVEis silently omitted on 9.5)CURRENT_ROLErole keyword in theTOclausePostgresPolicySupportis the corresponding@runtime_checkableProtocol, wired into the dialect alongside the mixin.Design note (归层):
POLICYis a PostgreSQL extension, not a SQL-standard statement, so all implementation lives in thepython-activerecord-postgresbackend package only; the core library (backend/expression/statements/) is untouched.Scope note: This PR intentionally does NOT include the RLS
ALTER TABLE ... ENABLE/FORCE/DISABLE ROW LEVEL SECURITYexpressions nor policy introspection (planned as a follow-up).Type of change
feat: A new featureci: Bump thepostgres 19CI job from19beta1to19beta2(PGQ)Breaking Change
Impact on End-Users:
No backward-incompatible changes; this adds opt-in RLS policy expressions only.
Impact on Backend Developers (Custom Implementations):
No breaking changes.
Related Repositories/Packages
None — PostgreSQL-only feature, contained within this repository.
Testing
Test Plan:
tests/rhosocial/activerecord_postgres_test/feature/backend/postgres/test_policy.py(64 assertions).test_ddl_protocols.py(2 runtime-checkable conformance cases).PYTHONPATH=src pytest tests/.test.yml): matrix of Python 3.8–3.14 × PostgreSQL 9–18 allsuccess; PG19beta2/PGQ jobsuccess(5353 passed, skipped = the extension-not-available/version-gated cases).Checklist
changelog.d/0.added.md— placeholder; will be renamed to the PR number once assigned).Additional Notes
changelog.d/0.added.md. After this PR is created, the fragment will be renamed tochangelog.d/<pr_number>.added.mdin a follow-up commit (per.claude/version_control.mdand the49→50precedent).