This topic provides an example of using PowerShell Cmdlets for the deployment of the NuGet package to the target database that includes the following stages:
#region the variables
# A target server name
$serverName = "DBMSSQLX64\MSSQL2016"
# A target sever user name
$userName = "sa"
# A target database name
$databaseName = "magma"
# A package file
$databasePackageFileName = "C:\Test\NuGet\Repository\Test.DevOpsAutomation.Database.3.0.0.nupkg"
#endregion
#region the check function
Function check {
param($result)
if ($result) {
Write-Host "Success" -ForegroundColor Green; Write-host ""
}
else {
Write-Host "Failed" -ForegroundColor Red;
Exit(1)
}
}
#endregion
#region synch from package to Database
# Create database connection
Write-Host "Creating database connection..."
$connection = New-DevartSqlDatabaseConnection -Server $serverName -Database $databaseName -UserName $userName
# Test database connection
Write-Host "Testing database connection..."
$result = Test-DevartDatabaseConnection -Connection $connection;
check($result)
# Sync database
Write-Host "Sync database..."
$result = Invoke-DevartSyncDatabaseSchema -Source $databasePackageFileName -Target $connection
check($result)
#endregion