Adding SqlCmdVars support for DacFx Deploy (#971)

* Adding SqlCmdVars support for DacFx Deploy

* Adding SqlCmdVars support for GenerateDeployScript

* Consolidating test logic
This commit is contained in:
Benjin Dubishar
2020-06-10 16:00:59 -07:00
committed by GitHub
parent e8e699dbd8
commit c51a59dadf
6 changed files with 181 additions and 45 deletions

View File

@@ -2,9 +2,8 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
{
@@ -17,6 +16,11 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
/// Gets or sets if upgrading existing database
/// </summary>
public bool UpgradeExisting { get; set; }
/// <summary>
/// Gets or sets SQLCMD variables for deployment
/// </summary>
public IDictionary<string, string> SqlCommandVariableValues { get; set; }
}
/// <summary>

View File

@@ -2,9 +2,8 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
{
@@ -22,6 +21,11 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
/// Gets or sets the filepath where to save the deployment report
/// </summary>
public string DeploymentReportFilePath { get; set; }
/// <summary>
/// Gets or sets SQLCMD variables for script generation
/// </summary>
public IDictionary<string, string> SqlCommandVariableValues { get; set; }
}
/// <summary>

View File

@@ -5,11 +5,7 @@
using Microsoft.SqlServer.Dac;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.Utility;
using System;
using Microsoft.Data.SqlClient;
using System.Diagnostics;
namespace Microsoft.SqlTools.ServiceLayer.DacFx
{
@@ -30,6 +26,15 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
{
DacPackage dacpac = DacPackage.Load(this.Parameters.PackageFilePath);
DacDeployOptions options = this.GetDefaultDeployOptions();
if (this.Parameters.SqlCommandVariableValues != null)
{
foreach (string key in this.Parameters.SqlCommandVariableValues.Keys)
{
options.SqlCommandVariableValues[key] = this.Parameters.SqlCommandVariableValues[key];
}
}
this.DacServices.Deploy(dacpac, this.Parameters.DatabaseName, this.Parameters.UpgradeExisting, options, this.CancellationToken);
}
}

View File

@@ -37,6 +37,14 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
publishOptions.CancelToken = this.CancellationToken;
publishOptions.DeployOptions = this.GetDefaultDeployOptions();
if (this.Parameters.SqlCommandVariableValues != null)
{
foreach (string key in this.Parameters.SqlCommandVariableValues.Keys)
{
publishOptions.DeployOptions.SqlCommandVariableValues[key] = this.Parameters.SqlCommandVariableValues[key];
}
}
this.Result = this.DacServices.Script(dacpac, this.Parameters.DatabaseName, publishOptions);
// tests don't create a SqlTask, so only add the script when the SqlTask isn't null