How can we help you today? How can we help you today?
PeterDaniels
Thank, Mac.  I'm using package deployment.  I'm using New-DatabaseReleaseArtifact + Export-DatabaseReleaseArtifact.  One of the outputs of Export-DatabaseReleaseArtifact is a "TargetedDeploymentScript.sql".  This script works for me, but I have to edit it to remove the code that requires a specific target server name. I'm asking if there is a setting in the project file that I can use to have it not include that check so I don't have to edit it each time? Example of the generated code I remove: -- As this script has been generated for a specific server instance/database combination, stop execution if there is a mismatch IF (@@SERVERNAME != 'ATL2100PC0GQ1DZ' OR '$(DatabaseName)' != 'TestSCA_DEV_INT') BEGIN RAISERROR(N'This script should only be executed on the following server/instance: [ATL2100PC0GQ1DZ] (Database: [TestSCA_DEV_INT]). Halting deployment.', 16, 127, N'UNKNOWN') WITH NOWAIT; RETURN; END GOMy PoSh function to remove it: function Remove-LinesFromFileAfterMatch { [cmdletbinding()] param ( [parameter(Mandatory=$true)] [string] $FilePath ,[parameter(Mandatory=$true)] [string] $StringToMatch ,[parameter(Mandatory=$false)] [int] $NumLinesToRemove = 1 ) begin { $TempFile = New-TemporaryFile $LineNum = 0 } process { switch -Wildcard -File $FilePath { $StringToMatch { # We don't want to output this line or the next $NumLinesToRemove $LineNum++ continue } {$LineNum -gt 0 -and $LineNum -le $NumLinesToRemove} { $LineNum++ continue } # Send rest of teh orig file to the new file default {$_ >> $TempFile} } } end { # and now swap the files (tmp -> orig) Copy-Item -Path $TempFile -Destination $FilePath -Force $FilePath } }And using it with the file: $FilePath = "C:\users\peter\tmp\TargetedDeploymentScript.sql" $Args = @{ FilePath = "$FilePath" StringToMatch = "-- As this script has been generated for a specific server instance/database combination, stop execution if there is a mismatch*" NumLinesToRemove = 8 } Remove-LinesFromFileAfterMatch @Args / comments
Thank, Mac.  I'm using package deployment.  I'm using New-DatabaseReleaseArtifact + Export-DatabaseReleaseArtifact.  One of the outputs of Export-DatabaseReleaseArtifact is a "TargetedDeploymentScr...
0 votes
I did, @Monday. Here's the function: $VersionInfo = Get-LatestVersionAndMigrationNumber -ProjectFilePath $ProjectFilePath $PackageVersion = $VersionInfo.Version + '-migration' + $VersionInfo.MigrationNumber $ReleaseVersion = $PackageVersion </code># Get latest version and migration from project file path # This is cool. Version like 1.1.0 and Migration number like 5 - to build ReleaseVersion and/or PackageVersion function Get-LatestVersionAndMigrationNumber { [CmdletBinding()] param ( [parameter(Mandatory=$true)] [string] $ProjectFilePath ) process { # First, strip the project file name and find the Migrations folder $ProjectRootFolder = Split-Path -Path $ProjectFilePath $MigrationsFolder = Join-Path -Path $ProjectRootFolder -ChildPath "Migrations" if (-not (Test-Path -Path $MigrationsFolder)) { Write-Error -Message "Invalid path: $MigrationsFolder" exit } # Get the latest migration folder sem ver [string]$Latest = Get-ChildItem -Path $MigrationsFolder -Directory | ForEach-Object {[Version]($_.Name -split "-")[0]} | Sort-Object -Descending | Select -First 1 # Get the base folder back now that I found the latest version: $LatestFolder = Get-ChildItem -Path $MigrationsFolder -Directory | Where-Object {$_.Name -like "$Latest*"} # Now get the migrations in that folder $LatestMigrationsFolder = Join-Path -Path $MigrationsFolder -ChildPath $LatestFolder $LatestMigration = (Get-ChildItem -Path $LatestMigrationsFolder -File).Name | Sort-Object -Descending | select -First 1 [int]$LatestMigrationSequenceNumber = ($LatestMigration -split "_")[0] # Return a custom object with the latest sem version and migration sequence num #$Latest + "-migration" + $LatestMigrationSequenceNumber $obj = New-Object -TypeName PSCustomObject -Property @{Version = $Latest;MigrationNumber = $LatestMigrationSequenceNumber} $obj } } </pre><div>I then use it:<br><pre class="CodeBlock"><code>To create a version that looks like (for example) 1.1.0-migration14 / comments
I did, @Monday. Here's the function:$VersionInfo = Get-LatestVersionAndMigrationNumber -ProjectFilePath $ProjectFilePath $PackageVersion = $VersionInfo.Version + '-migration' + $VersionInfo.Migrati...
0 votes
Thank you, @Mike U! I think this falls under the umbrella of needing to update the docs. I'd be willing to help you and the team with this process. Cheers. -Peter / comments
Thank you, @Mike U! I think this falls under the umbrella of needing to update the docs. I'd be willing to help you and the team with this process. Cheers.-Peter
0 votes