Skip to content

Instantly share code, notes, and snippets.

@Alex-Yates
Created July 22, 2016 10:06
Show Gist options
  • Save Alex-Yates/6f40897c97d6eb4c62e5c12b2e51e52c to your computer and use it in GitHub Desktop.
Save Alex-Yates/6f40897c97d6eb4c62e5c12b2e51e52c to your computer and use it in GitHub Desktop.
DLM Automation PS scripts: Deploy from database release
param
(
[Parameter(Mandatory=$true)]
[string]$PackageFilePathPattern = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseDeploymentResourcesPath = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseServer = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseName = $null,
[Parameter(Mandatory=$false)]
[string]$DatabaseUserName = $null,
[Parameter(Mandatory=$false)]
[string]$DatabasePassword = $null
)
$ErrorActionPreference = "Stop"
# Match the package file name. Only one file should match
$possiblePackageFiles = (Get-ChildItem $PackageFilePathPattern)
if ($possiblePackageFiles.Count -ne 1)
{
[string]$message = "Error: " + $possiblePackageFiles.Count.ToString() + " files match. Precisely 1 file should match pattern."
throw [System.Exception] $message
}
$PackageFilePath = $possiblePackageFiles.FullName
$PackageFileNameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($PackageFilePath)
# Combine deployment path with NuGet package name for unique directory
$DatabaseDeploymentResourcesPath = Join-Path $DatabaseDeploymentResourcesPath $PackageFileNameWithoutExtension
# Create connection string
$targetDb = New-DlmDatabaseConnection -ServerInstance $DatabaseServer -Database $DatabaseName -Username $DatabaseUserName -Password $DatabasePassword | Test-DlmDatabaseConnection
# Stop on any warnings
$highWarnings = $databaseUpdate.Warnings | Where { $_.Severity -eq "High" }
if($highWarnings.Count -gt 0)
{
[string]$highWarningsDetails = ""
$highWarnings | ForEach-Object { $highWarningsDetails = $highWarningsDetails + $_.Details + "`n" }
throw [System.Exception] $highWarningsDetails
}
# Update target from database release object
Import-DlmDatabaseRelease $DatabaseDeploymentResourcesPath | Use-DlmDatabaseRelease -DeployTo $targetDb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment