functions/Update-DBOPackage.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function Update-DBOPackage {
    <#
    .SYNOPSIS
    Updates DBOps package parameters
 
    .DESCRIPTION
    Overwrites package file inside the existing DBOps package with the new values provided by user
 
    .PARAMETER Path
    Path to the existing DBOpsPackage.
    Aliases: Name, FileName, Package
 
    .PARAMETER Slim
        Do not include accompanying modules into the package file.
 
    .PARAMETER PreScriptPath
        Path to the script(s) to be executed against the database before running the deployment. Pre-scripts are not journaled to the Schema Version table.
 
    .PARAMETER PostScriptPath
        Path to the Script(s) to be executed against the database after the deployment. Post-scripts are not journaled to the Schema Version table.
 
    .PARAMETER Confirm
        Prompts to confirm certain actions
 
    .PARAMETER WhatIf
        Shows what would happen if the command would execute, but does not actually perform the command
 
    .EXAMPLE
    # Reconfigure package to become module-less
    Update-DBOPackage Package.zip -Slim $true
 
    .EXAMPLE
    # Reconfigure Pre- and Post scripts
    Get-DBOPackage Package.zip | Update-DBOPackage -PreScriptPath .\prescripts -PostScriptPath (Get-ChildItem .\postscripts)
 
    #>

    [CmdletBinding(DefaultParameterSetName = 'Value',
        SupportsShouldProcess)]
    Param (
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            Position = 1)]
        [Alias('FileName', 'Name', 'Package')]
        [string[]]$Path,
        [ValidateNotNullOrEmpty()]
        [bool]$Slim,
        [object[]]$PreScriptPath,
        [object[]]$PostScriptPath
        # [ValidateNotNullOrEmpty()]
        # [string]$Version
    )
    begin {

    }
    process {
        foreach ($p in $Path) {
            $package = Get-DBOPackage -Path $p
            if ($pscmdlet.ShouldProcess($package, "Updating the package file/object")) {
                if (Test-PSFParameterBinding -ParameterName Slim) {
                    Write-PSFMessage -Level Verbose -Message "Setting Slim to $Slim"
                    $package.Slim = $Slim
                }
                if (Test-PSFParameterBinding -ParameterName PreScriptPath) {
                    $preScriptCollection = Get-DbopsFile $PreScriptPath
                    Write-PSFMessage -Level Verbose -Message "Adding $($preScriptCollection.Count) pre-script(s) from $PreScriptPath"
                    $package.SetPreScripts($preScriptCollection)
                }
                if (Test-PSFParameterBinding -ParameterName PostScriptPath) {
                    $postScriptCollection = Get-DbopsFile $PostScriptPath
                    Write-PSFMessage -Level Verbose -Message "Adding $($postScriptCollection.Count) post-script(s) from $PostScriptPath"
                    $package.SetPostScripts($postScriptCollection)
                }
                # if (Test-PSFParameterBinding -ParameterName Version) {
                # Write-PSFMessage -Level Verbose -Message "Setting Version to $Version"
                # $package.Version = $Version
                # }
                $package.Alter()
            }
        }
    }
    end {

    }
}