Added IsCdCEnabled to Get-DbaDatabase
No attempt made to touch the Azure stuff.
Type of Change
- [ ] Bug fix (non-breaking change, fixes # )
- [X] New feature (non-breaking change, adds functionality, fixes #9669 )
- [ ] Breaking change (affects multiple commands or functionality, fixes # )
- [ ] Ran manual Pester test and has passed (
Invoke-ManualPester) - [ ] Adding code coverage to existing functionality
- [ ] Pester test is included
- [ ] If new file reference added for test, has is been added to github.com/dataplat/appveyor-lab ?
- [ ] Unit test is included
- [ ] Documentation
- [ ] Build system
Purpose
See #9669.
Approach
I did the first thing that came to mind and it immediately worked. I expected this to be much harder!
Commands to test
Get-DbaDatabase
Screenshots
ok, now the code is right but .... are we sure the column is there for every version ? Feature-wise, I think CDC is from 2008 onwards, and restricted to enterprise only till 2016sp1.
I thought the automated testing hit some really old versions?
My old copy of SQL Server MVP Deep Dives Volume 1 agrees that it was new in 2008.
We already have an if branch for major version 8. I doubt that any of this at all works for version before 8. And to my knowledge, 2008 is version 10. So I guess that I just need to write another branch for version 9 and then I'm done? Do you agree?
Why don't we use the property? https://learn.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.management.smo.database.changetrackingenabled?view=sql-smo-172#microsoft-sqlserver-management-smo-database-changetrackingenabled
@andreasjordan Aren't Change Tracking and CDC two different things?
@ReeceGoding yes, you are right. I was on the wrong track...
Maybe we should wrap $server.Query("SELECT name, state, SUSER_SNAME(owner_sid) AS [Owner], is_cdc_enabled FROM sys.databases") with a try catch and use the old query in the catch block.
@niphlod @andreasjordan Better?
The code looks save now, thanks fo rthe change.
But we need to talk about the values. Should the property IsCdcEnabled be of type boolean? I can not test this at the moment, but your screenshot looks like it works on current versions, so the "bit" column type is converted to a boolean. But what about the old versions. The "0" in your query is likely just a number. Or should the query return $null as the feature is not availabe?
Should the property IsCdcEnabled be of type boolean? I can not test this at the moment, but your screenshot looks like it works on current versions, so the "bit" column type is converted to a boolean. But what about the old versions. The "0" in your query is likely just a number. Or should the query return $null as the feature is not availabe?
I'm afraid that I don't know and also lack any way to find out. Suggestions?
So $server.Query("SELECT name, state, SUSER_SNAME(owner_sid) AS [Owner], 0 AS is_cdc_enabled FROM sys.databases") returns a number, not a boolean. As the feature is not present in that version, I vote for returning $null. We can do that by just remove , 0 AS is_cdc_enabled from that line.
I think that is the last change request before I approve the PR....
@andreasjordan Done?
oh wow, didnt realize this one was done! awesome. thanks everyone 🥳