-
Notifications
You must be signed in to change notification settings - Fork 228
Test-SqlDscIsDatabase: Check database existence #2325
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 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a1a9c9b
Refactor Test-SqlDscDatabaseProperty integration tests to use persist…
johlju e654cab
Add Refresh parameter to Test-SqlDscDatabaseProperty for database upd…
johlju d1baa0c
Add tests for Refresh parameter in Test-SqlDscDatabaseProperty
johlju 1fe35fd
Remove Test-SqlDscDatabase and associated integration and unit tests
johlju a2b4c31
`Test-SqlDscIsDatabase`: Check database existence
johlju ab23d12
Remove verbose output tests from Test-SqlDscIsDatabase for simplifica…
johlju 167aa91
Remove redundant public command `Test-SqlDscDatabase` and update docu…
johlju 3810751
Add identifier to IsDatabase_Test message for tracking purposes
johlju 6dba92b
Add INPUTS section to documentation for Test-SqlDscIsDatabase
johlju 0bb8d5b
Add -ErrorAction 'Stop' to Test-SqlDscIsDatabase integration tests fo…
johlju f7aa355
Refactor Test-SqlDscIsDatabase tests to use Mock for Get-SqlDscDataba…
johlju 9180e47
Enhance Test-SqlDscIsDatabase tests by mocking Get-SqlDscDatabase for…
johlju 27581fe
Add -ErrorAction 'Stop' to case sensitivity tests in Test-SqlDscIsDat…
johlju 5ddf7e5
Add clarification to OUTPUTS section in Test-SqlDscIsDatabase documen…
johlju 9abef83
Fix database name reference in comprehensive property tests for consi…
johlju cd79e93
Fix hardcoded database name in Test-SqlDscDatabaseProperty tests for …
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
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
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 was deleted.
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
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,79 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Tests if a database exists on a SQL Server Database Engine instance. | ||
|
|
||
| .DESCRIPTION | ||
| This command tests if a database exists on a SQL Server Database Engine instance. | ||
|
|
||
| .PARAMETER ServerObject | ||
| Specifies current server connection object. | ||
|
|
||
| .PARAMETER Name | ||
| Specifies the name of the database to test for existence. | ||
|
|
||
| .PARAMETER Refresh | ||
| Specifies that the **ServerObject**'s databases should be refreshed before | ||
| testing the database existence. 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. | ||
|
|
||
| .EXAMPLE | ||
| $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance' | ||
| $serverObject | Test-SqlDscIsDatabase -Name 'MyDatabase' | ||
|
|
||
| Tests if the database named **MyDatabase** exists on the instance. | ||
|
|
||
| .EXAMPLE | ||
| $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance' | ||
| Test-SqlDscIsDatabase -ServerObject $serverObject -Name 'MyDatabase' -Refresh | ||
|
|
||
| Tests if the database named **MyDatabase** exists on the instance, refreshing | ||
| the server object's databases collection first. | ||
|
|
||
| .OUTPUTS | ||
| `[System.Boolean]` | ||
|
|
||
| .INPUTS | ||
| `[Microsoft.SqlServer.Management.Smo.Server]` | ||
|
|
||
| The server object can be provided via the pipeline to **ServerObject**. | ||
| #> | ||
| function Test-SqlDscIsDatabase | ||
| { | ||
| [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/8.')] | ||
| [OutputType([System.Boolean])] | ||
| [CmdletBinding()] | ||
| param | ||
| ( | ||
| [Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
| [Microsoft.SqlServer.Management.Smo.Server] | ||
| $ServerObject, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [ValidateNotNullOrEmpty()] | ||
| [System.String] | ||
| $Name, | ||
|
|
||
| [Parameter()] | ||
| [System.Management.Automation.SwitchParameter] | ||
| $Refresh | ||
| ) | ||
|
|
||
| process | ||
| { | ||
| Write-Verbose -Message ($script:localizedData.IsDatabase_Test -f $Name, $ServerObject.InstanceName) | ||
|
|
||
| # Check if database exists using Get-SqlDscDatabase | ||
| $sqlDatabaseObject = Get-SqlDscDatabase -ServerObject $ServerObject -Name $Name -Refresh:$Refresh -ErrorAction 'SilentlyContinue' | ||
|
|
||
| if ($sqlDatabaseObject) | ||
| { | ||
| return $true | ||
| } | ||
| else | ||
| { | ||
| return $false | ||
| } | ||
| } | ||
| } | ||
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.