mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-08 09:38:25 -05:00
Open dacfx deploy script instead of saving to file path (#822)
* open dacfx deploy script * moving test db cleanups into finally blocks
This commit is contained in:
@@ -13,11 +13,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
|
||||
/// </summary>
|
||||
public class GenerateDeployScriptParams : DacFxParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the filepath where to save the generated script
|
||||
/// </summary>
|
||||
public string ScriptFilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether a Deployment Report should be generated during deploy.
|
||||
/// </summary>
|
||||
|
||||
@@ -164,11 +164,12 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
{
|
||||
GenerateDeployScriptOperation operation = new GenerateDeployScriptOperation(parameters, connInfo);
|
||||
SqlTask sqlTask = null;
|
||||
TaskMetadata metadata = TaskMetadata.Create(parameters, SR.GenerateScriptTaskName, operation, ConnectionServiceInstance);
|
||||
|
||||
// want to show filepath in task history instead of server and database
|
||||
metadata.ServerName = parameters.ScriptFilePath;
|
||||
metadata.DatabaseName = string.Empty;
|
||||
TaskMetadata metadata = new TaskMetadata();
|
||||
metadata.TaskOperation = operation;
|
||||
metadata.TaskExecutionMode = parameters.TaskExecutionMode;
|
||||
metadata.ServerName = connInfo.ConnectionDetails.ServerName;
|
||||
metadata.DatabaseName = parameters.DatabaseName;
|
||||
metadata.Name = SR.GenerateScriptTaskName;
|
||||
|
||||
sqlTask = SqlTaskManagerInstance.CreateAndRun<SqlTask>(metadata);
|
||||
|
||||
@@ -275,9 +276,9 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
/// For testing purpose only
|
||||
/// </summary>
|
||||
/// <param name="operation"></param>
|
||||
internal void PerformOperation(DacFxOperation operation)
|
||||
internal void PerformOperation(DacFxOperation operation, TaskExecutionMode taskExecutionMode)
|
||||
{
|
||||
operation.Execute(TaskExecutionMode.Execute);
|
||||
operation.Execute(taskExecutionMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
{
|
||||
public GenerateDeployScriptParams Parameters { get; }
|
||||
|
||||
public PublishResult Result { get; set; }
|
||||
|
||||
public GenerateDeployScriptOperation(GenerateDeployScriptParams parameters, ConnectionInfo connInfo) : base(connInfo)
|
||||
{
|
||||
Validate.IsNotNull("parameters", parameters);
|
||||
@@ -34,15 +36,23 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
publishOptions.GenerateDeploymentReport = this.Parameters.GenerateDeploymentReport;
|
||||
publishOptions.CancelToken = this.CancellationToken;
|
||||
publishOptions.DeployOptions = this.GetDefaultDeployOptions();
|
||||
publishOptions.DatabaseScriptPath = this.Parameters.ScriptFilePath;
|
||||
// master script is only used if the target is Azure SQL db and the script contains all operations that must be done against the master database
|
||||
publishOptions.MasterDbScriptPath = Path.Combine(Path.GetDirectoryName(this.Parameters.ScriptFilePath), string.Concat("master_", Path.GetFileName(this.Parameters.ScriptFilePath)));
|
||||
|
||||
PublishResult result = this.DacServices.Script(dacpac, this.Parameters.DatabaseName, publishOptions);
|
||||
this.Result = this.DacServices.Script(dacpac, this.Parameters.DatabaseName, publishOptions);
|
||||
|
||||
if(this.Parameters.GenerateDeploymentReport && !string.IsNullOrEmpty(this.Parameters.DeploymentReportFilePath))
|
||||
// tests don't create a SqlTask, so only add the script when the SqlTask isn't null
|
||||
if (this.SqlTask != null)
|
||||
{
|
||||
File.WriteAllText(this.Parameters.DeploymentReportFilePath, result.DeploymentReport);
|
||||
this.SqlTask.AddScript(SqlTaskStatus.Succeeded, Result.DatabaseScript);
|
||||
if (!string.IsNullOrEmpty(this.Result.MasterDbScript))
|
||||
{
|
||||
// master script is only used if the target is Azure SQL db and the script contains all operations that must be done against the master database
|
||||
this.SqlTask.AddScript(SqlTaskStatus.Succeeded, this.Result.MasterDbScript);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.Parameters.GenerateDeploymentReport && !string.IsNullOrEmpty(this.Parameters.DeploymentReportFilePath))
|
||||
{
|
||||
File.WriteAllText(this.Parameters.DeploymentReportFilePath, this.Result.DeploymentReport);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
|
||||
public void Execute(TaskExecutionMode mode)
|
||||
{
|
||||
Execute();
|
||||
AddScriptToTask();
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
if (this.CancellationToken.IsCancellationRequested)
|
||||
{
|
||||
@@ -64,6 +58,17 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
try
|
||||
{
|
||||
this.ScriptGenerationResult = this.ComparisonResult.GenerateScript(this.Parameters.TargetDatabaseName);
|
||||
|
||||
// tests don't create a SqlTask, so only add the script when the SqlTask isn't null
|
||||
if (this.SqlTask != null)
|
||||
{
|
||||
this.SqlTask.AddScript(SqlTaskStatus.Succeeded, this.ScriptGenerationResult.Script);
|
||||
if (!string.IsNullOrEmpty(this.ScriptGenerationResult.MasterScript))
|
||||
{
|
||||
// master script is only used if the target is Azure SQL db and the script contains all operations that must be done against the master database
|
||||
this.SqlTask.AddScript(SqlTaskStatus.Succeeded, ScriptGenerationResult.MasterScript);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -73,17 +78,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
}
|
||||
|
||||
// Separated from Execute() since tests don't create SqlTasks
|
||||
public void AddScriptToTask()
|
||||
{
|
||||
this.SqlTask.AddScript(SqlTaskStatus.Succeeded, this.ScriptGenerationResult.Script);
|
||||
if (!string.IsNullOrEmpty(this.ScriptGenerationResult.MasterScript))
|
||||
{
|
||||
// master script is only used if the target is Azure SQL db and the script contains all operations that must be done against the master database
|
||||
this.SqlTask.AddScript(SqlTaskStatus.Succeeded, ScriptGenerationResult.MasterScript);
|
||||
}
|
||||
}
|
||||
|
||||
// The schema compare public api doesn't currently take a cancellation token so the operation can't be cancelled
|
||||
public void Cancel()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user