Deploy a NuGet package to the target database

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:

  • Creation of a target database connection.
  • Testing of the target database connection.
  • Synchronization.
#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

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge DevOps Automation for SQL Server.
Request a demo

Request a demo

If you consider employing the DevOps Automation for your business, request a demo to see it in action.
Ready to start using dbForge DevOps Automation for SQL Server?