Skip to content
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

Set-DcnConfiguration: create config database as 'simple' by default #174

Merged
merged 2 commits into from
Mar 5, 2022

Conversation

lowlydba
Copy link
Contributor

@lowlydba lowlydba commented Mar 4, 2022

Fixes #173 by using the more robust New-DbaDatabase versus inline TSQL.

@sanderstad
Copy link
Collaborator

sanderstad commented Mar 4, 2022

Thanks for taking the time to make the module better.
It may be a good idea to instead just setting the database to simple, to make a default when the recovery model is not supplied as a parameter to the command.
That means another parameter for this command like

    param(
        [ValidateSet('SQL', 'File')]
        [string]$InformationStore,
        [parameter(ParameterSetName = "SQL", Mandatory = $true)]
        [DbaInstanceParameter]$SqlInstance,
        [parameter(ParameterSetName = "SQL")]
        [PSCredential]$SqlCredential,
        [parameter(ParameterSetName = "SQL")]
        [string]$Database,
        [parameter(ParameterSetName = "SQL")]
        [string]$RecoveryModel,
        [parameter(ParameterSetName = "File", Mandatory = $true)]
        [string]$Path,
        [parameter(ParameterSetName = "File")]
        [PSCredential]$Credential,
        [switch]$EnableException,
        [parameter(ParameterSetName = "Prompt")]
        [switch]$InputPrompt,
        [switch]$Force
    )

And a check at the end of the begin block that checks for that parameter together with the $InformationStore:

        if (($InformationStore -eq 'SQL') -and (-not $RecoveryModel)) {
            Write-PSFMessage -Message "Setting recovery model for database to 'Simple'" -Level Verbose
            $RecoveryModel = 'Simple'
        }

After that we can just made the New-DbaDatabase command work more efficient:

$params = @{
        SqlInstance = $SqlInstance 
        SqlCredential = $SqlCredential 
        Name = $Database 
        RecoveryModel $RecoveryModel 
        EnableException = $true
}
New-DbaDatabase @params

Copy link
Collaborator

@sanderstad sanderstad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks great

@sanderstad sanderstad merged commit dd8e47a into dataplat:development Mar 5, 2022
@lowlydba lowlydba deleted the patch-4 branch March 5, 2022 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set-DcnConfiguration: Create database in SIMPLE recovery model
2 participants