You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stop additive mode from rewriting attributes and comments on pre-existing roles
add profile-level generated-role inherit support and thread it through the operator CRD
make CLI execution stick to a single backend and include backend identity in SQL execution failures
update user-facing docs for additive brownfield behavior and generated-role attributes
Why
A brownfield role like accounts_editor LOGIN NOINHERIT could cause additive mode to plan ALTER ROLE ... NOLOGIN INHERIT, which is not consistent with additive adoption semantics.
In environments where one hostname can resolve to multiple PostgreSQL servers, one-shot CLI commands could also inspect one backend and execute mutations against another. This change reduces that risk by keeping CLI execution on a single connection and improves diagnosis by surfacing backend identity when SQL execution fails.
This pull request extends profile-generated roles to support the inherit attribute, implements filtering of destructive changes in additive reconciliation mode to preserve pre-existing role attributes and comments, and enhances error reporting in the CLI. Changes span CRD schema extensions, core manifest expansion and change filtering logic, comprehensive documentation clarifications, and integration tests validating the new behaviors.
Updated documentation to clarify that additive mode preserves pre-existing role attributes and comments, and that profile-generated roles support the inherit attribute with defaults of login: false (NOLOGIN) and inherit: true (INHERIT).
Documentation: Manifest & Features docs/src/pages/docs/manifest-format.md
New comprehensive section introducing profiles as reusable templates with field reference (login, inherit, grants, default_privileges) and callout describing additive mode preservation semantics for existing roles.
Extended CRD schema to add optional nullable inherit boolean property to profile object definitions in spec.profiles.
Core Manifest & Profile Support crates/pgroles-core/src/manifest.rs, crates/pgroles-operator/src/crd.rs
Added inherit: Option<bool> field to Profile struct; implemented propagation of profile-level inherit to generated role's inherit field during manifest expansion and CRD-to-manifest conversion; updated and added tests verifying default/explicit inherit handling.
Modified filter_additive_changes to treat AlterRole and SetComment as destructive and remove them from applied change set; updated test expectations to verify absence of these changes.
Test Infrastructure & Integration Tests crates/pgroles-cli/tests/cli.rs, crates/pgroles-core/src/composition.rs
Added database URL construction utilities and role attribute inspection helpers; introduced integration tests validating additive mode does not rewrite pre-existing role attributes and that generated roles preserve profile-level inherit settings; updated test fixture to include new inherit field.
Refactored apply logic: centralized statement execution into execute_changes helper; enhanced database connectivity with PgPoolOptions and max_connections(1); added backend context fetching and improved error reporting to include SQLSTATE and backend details on statement failure; introduced unit tests for render_execution_failure with database and non-database error cases.
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
🐰 With whiskers twitching bright and proud,
Profiles now inherit without cloud!
Additive mode keeps what's already there,
No pre-existing roles need repair,
Schema-bound roles dance without a care! 🌿
The title clearly summarizes the main change: preventing additive reconciliation mode from rewriting attributes on pre-existing brownfield roles.
Linked Issues check
✅ Passed
The PR successfully implements all linked issue #94 objectives: additive mode filters AlterRole/SetComment for pre-existing roles, inherit attribute support is added to profiles and propagated through the CRD, SQL error classification is improved in execute_changes, and comprehensive regression tests are included.
Out of Scope Changes check
✅ Passed
All changes are directly related to issue #94: additive mode filtering, profile inherit support, CRD updates, test coverage, documentation updates, and CLI error handling improvements. No unrelated changes detected.
Docstring Coverage
✅ Passed
Docstring coverage is 81.63% which is sufficient. The required threshold is 80.00%.
Description Check
✅ Passed
Check skipped - CodeRabbit’s high-level summary is enabled.
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches📝 Generate docstrings
Create stacked PR
Commit on current branch
🧪 Generate unit tests (beta)
Create PR with unit tests
Commit unit tests in branch fix/additive-role-attrs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
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
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.
Summary
inheritsupport and thread it through the operator CRDWhy
A brownfield role like
accounts_editor LOGIN NOINHERITcould cause additive mode to planALTER ROLE ... NOLOGIN INHERIT, which is not consistent with additive adoption semantics.In environments where one hostname can resolve to multiple PostgreSQL servers, one-shot CLI commands could also inspect one backend and execute mutations against another. This change reduces that risk by keeping CLI execution on a single connection and improves diagnosis by surfacing backend identity when SQL execution fails.
Validation
Fixes #94