Created
March 6, 2015 01:55
-
-
Save bradymholt/7985966e2448844f75d6 to your computer and use it in GitHub Desktop.
Package Manager Console helper module for DbUp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-Migration { | |
param ( | |
[string]$name | |
) | |
$project = Get-Project | |
$projectDirectory = Split-Path $project.FullName | |
$scriptDirectory = $projectDirectory + "\Migrate" | |
$fileNameBase = (Get-Date -UFormat "%y%m%d%H%M%S") | |
$gitBranch = Get-Branch | |
if ($gitBranch -ne ""){ | |
$fileNameBase = $fileNameBase + "_" + $gitBranch | |
} | |
If ($name -ne ""){ | |
$fileNameBase = $fileNameBase + "_" + $name | |
} | |
$fileNameBase = $fileNameBase.Replace(" ","") | |
$fileName = $fileNameBase + ".sql" | |
$filePath = $scriptDirectory + "\" + $fileName | |
$migrateProjectItem = $null | |
try | |
{ | |
$migrateProjectItem = $project.ProjectItems.Item("Migrate") | |
} | |
catch | |
{ | |
$project.ProjectItems.AddFolder("Migrate") | Out-Null | |
$migrateProjectItem = $project.ProjectItems.Item("Migrate") | |
} | |
New-Item -path $scriptDirectory -name $fileName -type "file" -value "/* script */" | Out-Null | |
$migrateProjectItem.ProjectItems.AddFromFile($filePath) | Out-Null | |
$item = $migrateProjectItem.ProjectItems.Item($fileName) | |
$item.Properties.Item("BuildAction").Value = [int]2 #Content | |
$item.Properties.Item("CopyToOutputDirectory").Value = [int]2 #Copy if newer | |
Write-Host "Created new migration: ${fileName}" | |
} | |
function Start-Migrations { | |
$project = Get-Project | |
Write-Host "Building..." | |
$dte.Solution.SolutionBuild.BuildProject("Debug", $project.FullName, $true) | |
$projectDirectory = Split-Path $project.FullName | |
$projectExe = $projectDirectory + "\bin\Debug\" + $project.Name + ".exe" | |
iex $projectExe | |
} | |
function Get-Branch { | |
$branch = "" | |
if(Test-Path .git) { | |
$prompt_string = "GIT" | |
git branch | foreach { | |
if ($_ -match "^\*(.*)"){ | |
$branch += $matches[1] | |
} | |
} | |
} | |
return $branch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment