This topic provides an example of using PowerShell cmdlets for the deployment of the NuGet package to the target database that includes the following steps:
#region the variables
# A target server name
$serverName = "DBMSSQLX64\MSSQL2025"
# A target server username
$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 sync 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
Required variables
| Name | Description |
|---|---|
$serverName |
The name or network address of the SQL Server instance to connect to. |
$userName |
The username you use to connect to the target server. |
$databaseName |
The name of the target database you want to synchronize with the NuGet package. |
$databasePackageFileName |
The full path to the NuGet package file (.nupkg). |