feat: add reassign_owned_to parameter to role ressource#613
Open
jBouyoud wants to merge 3 commits intocyrilgdn:mainfrom
Open
feat: add reassign_owned_to parameter to role ressource#613jBouyoud wants to merge 3 commits intocyrilgdn:mainfrom
jBouyoud wants to merge 3 commits intocyrilgdn:mainfrom
Conversation
c9392a3 to
2ef42e6
Compare
|
Really want to see that merged soon! |
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
This PR adds a new optional parameter
reassign_owned_toto thepostgresql_roleresource, allowing users to specify the role to which owned objects should be reassigned when dropping a role.Critical Fix (Jan 20, 2026): The implementation now correctly executes
REASSIGN OWNEDacross all accessible databases, not just the current one. This fixes a critical bug where roles with objects in multiple databases couldn't be properly cleaned up.Problem Solved
REASSIGN OWNED BY role TO targetoperates at the database level, not at the cluster level. The initial implementation only executed this command in the current database, causingDROP ROLEto fail when the role owned objects in other databases.Error encountered before fix
Changes
Core Functionality
reassign_owned_toattribute to thepostgresql_roleresource schemaresourcePostgreSQLRoleDeletefunction to use the specified role instead of always defaulting to the current database userREASSIGN OWNED+DROP OWNEDin each onelistDatabases()helper function inhelpers.gowith comprehensive unit testsTesting
TestAccPostgresqlRole_ReassignOwnedToto validate the functionalitylistDatabases()function usinggo-sqlmock:Documentation
Behavior
When a role is deleted:
reassign_owned_tois set, owned objects are reassigned to the specified role in all databasesreassign_owned_tois not set, the default behavior is preserved (reassign to current user in all databases)skip_reassign_ownedistrue, thereassign_owned_toparameter is ignoredtemplate0,template1) and non-connectable databases are excludedImplementation Details
Query used to list databases
Multi-database execution flow
REASSIGN OWNED BY role TO targetDROP OWNED BY roleDROP ROLEat the cluster levelExample Usage
When
temp_roleis destroyed, all objects owned bytemp_rolein all databases will be reassigned toadmin_rolebefore the role is dropped.Files Modified
postgresql/helpers.go: NewlistDatabases()helper functionpostgresql/helpers_test.go: Unit tests forlistDatabases()postgresql/resource_postgresql_role.go: Multi-database REASSIGN OWNED logicpostgresql/resource_postgresql_role_test.go: Acceptance testImpact
Related
This change is useful when managing roles in environments where: