mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-04 01:25:43 -05:00
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:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user