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

BREAKING CHANGE: SqlDatabaseOwner: Support multi-instances #1204

Merged
merged 4 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- Corrected reference to "PsDscRunAsAccount" in documentation
([issue #1199](https://github.com/PowerShell/SqlServerDsc/issues/1199)).
[Nick Reilingh (@NReilingh)](https://github.com/NReilingh)
- Changes to SqlDatabaseOwner
- BREAKING CHANGE: Support multiple instances on the same node.
The parameter InstanceName is now Key and cannot be omitted.
([issue #1197](https://github.com/PowerShell/SqlServerDsc/issues/1197)).

## 11.4.0.0

Expand Down
12 changes: 6 additions & 6 deletions DSCResources/MSFT_SqlDatabaseOwner/MSFT_SqlDatabaseOwner.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ function Get-TargetResource
[System.String]
$ServerName = $env:COMPUTERNAME,

[Parameter()]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$InstanceName = 'MSSQLSERVER'
$InstanceName
)

Write-Verbose -Message "Getting owner of database $Database"
Expand Down Expand Up @@ -116,10 +116,10 @@ function Set-TargetResource
[System.String]
$ServerName = $env:COMPUTERNAME,

[Parameter()]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$InstanceName = 'MSSQLSERVER'
$InstanceName
)

Write-Verbose -Message "Setting owner $Name of database $Database"
Expand Down Expand Up @@ -191,10 +191,10 @@ function Test-TargetResource
[System.String]
$ServerName = $env:COMPUTERNAME,

[Parameter()]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$InstanceName = 'MSSQLSERVER'
$InstanceName
)

Write-Verbose -Message "Testing owner $Name of database $Database"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class MSFT_SqlDatabaseOwner : OMI_BaseResource
[Key, Description("The name of database to be configured.")] String Database;
[Required, Description("The name of the login that will become a owner of the desired sql database.")] String Name;
[Write, Description("The host name of the SQL Server to be configured.")] String ServerName;
[Write, Description("The name of the SQL instance to be configured.")] String InstanceName;
[Key, Description("The name of the SQL instance to be configured.")] String InstanceName;
};
23 changes: 21 additions & 2 deletions Examples/Resources/SqlDatabaseOwner/1-SetDatabaseOwner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Configuration Example

node localhost
{
SqlServerLogin Add_SqlServerLogin_SQLAdmin
SqlServerLogin Add_SqlServerLogin_SQLAdmin_DSC
{
Ensure = 'Present'
Name = 'CONTOSO\SQLAdmin'
Expand All @@ -26,13 +26,32 @@ Configuration Example
PsDscRunAsCredential = $SqlAdministratorCredential
}

SqlDatabaseOwner Set_SqlDatabaseOwner_SQLAdmin
SqlServerLogin Add_SqlServerLogin_SQLAdmin_DSC2
{
Ensure = 'Present'
Name = 'CONTOSO\SQLAdmin'
LoginType = 'WindowsUser'
ServerName = 'sqltest.company.local'
InstanceName = 'DSC2'
PsDscRunAsCredential = $SqlAdministratorCredential
}

SqlDatabaseOwner Set_SqlDatabaseOwner_SQLAdmin_DSC
{
Name = 'CONTOSO\SQLAdmin'
Database = 'AdventureWorks'
ServerName = 'sqltest.company.local'
InstanceName = 'DSC'
PsDscRunAsCredential = $SqlAdministratorCredential
}

SqlDatabaseOwner Set_SqlDatabaseOwner_SQLAdmin_DSC2
{
Name = 'CONTOSO\SQLAdmin'
Database = 'AdventureWorks'
ServerName = 'sqltest.company.local'
InstanceName = 'DSC2'
PsDscRunAsCredential = $SqlAdministratorCredential
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ For more information about database owner, please read the article
* **`[String]` Name** _(Required)_: The name of the login that will become a owner
of the desired sql database.
* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured.
* **`[String]` InstanceName** _(Write)_: The name of the SQL instance to be configured.
* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured.

#### Examples

Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ try

Context 'When the system is either in the desired state or not in the desired state' {
It 'Should not throw' {
$testParameters = $defaultParameters
$testParameters = $mockDefaultParameters
$testParameters += @{
Database = $mockSqlDatabaseName
Name = $mockSqlServerLogin
Expand Down Expand Up @@ -151,7 +151,7 @@ try

Context 'When the system is not in the desired state' {
It 'Should return the state as false when desired login is not the database owner' {
$testParameters = $defaultParameters
$testParameters = $mockDefaultParameters
$testParameters += @{
Database = $mockSqlDatabaseName
Name = $mockSqlServerLogin
Expand All @@ -170,7 +170,7 @@ try
It 'Should return the state as true when desired login is the database owner' {
$mockDatabaseOwner = 'Zebes\SamusAran'
$mockSqlServerLogin = 'Zebes\SamusAran'
$testParameters = $defaultParameters
$testParameters = $mockDefaultParameters
$testParameters += @{
Database = $mockSqlDatabaseName
Name = $mockSqlServerLogin
Expand Down