Comments
7 comments
-
This is a good question and one I am hoping to understand as well. I could write a script but seems it would be cleaner to use a built in API if possible.
-
Hi @PeterDaniels,
I'm afraid we don't expose that at the moment. -
Bummer. I'd like to create coherent concept of "version" from SCA to Bamboo to Octo as well as in the __MigrationLog. Frankly, I want it to integrate with DLM Dashboard, too. But...I digress.
I think I'll have to add a custom build step to recurse through the migrations folder to look for the latest sem ver folder name.... -
PeterDaniels Did you ever write a script to recurse through the migrations folder to look for the latest version? If so would you mind sharing? If not I have a need as well and will be looking into this myself.
-
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
-
@PeterDaniels Pretty much what I did as well. I was going to read the .sqlproj file and get how it is configured instead of assuming how I think it is. Maybe I will do that later.
<DeployOnceSubFolder>Migrations</DeployOnceSubFolder>
<MigrationOrdering>FilePath</MigrationOrdering>
-
@Monday - I love how your'e thinking here. I was considering adding that functionality to make it more robust, but decided on a quick dev first.
Add comment
Please sign in to leave a comment.
I'm hoping to avoid writing a script to look for the latest migration folder in the project.
TIA,
- Peter