Skip to content

Commit 3c30929

Browse files
authored
BREAKING CHANGE: SqlScript, SqlScriptQuery - Add new key 'Id' to allow 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).
1 parent 23d7684 commit 3c30929

21 files changed

+130
-62
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
### Changed
1616

17+
- SqlScript
18+
- BREAKING CHANGE: The parameter `Id` is now required to allow
19+
reuse of a script with different variables. Set this to a unique value.
20+
The information entered is never used to actually run the script.
21+
([issue #596](https://github.com/dsccommunity/SqlServerDsc/issues/596)).
22+
- Fix unit test to fully check Set-TargetResource using timeout.
23+
- SqlScriptQuery
24+
- BREAKING CHANGE: The parameter `Id` is now required to allow
25+
reuse of a script with different variables. Set this to a unique value.
26+
The information entered is never used to actually run the script.
27+
([issue #596](https://github.com/dsccommunity/SqlServerDsc/issues/596)).
28+
- Fix unit test to fully check Set-TargetResource using timeout.
29+
1730
- SqlServerDsc
1831
- Replaced inline task `Package_Wiki_Content` with the one now available
1932
in the module _DscResource.DocGenerator_.

source/DSCResources/DSC_SqlScript/DSC_SqlScript.psm1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
1010
.SYNOPSIS
1111
Returns the current state of what the Get-script returns.
1212
13+
.PARAMETER Id
14+
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
15+
The information entered is never used during the actual process of running the scripts.
16+
1317
.PARAMETER InstanceName
1418
Specifies the name of the SQL Server Database Engine instance. For the
1519
default instance specify 'MSSQLSERVER'.
@@ -67,6 +71,10 @@ function Get-TargetResource
6771
[OutputType([System.Collections.Hashtable])]
6872
param
6973
(
74+
[Parameter(Mandatory = $true)]
75+
[System.String]
76+
$Id,
77+
7078
[Parameter(Mandatory = $true)]
7179
[System.String]
7280
$InstanceName,
@@ -138,6 +146,7 @@ function Get-TargetResource
138146
$getResult = Out-String -InputObject $result
139147

140148
$returnValue = @{
149+
Id = [System.String] $Id
141150
ServerName = [System.String] $ServerName
142151
InstanceName = [System.String] $InstanceName
143152
SetFilePath = [System.String] $SetFilePath
@@ -158,6 +167,10 @@ function Get-TargetResource
158167
.SYNOPSIS
159168
Executes the Set-script.
160169
170+
.PARAMETER Id
171+
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
172+
The information entered is never used during the actual process of running the scripts.
173+
161174
.PARAMETER InstanceName
162175
Specifies the name of the SQL Server Database Engine instance. For the
163176
default instance specify 'MSSQLSERVER'.
@@ -215,6 +228,10 @@ function Set-TargetResource
215228
[CmdletBinding()]
216229
param
217230
(
231+
[Parameter(Mandatory = $true)]
232+
[System.String]
233+
$Id,
234+
218235
[Parameter(Mandatory = $true)]
219236
[System.String]
220237
$InstanceName,
@@ -288,6 +305,10 @@ function Set-TargetResource
288305
.SYNOPSIS
289306
Evaluates the value returned from the Test-script.
290307
308+
.PARAMETER Id
309+
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
310+
The information entered is never used during the actual process of running the scripts.
311+
291312
.PARAMETER InstanceName
292313
Specifies the name of the SQL Server Database Engine instance. For the
293314
default instance specify 'MSSQLSERVER'.
@@ -346,6 +367,10 @@ function Test-TargetResource
346367
[OutputType([System.Boolean])]
347368
param
348369
(
370+
[Parameter(Mandatory = $true)]
371+
[System.String]
372+
$Id,
373+
349374
[Parameter(Mandatory = $true)]
350375
[System.String]
351376
$InstanceName,

source/DSCResources/DSC_SqlScript/DSC_SqlScript.schema.mof

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[ClassVersion("1.0.0.0"), FriendlyName("SqlScript")]
22
class DSC_SqlScript : OMI_BaseResource
33
{
4+
[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;
45
[Key, Description("Specifies the name of the _SQL Server Database Engine_ instance. For the default instance specify the value `'MSSQLSERVER'`.")] String InstanceName;
56
[Key, Description("Path to the T-SQL file that will perform _Set_ action.")] String SetFilePath;
67
[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;

source/DSCResources/DSC_SqlScript/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Get T-SQL script, Set T-SQL script and the Test T-SQL script.
1010
* Target machine must be running SQL Server 2012 or later.
1111
* Target machine must have access to the SQLPS PowerShell module or the SqlServer
1212
PowerShell module.
13+
* Parameter `Id` is a unique identifier for this resource, allowing multiple
14+
resources to be created, with only the Variable parameter changing.
15+
Set this to any unique value - the information entered is never used during
16+
the actual process of running the scripts.
1317
* Parameter `Encrypt` controls whether the connection used by `Invoke-SqlCmd`
1418
should enforce encryption. This parameter can only be used together with the
1519
module _SqlServer_ v22.x (minimum v22.0.49-preview). The parameter will be

source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.psm1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
1010
.SYNOPSIS
1111
Returns the current state of what the Get-query returns.
1212
13+
.PARAMETER Id
14+
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
15+
The information entered is never used during the actual process of running the scripts.
16+
1317
.PARAMETER InstanceName
1418
Specifies the name of the SQL Server Database Engine instance. For the
1519
default instance specify 'MSSQLSERVER'.
@@ -67,6 +71,10 @@ function Get-TargetResource
6771
[OutputType([System.Collections.Hashtable])]
6872
param
6973
(
74+
[Parameter(Mandatory = $true)]
75+
[System.String]
76+
$Id,
77+
7078
[Parameter(Mandatory = $true)]
7179
[System.String]
7280
$InstanceName,
@@ -138,6 +146,7 @@ function Get-TargetResource
138146
$getResult = Out-String -InputObject $result
139147

140148
$returnValue = @{
149+
Id = [System.String] $Id
141150
ServerName = [System.String] $ServerName
142151
InstanceName = [System.String] $InstanceName
143152
GetQuery = [System.String] $GetQuery
@@ -158,6 +167,10 @@ function Get-TargetResource
158167
.SYNOPSIS
159168
Executes the Set-query.
160169
170+
.PARAMETER Id
171+
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
172+
The information entered is never used during the actual process of running the scripts.
173+
161174
.PARAMETER InstanceName
162175
Specifies the name of the SQL Server Database Engine instance. For the
163176
default instance specify 'MSSQLSERVER'.
@@ -215,6 +228,10 @@ function Set-TargetResource
215228
[CmdletBinding()]
216229
param
217230
(
231+
[Parameter(Mandatory = $true)]
232+
[System.String]
233+
$Id,
234+
218235
[Parameter(Mandatory = $true)]
219236
[System.String]
220237
$InstanceName,
@@ -288,6 +305,10 @@ function Set-TargetResource
288305
.SYNOPSIS
289306
Evaluates the value returned from the Test-query.
290307
308+
.PARAMETER Id
309+
Unique identifier for this resource. Set this to a unique value - allowing multiple resources with only the Variable parameter changing.
310+
The information entered is never used during the actual process of running the scripts.
311+
291312
.PARAMETER InstanceName
292313
Specifies the name of the SQL Server Database Engine instance. For the
293314
default instance specify 'MSSQLSERVER'.
@@ -346,6 +367,10 @@ function Test-TargetResource
346367
[OutputType([System.Boolean])]
347368
param
348369
(
370+
[Parameter(Mandatory = $true)]
371+
[System.String]
372+
$Id,
373+
349374
[Parameter(Mandatory = $true)]
350375
[System.String]
351376
$InstanceName,

source/DSCResources/DSC_SqlScriptQuery/DSC_SqlScriptQuery.schema.mof

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[ClassVersion("1.0.0.0"), FriendlyName("SqlScriptQuery")]
22
class DSC_SqlScriptQuery : OMI_BaseResource
33
{
4+
[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;
45
[Key, Description("Specifies the name of the _SQL Server Database Engine_ instance. For the default instance specify the value `'MSSQLSERVER'`.")] String InstanceName;
56
[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;
67
[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;

source/DSCResources/DSC_SqlScriptQuery/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ T-SQL script, Set T-SQL script and the Test T-SQL script.
1010
* Target machine must be running SQL Server 2012 or later.
1111
* Target machine must have access to the SQLPS PowerShell module or the SqlServer
1212
PowerShell module.
13+
* Parameter `Id` is a unique identifier for this resource, allowing multiple
14+
resources to be created, with only the Variable parameter changing.
15+
Set this to any unique value - the information entered is never used during
16+
the actual process of running the scripts.
1317
* Parameter `Encrypt` controls whether the connection used by `Invoke-SqlCmd`
1418
should enforce encryption. This parameter can only be used together with the
1519
module _SqlServer_ v22.x (minimum v22.0.49-preview). The parameter will be

source/Examples/Resources/SqlScript/1-RunScriptUsingSQLAuthentication.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Configuration Example
1818
{
1919
SqlScript 'RunAsSqlCredential'
2020
{
21+
Id = 'RunAsSqlCredential'
2122
ServerName = 'localhost'
2223
InstanceName = 'SQL2016'
2324
Credential = $SqlCredential

source/Examples/Resources/SqlScript/2-RunScriptUsingWindowsAuthentication.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Configuration Example
2020
{
2121
SqlScript 'RunAsSYSTEM'
2222
{
23+
Id = 'RunAsSYSTEM'
2324
ServerName = 'localhost'
2425
InstanceName = 'SQL2016'
2526

@@ -31,6 +32,7 @@ Configuration Example
3132

3233
SqlScript 'RunAsUser'
3334
{
35+
Id = 'RunAsUser'
3436
ServerName = 'localhost'
3537
InstanceName = 'SQL2016'
3638

@@ -44,6 +46,7 @@ Configuration Example
4446

4547
SqlScript 'RunAsUser-With30SecondTimeout'
4648
{
49+
Id = 'RunAsUser-With30SecondTimeout'
4750
ServerName = 'localhost'
4851
InstanceName = 'SQL2016'
4952

source/Examples/Resources/SqlScript/3-RunScriptCompleteExample.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Configuration Example
144144

145145
SqlScript 'Integration_Test'
146146
{
147+
Id = 'Integration_Test'
147148
ServerName = $Node.ServerName
148149
InstanceName = $Node.InstanceName
149150

0 commit comments

Comments
 (0)