Open schema compare generated script (#813)

This commit is contained in:
kisantia
2019-05-20 14:14:50 -07:00
committed by GitHub
parent 151a2de625
commit e68b6d62aa
5 changed files with 39 additions and 44 deletions

View File

@@ -38,16 +38,23 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
public SchemaComparisonResult ComparisonResult { get; set; }
public SchemaCompareScriptGenerationResult ScriptGenerationResult { get; set; }
public SchemaCompareGenerateScriptOperation(SchemaCompareGenerateScriptParams parameters, SchemaComparisonResult comparisonResult)
{
Validate.IsNotNull("parameters", parameters);
Validate.IsNotNull("scriptFilePath", parameters.ScriptFilePath);
this.Parameters = parameters;
Validate.IsNotNull("comparisonResult", comparisonResult);
this.ComparisonResult = comparisonResult;
}
public void Execute(TaskExecutionMode mode)
{
Execute();
AddScriptToTask();
}
public void Execute()
{
if (this.CancellationToken.IsCancellationRequested)
{
@@ -56,15 +63,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
try
{
SchemaCompareScriptGenerationResult result = this.ComparisonResult.GenerateScript(this.Parameters.TargetDatabaseName);
File.WriteAllText(this.Parameters.ScriptFilePath, result.Script);
if (!string.IsNullOrEmpty(result.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
string masterScriptPath = Path.Combine(Path.GetDirectoryName(this.Parameters.ScriptFilePath), string.Concat("master_", Path.GetFileName(this.Parameters.ScriptFilePath)));
File.WriteAllText(masterScriptPath, result.MasterScript);
}
this.ScriptGenerationResult = this.ComparisonResult.GenerateScript(this.Parameters.TargetDatabaseName);
}
catch (Exception e)
{
@@ -74,6 +73,17 @@ 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()
{