Skip to content

Commit d10e336

Browse files
authored
Merge pull request #982 from jpomfret/psconf
PSConfEU demos and stuff
2 parents 4e4f8ad + 63dbcaa commit d10e336

File tree

6 files changed

+163
-2
lines changed

6 files changed

+163
-2
lines changed

.vscode/settings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@
4747
"[markdown]": {
4848
"editor.trimAutoWhitespace": false,
4949
"files.trimTrailingWhitespace": false
50-
}
51-
}
50+
},
51+
"cSpell.enableFiletypes": [
52+
"powershell"
53+
]
54+
}

CONTRIBUTING.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,100 @@
11
# Contributing
22

33
## TODO
4+
## Welcome
5+
6+
Before we go any further, thanks for being here. Thanks for using dbachecks and especially thanks
7+
for being here and looking into how you can help!
8+
9+
## Important resources
10+
11+
- docs
12+
- bugs
13+
- communicate with the team
14+
- slack
15+
- github discussions?
16+
- presentations\blogs?
417

518
## Running the Tests
619

720
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)
21+
22+
## Environment details
23+
24+
We strongly believe that 'every repo should have a devcontainer' and therefore we've built one
25+
for this project that includes 3 SQL Servers and everything you need to develop and build the
26+
dbachecks module.
27+
28+
It's magic!
29+
30+
### Prerequisites:
31+
32+
In order to use the devcontainer there are a few things you need to get started.
33+
34+
- [Docker](https://www.docker.com/get-started)
35+
- [git](https://git-scm.com/downloads)
36+
- [VSCode](https://code.visualstudio.com/download)
37+
- [`Remote Development` Extension for VSCode](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)
38+
39+
### Setup
40+
41+
Once the prerequisites are in place follow these steps to download the repo and start up the
42+
devcontainer. The first time you build the devcontainer it will need to pull down the images
43+
so that could take a hot second depending on your internet speeds.
44+
45+
1. Download the repo from GitHub
46+
```PowerShell
47+
# change directory to where you'd like the repo to go
48+
cd C:\GitHub\
49+
50+
# clone the repo from GitHub
51+
git clone https://github.com/dataplat/dbachecks
52+
53+
# move into the folder
54+
cd .\dbachecks\
55+
56+
# open VSCode
57+
code .
58+
```
59+
60+
754662. Once code opens, there should be a toast in the bottom right that suggests you 'ReOpen in Container'.
61+
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
62+
63+
### Develop & Build
64+
TODO: sampler instructions - similar to /workspace/developing/Howto.md
65+
66+
### Rebuild
67+
68+
The only way to properly rebuild to ensure that all volumes etc are removed is to open up a console
69+
or PowerShell window outside of the devcontainer and run the following:
70+
71+
```PowerShell
72+
cd \path-of-dbachecks-folder\.devcontainer
73+
74+
docker-compose -f "docker-compose.yml" -p "bitsdbatools_devcontainer" down
75+
```
76+
77+
## How to submit changes:
78+
TODO:
79+
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.
80+
81+
## How to report a bug:
82+
TODO:
83+
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.
84+
85+
## Templates:
86+
TODO:
87+
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.
88+
89+
## Style Guide
90+
TODO:
91+
include extensions and vscode settings we use to keep things neat
92+
93+
## Code of Conduct
94+
TODO: maybe beef this out - stolen from data sat repo for now.
95+
96+
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
97+
98+
BE EXCELLENT TO EACH OTHER
99+
100+
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.

developing/PSConfEU demo.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# PSConfEU demo
2+
3+
1. Develop in the source repository
4+
- copy existing check & rewrite - add check to `source/checks/Databasev5.Tests.ps1`
5+
- add configuration to `source/internal/configurations/configuration.ps1`
6+
- `skip.database.pseudosimple`
7+
- `policy.database.pseudosimpleexcludedb`
8+
- add object info to `source/internal/functions/Get-AllDatabaseInfo.ps1`
9+
10+
11+
2. Build the module
12+
```PowerShell
13+
./build.ps1 -Tasks build
14+
```
15+
16+
3. Sampler automatically adds the new version to your path
17+
```PowerShell
18+
get-module dbachecks -ListAvailable | select name, modulebase
19+
```
20+
21+
4. Import new version of the module (if you get a bogus error the first time retry it)
22+
```PowerShell
23+
Import-Module dbachecks -force
24+
```
25+
26+
5. Test out the new code
27+
28+
```PowerShell
29+
# save the password to make for easy connections
30+
$password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
31+
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
32+
33+
$show = 'All'
34+
$checks = 'RecoveryModel'
35+
36+
#$sqlinstances = 'localhost,7401', 'localhost,7402', 'localhost,7403'
37+
$sqlinstances = 'dbachecks1', 'dbachecks2', 'dbachecks3' # need client aliases for this to work New-DbaClientAlias
38+
39+
# Run v4 checks
40+
$v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru
41+
# Run v5 checks
42+
$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru -Verbose
43+
44+
Invoke-PerfAndValidateCheck -SQLInstances $sqlinstances -Checks $Checks
45+
Invoke-PerfAndValidateCheck -SQLInstances $sqlinstances -Checks $Checks -PerfDetail
46+
Invoke-PerfAndValidateCheck -SQLInstances $sqlinstances -Checks $Checks -showTestResults
47+
```
48+

source/checks/Databasev5.Tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,13 @@ Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -Fo
232232
}
233233
}
234234
}
235+
236+
Describe "Recovery Model" -Tag RecoveryModel, DISA, Medium, Database -ForEach $InstancesToTest {
237+
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.recoverymodel').Value
238+
239+
Context "Testing Recovery Model" {
240+
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 } } {
241+
$psitem.RecoveryModel | Should -Be $psitem.ConfigValues.recoverymodeltype -Because "You expect this recovery model."
242+
}
243+
}
244+
}

source/internal/configurations/configuration.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.autoupdatestatisticsasynchro
324324
Set-PSFConfig -Module dbachecks -Name skip.database.trustworthy -Validation bool -Value $false -Initialize -Description "Skip the trustworthy database test"
325325
Set-PSFConfig -Module dbachecks -Name skip.database.status -Validation bool -Value $false -Initialize -Description "Skip the database status test"
326326
Set-PSFConfig -Module dbachecks -Name skip.database.compatibilitylevel -Validation bool -Value $false -Initialize -Description "Skip the database compatibility test"
327+
Set-PSFConfig -Module dbachecks -Name skip.database.recoverymodel -Validation bool -Value $false -Initialize -Description "Skip the database recovery model test"
327328

328329

329330
Set-PSFConfig -Module dbachecks -Name skip.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test"

source/internal/functions/Get-AllDatabaseInfo.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ function Get-AllDatabaseInfo {
139139
$guestUserConnect = $true
140140
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'guestuserexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'database.guestuser.excludedb').Value
141141
}
142+
'RecoveryModel' {
143+
$recoverymodel = $true
144+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'recoverymodeltype' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.recoverymodel.type').Value
145+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'recoverymodelexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.recoverymodel.excludedb').Value
146+
}
142147
Default { }
143148
}
144149

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

0 commit comments

Comments
 (0)