How to use -Target <list> in New-DatabaseReleaseArtifact?

The docs for New-DatabaseReleaseArtifact discuss using a list of one or more items as an argument to the -Target parameter. When I tried to do that, I got: "to create a release for a SQL change automation project, the Target must be a single database".  Can anyone tell me how the list of targets may be utilized?
Tagged:

Best Answer

  • Eddie DEddie D Posts: 1,780 Rose Gold 5
    Hi Peter, thank you for your reply.

    I think there is a mi-understanding, regarding this line in the help documentation:

    If you use a list, the cmdlet will check that everything in the list has the same database schema. If there are no differences in schema, the cmdlet will create the Database Release. If there are any differences in schema, the cmdlet will fail and inform you.

    You can only specify one target schema.  However, you can use a list containing one or more methods (listed below) to specify the one schema:

     a Database Connection object created by the New-DatabaseConnection cmdlet
    - a database connection string
    - a path for a NuGet package or .zip file. This must contain a scripts folder located at db\state
    - a Database Build Artifact object produced by the New-DatabaseBuildArtifact cmdlet
    - a path for a scripts folder, created by SQL Compare or from your SQL Source Control database repository
    - a list containing one or more of the above

    There is not a method available to specify multiple schemas.

    Many Thanks
    Eddie
    Eddie Davis
    Senior Product Support Engineer
    Redgate Software Ltd
    Email: support@red-gate.com

Answers

  • Russell DRussell D Posts: 1,324 Diamond 5
    edited December 17, 2018 1:55PM
    Hi Peter, this could be a problem with the syntax - can you share the command you're trying?
    Have you visited our Help Centre?
  • $ErrorActionPreference = "stop"

    #Input the build artifact nupkg file path
    $pathToBuildArtifact = "C:\Export\DatabaseBuild\SCAPOC.1.0.0.nupkg"

    #Input the path to export the release artifact to
    $exportPath = "C:\Export\DatabaseRelease\tmp"

    #try multiple targets
    $t1 = New-DatabaseConnection -ServerInstance "localhost" -Database "SCAPOC_UAT"
    $t2 = New-DatabaseConnection -ServerInstance "localhost" -Database "SCAPOC_PROD"

    #ERROR: To create a release for a SQL Change Automation project, the Target parameter must be a single Database 
    #Connection.

    #Create and export a release artifact - based on 2 targets
    $releaseArtifact = New-DatabaseReleaseArtifact -Source $pathToBuildArtifact -Target @($t1, $t2)

  • # And here is the code that exported the build artifact
    $ErrorActionPreference = "stop"

    # Input path to SCA project file
    $pathToProjectFile = "C:\Users\peter\Documents\IncommSVN_PPD\SCAPOC\SCAPOC\SCAPOC\SCAPOC.sqlproj"

    #validate the project by building
    $validatedProject = $pathToProjectFile | Invoke-DatabaseBuild

    #create athe build artifcat and export it to file
    $buildArtifact = $validatedProject | New-DatabaseBuildArtifact -PackageId "SCAPOC" -PackageVersion 1.0.0
    $buildArtifact | Export-DatabaseBuildArtifact -Path "C:\Export\DatabaseBuild\" -Force

  • Russell D said:
    Hi Peter, this could be a problem with the syntax - can you share the command you're trying?
    Russel - I put this code in the thread.  Hoping you can shed some light on correct usage.
  • PeterDanielsPeterDaniels Posts: 89 Bronze 3
    edited December 26, 2018 5:39PM
    <Deleted - mistaken post>
Sign In or Register to comment.