Skip to content

Commit

Permalink
Merge pull request #982 from jpomfret/psconf
Browse files Browse the repository at this point in the history
PSConfEU demos and stuff
  • Loading branch information
jpomfret authored Jun 21, 2023
2 parents 4e4f8ad + 63dbcaa commit d10e336
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
"[markdown]": {
"editor.trimAutoWhitespace": false,
"files.trimTrailingWhitespace": false
}
}
},
"cSpell.enableFiletypes": [
"powershell"
]
}
93 changes: 93 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,100 @@
# Contributing

## TODO
## Welcome

Before we go any further, thanks for being here. Thanks for using dbachecks and especially thanks
for being here and looking into how you can help!

## Important resources

- docs
- bugs
- communicate with the team
- slack
- github discussions?
- presentations\blogs?

## Running the Tests

If want to know how to run this module's tests you can look at the [Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines/#running-tests)

## Environment details

We strongly believe that 'every repo should have a devcontainer' and therefore we've built one
for this project that includes 3 SQL Servers and everything you need to develop and build the
dbachecks module.

It's magic!

### Prerequisites:

In order to use the devcontainer there are a few things you need to get started.

- [Docker](https://www.docker.com/get-started)
- [git](https://git-scm.com/downloads)
- [VSCode](https://code.visualstudio.com/download)
- [`Remote Development` Extension for VSCode](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)

### Setup

Once the prerequisites are in place follow these steps to download the repo and start up the
devcontainer. The first time you build the devcontainer it will need to pull down the images
so that could take a hot second depending on your internet speeds.

1. Download the repo from GitHub
```PowerShell
# change directory to where you'd like the repo to go
cd C:\GitHub\
# clone the repo from GitHub
git clone https://github.com/dataplat/dbachecks
# move into the folder
cd .\dbachecks\
# open VSCode
code .
```

754662. Once code opens, there should be a toast in the bottom right that suggests you 'ReOpen in Container'.
1. The first time you do this it may take a little, and you'll need an internet connection, as it'll download the container images used in our demos

### Develop & Build
TODO: sampler instructions - similar to /workspace/developing/Howto.md

### Rebuild

The only way to properly rebuild to ensure that all volumes etc are removed is to open up a console
or PowerShell window outside of the devcontainer and run the following:

```PowerShell
cd \path-of-dbachecks-folder\.devcontainer
docker-compose -f "docker-compose.yml" -p "bitsdbatools_devcontainer" down
```

## How to submit changes:
TODO:
Pull Request protocol etc. You might also include what response they'll get back from the team on submission, or any caveats about the speed of response.

## How to report a bug:
TODO:
Bugs are problems in code, in the functionality of an application or in its UI design; you can submit them through "bug trackers" and most projects invite you to do so, so that they may "debug" with more efficiency and the input of a contributor. Take a look at Atom's example for how to teach people to report bugs to your project.

## Templates:
TODO:
in this section of your file, you might also want to link to a bug report "template" like this one here which contributors can copy and add context to; this will keep your bugs tidy and relevant.

## Style Guide
TODO:
include extensions and vscode settings we use to keep things neat

## Code of Conduct
TODO: maybe beef this out - stolen from data sat repo for now.

We expect and demand that you follow some basic rules. Nothing dramatic here. There will be a proper code of conduct for the websites added soon, but in this repository

BE EXCELLENT TO EACH OTHER

Do I need to say more? If your behaviour or communication does not fit into this statement, we do not wish for you to help us.
48 changes: 48 additions & 0 deletions developing/PSConfEU demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# PSConfEU demo

1. Develop in the source repository
- copy existing check & rewrite - add check to `source/checks/Databasev5.Tests.ps1`
- add configuration to `source/internal/configurations/configuration.ps1`
- `skip.database.pseudosimple`
- `policy.database.pseudosimpleexcludedb`
- add object info to `source/internal/functions/Get-AllDatabaseInfo.ps1`


2. Build the module
```PowerShell
./build.ps1 -Tasks build
```

3. Sampler automatically adds the new version to your path
```PowerShell
get-module dbachecks -ListAvailable | select name, modulebase
```

4. Import new version of the module (if you get a bogus error the first time retry it)
```PowerShell
Import-Module dbachecks -force
```

5. Test out the new code

```PowerShell
# save the password to make for easy connections
$password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
$show = 'All'
$checks = 'RecoveryModel'
#$sqlinstances = 'localhost,7401', 'localhost,7402', 'localhost,7403'
$sqlinstances = 'dbachecks1', 'dbachecks2', 'dbachecks3' # need client aliases for this to work New-DbaClientAlias
# Run v4 checks
$v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru
# Run v5 checks
$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru -Verbose
Invoke-PerfAndValidateCheck -SQLInstances $sqlinstances -Checks $Checks
Invoke-PerfAndValidateCheck -SQLInstances $sqlinstances -Checks $Checks -PerfDetail
Invoke-PerfAndValidateCheck -SQLInstances $sqlinstances -Checks $Checks -showTestResults
```

10 changes: 10 additions & 0 deletions source/checks/Databasev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,13 @@ Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -Fo
}
}
}

Describe "Recovery Model" -Tag RecoveryModel, DISA, Medium, Database -ForEach $InstancesToTest {
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.recoverymodel').Value

Context "Testing Recovery Model" {
It "Database <_.Name> should be set to <_.ConfigValues.recoverymodeltype> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.recoverymodelexclude -notcontains $psitem.Name } } {
$psitem.RecoveryModel | Should -Be $psitem.ConfigValues.recoverymodeltype -Because "You expect this recovery model."
}
}
}
1 change: 1 addition & 0 deletions source/internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.autoupdatestatisticsasynchro
Set-PSFConfig -Module dbachecks -Name skip.database.trustworthy -Validation bool -Value $false -Initialize -Description "Skip the trustworthy database test"
Set-PSFConfig -Module dbachecks -Name skip.database.status -Validation bool -Value $false -Initialize -Description "Skip the database status test"
Set-PSFConfig -Module dbachecks -Name skip.database.compatibilitylevel -Validation bool -Value $false -Initialize -Description "Skip the database compatibility test"
Set-PSFConfig -Module dbachecks -Name skip.database.recoverymodel -Validation bool -Value $false -Initialize -Description "Skip the database recovery model test"


Set-PSFConfig -Module dbachecks -Name skip.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test"
Expand Down
6 changes: 6 additions & 0 deletions source/internal/functions/Get-AllDatabaseInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ function Get-AllDatabaseInfo {
$guestUserConnect = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'guestuserexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'database.guestuser.excludedb').Value
}
'RecoveryModel' {
$recoverymodel = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'recoverymodeltype' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.recoverymodel.type').Value
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'recoverymodelexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.recoverymodel.excludedb').Value
}
Default { }
}

Expand Down Expand Up @@ -174,6 +179,7 @@ function Get-AllDatabaseInfo {
CompatibilityLevel = @(if ($compatibilitylevel) { $psitem.CompatibilityLevel })
ServerLevel = @(if ($compatibilitylevel) { [Enum]::GetNames('Microsoft.SqlServer.Management.Smo.CompatibilityLevel').Where{ $psitem -match $Instance.VersionMajor } })
GuestUserConnect = @(if ($guestUserConnect) { if ($psitem.EnumDatabasePermissions('guest') | Where-Object { $_.PermissionState -eq 'Grant' -and $_.PermissionType.Connect }) { $true } } )
RecoveryModel = @(if ($recoverymodel) { $psitem.RecoveryModel })
}
}
}
Expand Down

0 comments on commit d10e336

Please sign in to comment.