-
Notifications
You must be signed in to change notification settings - Fork 226
Set-SqlDscDatabaseProperty: Refactor command
#2327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
913e672
`Set-SqlDscDatabase`: Refactor command
johlju 8d3f53c
Update Get-SqlDscDatabase calls to include ErrorAction parameter for …
johlju 4b60d19
Remove CatalogCollation parameter and update documentation for read-o…
johlju 8633f82
Update CHANGELOG.md to clarify removal of OwnerName parameter and add…
johlju 31bd4b7
Enhance Set-SqlDscDatabaseOwner with idempotence check and error hand…
johlju cfad5dd
Update Set-SqlDscDatabase documentation to clarify output behavior fo…
johlju c42783f
Fix error handling in Set-SqlDscDatabase to use correct database obje…
johlju a707b2a
Update compatibility level in Set-SqlDscDatabase tests to Version140 …
johlju 6ae63ed
Add integration tests for Get-SqlDscCompatibilityLevel to verify comp…
johlju 5586319
Refactor assertions in Set-SqlDscDatabase integration tests to use Sh…
johlju 5f69cce
Add ErrorAction parameter to Get-SqlDscDatabase calls for improved er…
johlju 929a663
Fix build script path in test files for correct dependency resolution
johlju 914d116
Refactor Set-SqlDscDatabase tests to improve readability and add para…
johlju 8a5caae
Add parameter validation tests for Set-SqlDscDatabaseOwner to ensure …
johlju baea0a7
Add Refresh parameter to Set-SqlDscDatabase call in test for desired …
johlju e8b5bc3
Refactor Get-SqlDscCompatibilityLevel function to improve readability…
johlju 81587d9
Add suppression message for ScriptAnalyzer rule in Get-SqlDscCompatib…
johlju cfa078c
Add Refresh parameter to Set-SqlDscDatabase calls in tests for improv…
johlju b5af528
Add AfterAll block to disconnect from SQL database engine in Get-SqlD…
johlju 1bf9a9d
Update stream redirection in test scripts to use the correct error st…
johlju a358150
Refactor Set-SqlDscDatabase to support all settable SMO Database prop…
johlju 54ba3af
Add VersionMajor property to object initialization in SMO stub for en…
johlju 0a6cc35
Add ErrorAction parameter to database connection and disconnection fo…
johlju 8ac28ba
Add ErrorAction parameter to Connect-SqlDscDatabaseEngine and Disconn…
johlju 77db78a
Add justification for suppressing PSUseDeclaredVarsMoreThanAssignment…
johlju 063a2d0
Add tests for validating parameter sets in Get-SqlDscCompatibilityLevel
johlju 806c6fc
Enhance mock server object by adding Refresh method to database colle…
johlju f29221f
Refactor Set-SqlDscDatabase to remove deprecated parameters and updat…
johlju 308841f
Remove unused SetOwner method from mock database object in Set-SqlDsc…
johlju 589c804
Add IsReadCommittedSnapshotOn parameter to Set-SqlDscDatabase and upd…
johlju 5f22e1f
Add Set-SqlDscDatabaseProperty function to manage SQL Server database…
johlju da74cd8
Rename Set-SqlDscDatabase to Set-SqlDscDatabaseProperty and update re…
johlju 03d87de
Add integration tests for Set-SqlDscDatabaseProperty to validate data…
johlju bf0579b
Add unit tests for Set-SqlDscDatabaseProperty to validate database pr…
johlju a9cbc61
Add parameters for DatabaseSnapshotBaseName, IsLedger, IsParameteriza…
johlju 91f92e8
Add CatalogCollation parameter to New-SqlDscDatabase for system catal…
johlju c67fb70
Update type assertion for Set-SqlDscDatabaseProperty result to use ty…
johlju 141c8fd
Remove OwnerName parameter from Set-SqlDscDatabaseProperty tests afte…
johlju eef8600
Add detailed status messages for Set-SqlDscDatabaseProperty and Set-S…
johlju 17ba394
Add localized error message for property not found in Set-SqlDscDatab…
johlju f9bf9ca
Add Set-SqlDscDatabaseOwner integration tests to pipeline
johlju 57b181b
Remove DefaultFullTextCatalog parameter and update MaxSizeInBytes typ…
johlju 0bdc7fb
Update MaxSizeInBytes type to Double in parameter sets for Set-SqlDsc…
johlju 9d98844
Fix Describe block name in Set-SqlDscDatabaseProperty tests
johlju d754bb3
Add note about SQL Server version requirement for CatalogCollation pa…
johlju d638be6
Add validation for CatalogCollation parameter and error message for u…
johlju 6d34ecb
Add DelayedDurability parameter to Set-SqlDscDatabaseProperty and def…
johlju 5a4f5ac
Fix error handling in Set-SqlDscDatabaseProperty to target the databa…
johlju be7d199
Change DelayedDurability property to use enum type in SMO stub
johlju d6b18d5
Update parameter sets in Set-SqlDscDatabaseProperty tests to include …
johlju c5cd62b
Add CatalogCollationType enum and update parameter set in New-SqlDscD…
johlju f29296f
Add refresh logic for database owner in Set-SqlDscDatabaseOwner funct…
johlju e191872
Implement feature X to enhance user experience and fix bug Y in module Z
johlju ff38703
Change CatalogCollation property to use CatalogCollationType enum for…
johlju 4554951
Fix comments for clarity in BeforeDiscovery block of Set-SqlDscDataba…
johlju df95655
Refactor Set-SqlDscDatabaseOwner test to ensure SetOwner is not calle…
johlju d7a512a
Add CatalogCollation property to enum properties in database property…
johlju 527ae77
Update Get-SqlDscDatabase calls to include Refresh parameter for accu…
johlju 1878d66
Enhance Set-SqlDscDatabaseOwner to call Alter after setting owner for…
johlju 810fe69
Add refresh logic to Get-SqlDscDatabase for updated database object r…
johlju 75271aa
Add verbose logging for original database owner and update Set-SqlDsc…
johlju 689fdfe
Add DropExistingUser parameter to Set-SqlDscDatabaseOwner for user ac…
johlju 4959ec0
Add Refresh method to SMO class for improved state management
johlju 9559d31
Refactor Set-SqlDscDatabaseOwner to ensure database object is refresh…
johlju a7ba2b8
Remove obsolete test case for non-existent database in Set-SqlDscData…
johlju 480db6b
Update error code in Set-SqlDscDatabaseOwner for improved error handling
johlju a00092a
Fix formatting in documentation for Set-SqlDscDatabaseOwner parameter…
johlju 1f2dd60
Comment out Alter method calls in Set-SqlDscDatabaseOwner for debuggi…
johlju 4a7a5d3
Remove commented Alter method calls in Set-SqlDscDatabaseOwner for cl…
johlju 9a86402
Add Get-SqlDscCompatibilityLevel integration test to pipeline and doc…
johlju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Sets the owner of a database in a SQL Server Database Engine instance. | ||
|
|
||
| .DESCRIPTION | ||
| This command sets the owner of a database in a SQL Server Database Engine instance. | ||
|
|
||
| The owner must be a valid login on the SQL Server instance. The command uses | ||
| the SetOwner() method on the SMO Database object to change the ownership. | ||
|
|
||
| .PARAMETER ServerObject | ||
| Specifies current server connection object. | ||
|
|
||
| .PARAMETER Name | ||
| Specifies the name of the database to modify. | ||
|
|
||
| .PARAMETER DatabaseObject | ||
| Specifies the database object to modify (from Get-SqlDscDatabase). | ||
|
|
||
| .PARAMETER Refresh | ||
| Specifies that the **ServerObject**'s databases should be refreshed before | ||
| trying to get the database object. This is helpful when databases could have been | ||
| modified outside of the **ServerObject**, for example through T-SQL. But | ||
| on instances with a large amount of databases it might be better to make | ||
| sure the **ServerObject** is recent enough. | ||
|
|
||
| This parameter is only used when setting owner using **ServerObject** and | ||
| **Name** parameters. | ||
|
|
||
| .PARAMETER OwnerName | ||
| Specifies the name of the login that should be the owner of the database. | ||
|
|
||
| .PARAMETER Force | ||
| Specifies that the database owner should be modified without any confirmation. | ||
|
|
||
| .PARAMETER PassThru | ||
| Specifies that the database object should be returned after modification. | ||
|
|
||
| .EXAMPLE | ||
| $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance' | ||
| Set-SqlDscDatabaseOwner -ServerObject $serverObject -Name 'MyDatabase' -OwnerName 'sa' | ||
|
|
||
| Sets the owner of the database named **MyDatabase** to **sa**. | ||
|
|
||
| .EXAMPLE | ||
| $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance' | ||
| $databaseObject = $serverObject | Get-SqlDscDatabase -Name 'MyDatabase' | ||
| Set-SqlDscDatabaseOwner -DatabaseObject $databaseObject -OwnerName 'DOMAIN\SqlAdmin' -Force | ||
|
|
||
| Sets the owner of the database using a database object without prompting for confirmation. | ||
|
|
||
| .EXAMPLE | ||
| $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance' | ||
| Set-SqlDscDatabaseOwner -ServerObject $serverObject -Name 'MyDatabase' -OwnerName 'sa' -PassThru | ||
|
|
||
| Sets the owner and returns the updated database object. | ||
|
|
||
| .INPUTS | ||
| `[Microsoft.SqlServer.Management.Smo.Database]` | ||
|
|
||
| The database object to modify (from Get-SqlDscDatabase). | ||
|
|
||
| .OUTPUTS | ||
| None. But when **PassThru** is specified the output is `[Microsoft.SqlServer.Management.Smo.Database]`. | ||
| #> | ||
| function Set-SqlDscDatabaseOwner | ||
| { | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues.')] | ||
| [OutputType()] | ||
| [OutputType([Microsoft.SqlServer.Management.Smo.Database])] | ||
| [CmdletBinding(DefaultParameterSetName = 'ServerObjectSet', SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] | ||
| param | ||
| ( | ||
| [Parameter(ParameterSetName = 'ServerObjectSet', Mandatory = $true)] | ||
| [Microsoft.SqlServer.Management.Smo.Server] | ||
| $ServerObject, | ||
|
|
||
| [Parameter(ParameterSetName = 'ServerObjectSet', Mandatory = $true)] | ||
| [ValidateNotNullOrEmpty()] | ||
| [System.String] | ||
| $Name, | ||
|
|
||
| [Parameter(ParameterSetName = 'ServerObjectSet')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| $Refresh, | ||
|
|
||
| [Parameter(ParameterSetName = 'DatabaseObjectSet', Mandatory = $true, ValueFromPipeline = $true)] | ||
| [Microsoft.SqlServer.Management.Smo.Database] | ||
| $DatabaseObject, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [ValidateNotNullOrEmpty()] | ||
| [System.String] | ||
| $OwnerName, | ||
|
|
||
| [Parameter()] | ||
| [System.Management.Automation.SwitchParameter] | ||
| $Force, | ||
|
|
||
| [Parameter()] | ||
| [System.Management.Automation.SwitchParameter] | ||
| $PassThru | ||
| ) | ||
|
|
||
| begin | ||
| { | ||
| if ($Force.IsPresent -and -not $Confirm) | ||
| { | ||
| $ConfirmPreference = 'None' | ||
| } | ||
| } | ||
|
|
||
| process | ||
| { | ||
| # Get the database object based on the parameter set | ||
| switch ($PSCmdlet.ParameterSetName) | ||
| { | ||
| 'ServerObjectSet' | ||
| { | ||
| $previousErrorActionPreference = $ErrorActionPreference | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| $sqlDatabaseObject = $ServerObject | | ||
| Get-SqlDscDatabase -Name $Name -Refresh:$Refresh -ErrorAction 'Stop' | ||
|
|
||
| $ErrorActionPreference = $previousErrorActionPreference | ||
| } | ||
|
|
||
| 'DatabaseObjectSet' | ||
| { | ||
| $sqlDatabaseObject = $DatabaseObject | ||
| } | ||
| } | ||
|
|
||
| $verboseDescriptionMessage = $script:localizedData.DatabaseOwner_Set_ShouldProcessVerboseDescription -f $sqlDatabaseObject.Name, $OwnerName, $sqlDatabaseObject.Parent.InstanceName | ||
| $verboseWarningMessage = $script:localizedData.DatabaseOwner_Set_ShouldProcessVerboseWarning -f $sqlDatabaseObject.Name, $OwnerName | ||
| $captionMessage = $script:localizedData.DatabaseOwner_Set_ShouldProcessCaption | ||
|
|
||
| if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage)) | ||
| { | ||
| Write-Debug -Message ($script:localizedData.DatabaseOwner_Updating -f $sqlDatabaseObject.Name, $OwnerName) | ||
| $sqlDatabaseObject.SetOwner($OwnerName) | ||
| Write-Debug -Message ($script:localizedData.DatabaseOwner_Updated -f $sqlDatabaseObject.Name, $OwnerName) | ||
|
|
||
| if ($PassThru.IsPresent) | ||
| { | ||
| return $sqlDatabaseObject | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.