Skip to content

Commit

Permalink
BREAKING CHANGE: SqlScript, SqlScriptQuery - Add new key 'Id' to allo…
Browse files Browse the repository at this point in the history
…w reuse of a script with different variables (#2043)

- SqlScript
  - BREAKING CHANGE: The parameter `Id` is now required to allow
    reuse of a script with different variables. Set this to a unique value.
    The information entered is never used to actually run the script.
    (issue #596).
  - Fix unit test to fully check Set-TargetResource using timeout.
- SqlScriptQuery
  - BREAKING CHANGE: The parameter `Id` is now required to allow
    reuse of a script with different variables. Set this to a unique value.
    The information entered is never used to actually run the script.
    (issue #596).
  • Loading branch information
Borgquite authored Aug 13, 2024
1 parent 23d7684 commit 3c30929
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 62 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- SqlScript
- BREAKING CHANGE: The parameter `Id` is now required to allow
reuse of a script with different variables. Set this to a unique value.
The information entered is never used to actually run the script.
([issue #596](https://github.com/dsccommunity/SqlServerDsc/issues/596)).
- Fix unit test to fully check Set-TargetResource using timeout.
- SqlScriptQuery
- BREAKING CHANGE: The parameter `Id` is now required to allow
reuse of a script with different variables. Set this to a unique value.
The information entered is never used to actually run the script.
([issue #596](https://github.com/dsccommunity/SqlServerDsc/issues/596)).
- Fix unit test to fully check Set-TargetResource using timeout.

- SqlServerDsc
- Replaced inline task `Package_Wiki_Content` with the one now available
in the module _DscResource.DocGenerator_.
Expand Down
25 changes: 25 additions & 0 deletions source/DSCResources/DSC_SqlScript/DSC_SqlScript.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
.SYNOPSIS
Returns the current state of what the Get-script returns.
.PARAMETER Id
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
The information entered is never used during the actual process of running the scripts.
.PARAMETER InstanceName
Specifies the name of the SQL Server Database Engine instance. For the
default instance specify 'MSSQLSERVER'.
Expand Down Expand Up @@ -67,6 +71,10 @@ function Get-TargetResource
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Id,

[Parameter(Mandatory = $true)]
[System.String]
$InstanceName,
Expand Down Expand Up @@ -138,6 +146,7 @@ function Get-TargetResource
$getResult = Out-String -InputObject $result

$returnValue = @{
Id = [System.String] $Id
ServerName = [System.String] $ServerName
InstanceName = [System.String] $InstanceName
SetFilePath = [System.String] $SetFilePath
Expand All @@ -158,6 +167,10 @@ function Get-TargetResource
.SYNOPSIS
Executes the Set-script.
.PARAMETER Id
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
The information entered is never used during the actual process of running the scripts.
.PARAMETER InstanceName
Specifies the name of the SQL Server Database Engine instance. For the
default instance specify 'MSSQLSERVER'.
Expand Down Expand Up @@ -215,6 +228,10 @@ function Set-TargetResource
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Id,

[Parameter(Mandatory = $true)]
[System.String]
$InstanceName,
Expand Down Expand Up @@ -288,6 +305,10 @@ function Set-TargetResource
.SYNOPSIS
Evaluates the value returned from the Test-script.
.PARAMETER Id
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
The information entered is never used during the actual process of running the scripts.
.PARAMETER InstanceName
Specifies the name of the SQL Server Database Engine instance. For the
default instance specify 'MSSQLSERVER'.
Expand Down Expand Up @@ -346,6 +367,10 @@ function Test-TargetResource
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Id,

[Parameter(Mandatory = $true)]
[System.String]
$InstanceName,
Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/DSC_SqlScript/DSC_SqlScript.schema.mof
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ClassVersion("1.0.0.0"), FriendlyName("SqlScript")]
class DSC_SqlScript : OMI_BaseResource
{
[Key, Description("Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. The information entered is never used during the actual process of running the scripts.")] String Id;
[Key, Description("Specifies the name of the _SQL Server Database Engine_ instance. For the default instance specify the value `'MSSQLSERVER'`.")] String InstanceName;
[Key, Description("Path to the T-SQL file that will perform _Set_ action.")] String SetFilePath;
[Key, Description("Path to the T-SQL file that will perform _Get_ action. Any values returned by the T-SQL queries will also be returned when calling _Get_ (for example by using the cmdlet `Get-DscConfiguration`) through the `'GetResult'` property.")] String GetFilePath;
Expand Down
4 changes: 4 additions & 0 deletions source/DSCResources/DSC_SqlScript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Get T-SQL script, Set T-SQL script and the Test T-SQL script.
* Target machine must be running SQL Server 2012 or later.
* Target machine must have access to the SQLPS PowerShell module or the SqlServer
PowerShell module.
* Parameter `Id` is a unique identifier for this resource, allowing multiple
resources to be created, with only the Variable parameter changing.
Set this to any unique value - the information entered is never used during
the actual process of running the scripts.
* Parameter `Encrypt` controls whether the connection used by `Invoke-SqlCmd`
should enforce encryption. This parameter can only be used together with the
module _SqlServer_ v22.x (minimum v22.0.49-preview). The parameter will be
Expand Down
25 changes: 25 additions & 0 deletions source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
.SYNOPSIS
Returns the current state of what the Get-query returns.
.PARAMETER Id
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
The information entered is never used during the actual process of running the scripts.
.PARAMETER InstanceName
Specifies the name of the SQL Server Database Engine instance. For the
default instance specify 'MSSQLSERVER'.
Expand Down Expand Up @@ -67,6 +71,10 @@ function Get-TargetResource
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Id,

[Parameter(Mandatory = $true)]
[System.String]
$InstanceName,
Expand Down Expand Up @@ -138,6 +146,7 @@ function Get-TargetResource
$getResult = Out-String -InputObject $result

$returnValue = @{
Id = [System.String] $Id
ServerName = [System.String] $ServerName
InstanceName = [System.String] $InstanceName
GetQuery = [System.String] $GetQuery
Expand All @@ -158,6 +167,10 @@ function Get-TargetResource
.SYNOPSIS
Executes the Set-query.
.PARAMETER Id
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
The information entered is never used during the actual process of running the scripts.
.PARAMETER InstanceName
Specifies the name of the SQL Server Database Engine instance. For the
default instance specify 'MSSQLSERVER'.
Expand Down Expand Up @@ -215,6 +228,10 @@ function Set-TargetResource
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Id,

[Parameter(Mandatory = $true)]
[System.String]
$InstanceName,
Expand Down Expand Up @@ -288,6 +305,10 @@ function Set-TargetResource
.SYNOPSIS
Evaluates the value returned from the Test-query.
.PARAMETER Id
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
The information entered is never used during the actual process of running the scripts.
.PARAMETER InstanceName
Specifies the name of the SQL Server Database Engine instance. For the
default instance specify 'MSSQLSERVER'.
Expand Down Expand Up @@ -346,6 +367,10 @@ function Test-TargetResource
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Id,

[Parameter(Mandatory = $true)]
[System.String]
$InstanceName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ClassVersion("1.0.0.0"), FriendlyName("SqlScriptQuery")]
class DSC_SqlScriptQuery : OMI_BaseResource
{
[Key, Description("Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing. The information entered is never used during the actual process of running the scripts.")] String Id;
[Key, Description("Specifies the name of the _SQL Server Database Engine_ instance. For the default instance specify the value `'MSSQLSERVER'`.")] String InstanceName;
[Key, Description("Full T-SQL query that will perform _Get_ action. Any values returned by the T-SQL queries will also be returned when calling _Get_ (for example by using the cmdlet `Get-DscConfiguration`) through the `'GetResult'` property.")] String GetQuery;
[Key, Description("Full T-SQL query that will perform _Test_ action. Any script that does not throw an error or returns `NULL` is evaluated to `$true`. The cmdlet `Invoke-SqlCmd` treats T-SQL `PRINT` statements as verbose text, and will not cause the test to return `$false`.")] String TestQuery;
Expand Down
4 changes: 4 additions & 0 deletions source/DSCResources/DSC_SqlScriptQuery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ T-SQL script, Set T-SQL script and the Test T-SQL script.
* Target machine must be running SQL Server 2012 or later.
* Target machine must have access to the SQLPS PowerShell module or the SqlServer
PowerShell module.
* Parameter `Id` is a unique identifier for this resource, allowing multiple
resources to be created, with only the Variable parameter changing.
Set this to any unique value - the information entered is never used during
the actual process of running the scripts.
* Parameter `Encrypt` controls whether the connection used by `Invoke-SqlCmd`
should enforce encryption. This parameter can only be used together with the
module _SqlServer_ v22.x (minimum v22.0.49-preview). The parameter will be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Configuration Example
{
SqlScript 'RunAsSqlCredential'
{
Id = 'RunAsSqlCredential'
ServerName = 'localhost'
InstanceName = 'SQL2016'
Credential = $SqlCredential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Configuration Example
{
SqlScript 'RunAsSYSTEM'
{
Id = 'RunAsSYSTEM'
ServerName = 'localhost'
InstanceName = 'SQL2016'

Expand All @@ -31,6 +32,7 @@ Configuration Example

SqlScript 'RunAsUser'
{
Id = 'RunAsUser'
ServerName = 'localhost'
InstanceName = 'SQL2016'

Expand All @@ -44,6 +46,7 @@ Configuration Example

SqlScript 'RunAsUser-With30SecondTimeout'
{
Id = 'RunAsUser-With30SecondTimeout'
ServerName = 'localhost'
InstanceName = 'SQL2016'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Configuration Example

SqlScript 'Integration_Test'
{
Id = 'Integration_Test'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Configuration Example
{
SqlScript 'RunWithDisabledVariables'
{
Id = 'RunWithDisabledVariables'
ServerName = 'localhost'
InstanceName = 'SQL2016'
Credential = $SqlCredential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Configuration Example
{
SqlScriptQuery 'RunAsSqlCredential'
{
Id = 'RunAsSqlCredential'
ServerName = 'localhost'
InstanceName = 'SQL2016'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Configuration Example
{
SqlScriptQuery 'RunAsSYSTEM'
{
Id = 'RunAsSYSTEM'
ServerName = 'localhost'
InstanceName = 'SQL2016'

Expand All @@ -31,6 +32,7 @@ Configuration Example

SqlScriptQuery 'RunAsUser'
{
Id = 'RunAsUser'
ServerName = 'localhost'
InstanceName = 'SQL2016'

Expand All @@ -44,6 +46,7 @@ Configuration Example

SqlScriptQuery 'RunAsUser-With30SecondTimeout'
{
Id = 'RunAsUser-With30SecondTimeout'
ServerName = 'localhost'
InstanceName = 'SQL2016'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Configuration Example
{
SqlScriptQuery 'CreateDatabase_ScriptDatabase1'
{
Id = 'CreateDatabase_ScriptDatabase1'
ServerName = $env:COMPUTERNAME
InstanceName = 'DSCTEST'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Configuration Example
{
SqlScriptQuery 'RunWithDisabledVariables'
{
Id = 'RunWithDisabledVariables'
ServerName = 'localhost'
InstanceName = 'SQL2016'
Credential = $SqlCredential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Configuration DSC_SqlDatabaseObjectPermission_Prerequisites_Table1_Config
{
SqlScriptQuery 'CreateTable'
{
Id = 'CreateTable'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down Expand Up @@ -146,6 +147,7 @@ Configuration DSC_SqlDatabaseObjectPermission_Prerequisites_Procedure1_Config
{
SqlScriptQuery 'CreateProcedure1'
{
Id = 'CreateProcedure1'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down Expand Up @@ -182,6 +184,7 @@ Configuration DSC_SqlDatabaseObjectPermission_Prerequisites_Procedure2_Config
{
SqlScriptQuery 'CreateProcedure2'
{
Id = 'CreateProcedure2'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/Resources/DSC_SqlDatabaseUser.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ Configuration DSC_SqlDatabaseUser_AddDatabaseUser5_Config
{
SqlScriptQuery 'CreateDatabaseCertificate'
{
Id = 'CreateDatabaseCertificate'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down Expand Up @@ -294,6 +295,7 @@ Configuration DSC_SqlDatabaseUser_AddDatabaseUser6_Config
{
SqlScriptQuery 'CreateDatabaseAsymmetricKey'
{
Id = 'CreateDatabaseAsymmetricKey'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/Resources/DSC_SqlScript.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Configuration DSC_SqlScript_RunSqlScriptAsWindowsUser_Config
{
SqlScript 'Integration_Test'
{
Id = 'Integration_Test'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down Expand Up @@ -240,6 +241,7 @@ Configuration DSC_SqlScript_RunSqlScriptAsSqlUser_Config
{
SqlScript 'Integration_Test'
{
Id = 'Integration_Test'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down Expand Up @@ -275,6 +277,7 @@ Configuration DSC_SqlScript_RunSqlScriptWithVariablesDisabled_Config
{
SqlScript 'Integration_Test'
{
Id = 'Integration_Test'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/Resources/DSC_SqlScriptQuery.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Configuration DSC_SqlScriptQuery_RunSqlScriptQueryAsWindowsUser_Config
{
SqlScriptQuery 'Integration_Test'
{
Id = 'Integration_Test'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down Expand Up @@ -97,6 +98,7 @@ Configuration DSC_SqlScriptQuery_RunSqlScriptQueryAsSqlUser_Config
{
SqlScriptQuery 'Integration_Test'
{
Id = 'Integration_Test'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down Expand Up @@ -137,6 +139,7 @@ Configuration DSC_SqlScriptQuery_RunSqlScriptQueryWithVariablesDisabled_Config
{
SqlScriptQuery 'Integration_Test'
{
Id = 'Integration_Test'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName

Expand Down
Loading

0 comments on commit 3c30929

Please sign in to comment.