Skip to content

Commit

Permalink
Changes to SqlDatabase
Browse files Browse the repository at this point in the history
  - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
    to ServerName and InstanceName respectivly (issue dsccommunity#308).
  • Loading branch information
johlju committed Dec 1, 2017
1 parent 2f2f327 commit f97914b
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 136 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
- Updated Pester syntax to v4
- Fixes broken links to issues in the CHANGELOG.md.
- Changes to xSQLServerDatabase
- BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
to ServerName and InstanceName respectivly ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)).
- Added parameter to specify collation for a database to be different from server
collation ([issue #767](https://github.com/PowerShell/xSQLServer/issues/767)).
- Fixed unit tests for Get-TargetResource to ensure correctly testing return
Expand Down
46 changes: 23 additions & 23 deletions DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare
.PARAMETER Name
The name of database to be created or dropped.
.PARAMETER SQLServer
.PARAMETER ServerName
The host name of the SQL Server to be configured.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
The name of the SQL instance to be configured.
.PARAMETER Collation
Expand Down Expand Up @@ -43,20 +43,20 @@ function Get-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLServer,
$ServerName,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLInstanceName,
$InstanceName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$Collation
)

$sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

if ($sqlServerObject)
{
Expand All @@ -79,11 +79,11 @@ function Get-TargetResource
}

$returnValue = @{
Name = $Name
Ensure = $Ensure
SQLServer = $SQLServer
SQLInstanceName = $SQLInstanceName
Collation = $sqlDatabaseCollation
Name = $Name
Ensure = $Ensure
ServerName = $ServerName
InstanceName = $InstanceName
Collation = $sqlDatabaseCollation
}

$returnValue
Expand All @@ -100,10 +100,10 @@ function Get-TargetResource
.PARAMETER Name
The name of database to be created or dropped.
.PARAMETER SQLServer
.PARAMETER ServerName
The host name of the SQL Server to be configured.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
The name of the SQL instance to be configured.
.PARAMETER Collation
Expand All @@ -129,20 +129,20 @@ function Set-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLServer,
$ServerName,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLInstanceName,
$InstanceName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$Collation
)

$sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

if ($sqlServerObject)
{
Expand All @@ -156,7 +156,7 @@ function Set-TargetResource
elseif ($Collation -notin $sqlServerObject.EnumCollations().Name)
{
throw New-TerminatingError -ErrorType InvalidCollationError `
-FormatArgs @($SQLServer, $SQLInstanceName, $Name, $Collation) `
-FormatArgs @($ServerName, $InstanceName, $Name, $Collation) `
-ErrorCategory InvalidOperation
}

Expand All @@ -174,7 +174,7 @@ function Set-TargetResource
catch
{
throw New-TerminatingError -ErrorType UpdateDatabaseSetError `
-FormatArgs @($SQLServer, $SQLInstanceName, $Name) `
-FormatArgs @($ServerName, $InstanceName, $Name) `
-ErrorCategory InvalidOperation `
-InnerException $_.Exception
}
Expand All @@ -195,7 +195,7 @@ function Set-TargetResource
catch
{
throw New-TerminatingError -ErrorType CreateDatabaseSetError `
-FormatArgs @($SQLServer, $SQLInstanceName, $Name) `
-FormatArgs @($ServerName, $InstanceName, $Name) `
-ErrorCategory InvalidOperation `
-InnerException $_.Exception
}
Expand All @@ -216,7 +216,7 @@ function Set-TargetResource
catch
{
throw New-TerminatingError -ErrorType DropDatabaseSetError `
-FormatArgs @($SQLServer, $SQLInstanceName, $Name) `
-FormatArgs @($ServerName, $InstanceName, $Name) `
-ErrorCategory InvalidOperation `
-InnerException $_.Exception
}
Expand All @@ -235,10 +235,10 @@ function Set-TargetResource
.PARAMETER Name
The name of database to be created or dropped.
.PARAMETER SQLServer
.PARAMETER ServerName
The host name of the SQL Server to be configured.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
The name of the SQL instance to be configured.
.PARAMETER Collation
Expand All @@ -265,12 +265,12 @@ function Test-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLServer,
$ServerName,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLInstanceName,
$InstanceName,

[Parameter()]
[ValidateNotNullOrEmpty()]
Expand Down
4 changes: 2 additions & 2 deletions DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class MSFT_SqlDatabase : OMI_BaseResource
{
[Key, Description("The name of the SQL database.")] String Name;
[Write, Description("An enumerated value that describes if the database is added (Present) or dropped (Absent). Valid values are 'Present' or 'Absent'. Default Value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Key, Description("The host name of the SQL Server to be configured.")] String SQLServer;
[Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName;
[Key, Description("The host name of the SQL Server to be configured.")] String ServerName;
[Key, Description("The name of the SQL instance to be configured.")] String InstanceName;
[Write, Description("The name of the SQL collation to use for the new database. Defaults to server collation.")] String Collation;
};
18 changes: 9 additions & 9 deletions Examples/Resources/SqlDatabase/1-CreateDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ Configuration Example
{
SqlDatabase Create_Database
{
Ensure = 'Present'
SQLServer = 'SQLServer'
SQLInstanceName = 'DSC'
Name = 'Contoso'
Ensure = 'Present'
ServerName = 'SQLServer'
InstanceName = 'DSC'
Name = 'Contoso'
}

SqlDatabase Create_Database_with_different_collation
{
Ensure = 'Present'
SQLServer = 'SQLServer'
SQLInstanceName = 'DSC'
Name = 'AdventureWorks'
Collation = 'SQL_Latin1_General_Pref_CP850_CI_AS'
Ensure = 'Present'
ServerName = 'SQLServer'
InstanceName = 'DSC'
Name = 'AdventureWorks'
Collation = 'SQL_Latin1_General_Pref_CP850_CI_AS'
}
}
}
8 changes: 4 additions & 4 deletions Examples/Resources/SqlDatabase/2-DeleteDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Configuration Example
{
SqlDatabase Delete_Database
{
Ensure = 'Absent'
SQLServer = 'SQLServer'
SQLInstanceName = 'DSC'
Name = 'AdventureWorks'
Ensure = 'Absent'
ServerName = 'SQLServer'
InstanceName = 'DSC'
Name = 'AdventureWorks'
}
}
}
Loading

0 comments on commit f97914b

Please sign in to comment.