mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
enable table designer for sqlproj (#1511)
* enable table designer for sqlproj * return issues and new table info on initialization * vbump dacfx * Revert "vbump dacfx" This reverts commit f59768b41f67866bd7620e06b141e8bfdb1523aa.
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
<PackageReference Update="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="1.1.1" />
|
<PackageReference Update="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="1.1.1" />
|
||||||
<PackageReference Update="Microsoft.Data.SqlClient" Version="3.1.0"/>
|
<PackageReference Update="Microsoft.Data.SqlClient" Version="3.1.0"/>
|
||||||
<PackageReference Update="Microsoft.SqlServer.SqlManagementObjects" Version="161.46367.54" />
|
<PackageReference Update="Microsoft.SqlServer.SqlManagementObjects" Version="161.46367.54" />
|
||||||
<PackageReference Update="Microsoft.SqlServer.DACFx" Version="160.6164.0-preview" GeneratePathProperty="true" />
|
<PackageReference Update="Microsoft.SqlServer.DACFx" Version="160.6174.0-preview" GeneratePathProperty="true" />
|
||||||
<PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" />
|
<PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" />
|
||||||
<PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4"/>
|
<PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4"/>
|
||||||
<PackageReference Update="Microsoft.SqlServer.Assessment" Version="[1.0.305]" />
|
<PackageReference Update="Microsoft.SqlServer.Assessment" Version="[1.0.305]" />
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
// Copyright (c) Microsoft. All rights reserved.
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||||
{
|
{
|
||||||
@@ -15,8 +14,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
|||||||
|
|
||||||
public TableViewModel ViewModel { get; set; }
|
public TableViewModel ViewModel { get; set; }
|
||||||
|
|
||||||
public List<string> ColumnTypes { get; set; }
|
public TableInfo TableInfo { get; set; }
|
||||||
|
|
||||||
public List<string> Schemas { get; set; }
|
public TableDesignerIssue[] Issues { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
|||||||
public List<DesignerDataPropertyInfo> AdditionalPrimaryKeyProperties { get; set; } = new List<DesignerDataPropertyInfo>();
|
public List<DesignerDataPropertyInfo> AdditionalPrimaryKeyProperties { get; set; } = new List<DesignerDataPropertyInfo>();
|
||||||
public BuiltinTableOptions PrimaryKeyColumnSpecificationTableOptions = new BuiltinTableOptions();
|
public BuiltinTableOptions PrimaryKeyColumnSpecificationTableOptions = new BuiltinTableOptions();
|
||||||
public List<DesignerTabView> AdditionalTabs { get; } = new List<DesignerTabView>();
|
public List<DesignerTabView> AdditionalTabs { get; } = new List<DesignerTabView>();
|
||||||
|
public bool UseAdvancedSaveMode { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BuiltinTableOptions
|
public class BuiltinTableOptions
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -10,6 +12,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TableInfo
|
public class TableInfo
|
||||||
{
|
{
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
public string Tooltip { get; set; }
|
||||||
|
|
||||||
public string Server { get; set; }
|
public string Server { get; set; }
|
||||||
|
|
||||||
public string Database { get; set; }
|
public string Database { get; set; }
|
||||||
@@ -25,5 +31,13 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
|||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
public string AccessToken { get; set; }
|
public string AccessToken { get; set; }
|
||||||
|
|
||||||
|
public string TableScriptPath { get; set; }
|
||||||
|
|
||||||
|
public string ProjectFilePath { get; set; }
|
||||||
|
|
||||||
|
public List<string> AllScripts { get; set; }
|
||||||
|
|
||||||
|
public string TargetVersion { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,10 +85,14 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
var tableDesigner = this.CreateTableDesigner(tableInfo);
|
var tableDesigner = this.CreateTableDesigner(tableInfo);
|
||||||
var viewModel = this.GetTableViewModel(tableInfo);
|
var viewModel = this.GetTableViewModel(tableInfo);
|
||||||
var view = this.GetDesignerViewInfo(tableInfo);
|
var view = this.GetDesignerViewInfo(tableInfo);
|
||||||
|
this.UpdateTableTitleInfo(tableInfo);
|
||||||
|
var issues = TableDesignerValidator.Validate(tableDesigner);
|
||||||
await requestContext.SendResult(new TableDesignerInfo()
|
await requestContext.SendResult(new TableDesignerInfo()
|
||||||
{
|
{
|
||||||
ViewModel = viewModel,
|
ViewModel = viewModel,
|
||||||
View = view
|
View = view,
|
||||||
|
TableInfo = tableInfo,
|
||||||
|
Issues = issues.ToArray()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -144,9 +148,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
{
|
{
|
||||||
var tableDesigner = this.GetTableDesigner(tableInfo);
|
var tableDesigner = this.GetTableDesigner(tableInfo);
|
||||||
tableDesigner.CommitChanges();
|
tableDesigner.CommitChanges();
|
||||||
string newId = string.Format("{0}|{1}|{2}|{3}|{4}", STSHost.ProviderName, tableInfo.Server, tableInfo.Database, tableDesigner.TableViewModel.Schema, tableDesigner.TableViewModel.Name);
|
|
||||||
string oldId = tableInfo.Id;
|
string oldId = tableInfo.Id;
|
||||||
this.idTableMap.Remove(oldId);
|
if (tableInfo.ProjectFilePath == null)
|
||||||
|
{
|
||||||
|
string newId = string.Format("{0}|{1}|{2}|{3}|{4}", STSHost.ProviderName, tableInfo.Server, tableInfo.Database, tableDesigner.TableViewModel.Schema, tableDesigner.TableViewModel.Name);
|
||||||
if (newId != oldId)
|
if (newId != oldId)
|
||||||
{
|
{
|
||||||
tableInfo.Name = tableDesigner.TableViewModel.Name;
|
tableInfo.Name = tableDesigner.TableViewModel.Name;
|
||||||
@@ -154,9 +159,12 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
tableInfo.IsNewTable = false;
|
tableInfo.IsNewTable = false;
|
||||||
tableInfo.Id = newId;
|
tableInfo.Id = newId;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
this.idTableMap.Remove(oldId);
|
||||||
// Recreate the table designer after the changes are published to make sure the table information is up to date.
|
// Recreate the table designer after the changes are published to make sure the table information is up to date.
|
||||||
// Todo: improve the dacfx table designer feature, so that we don't have to recreate it.
|
// Todo: improve the dacfx table designer feature, so that we don't have to recreate it.
|
||||||
this.CreateTableDesigner(tableInfo);
|
this.CreateTableDesigner(tableInfo);
|
||||||
|
this.UpdateTableTitleInfo(tableInfo);
|
||||||
await requestContext.SendResult(new PublishTableChangesResponse()
|
await requestContext.SendResult(new PublishTableChangesResponse()
|
||||||
{
|
{
|
||||||
NewTableInfo = tableInfo,
|
NewTableInfo = tableInfo,
|
||||||
@@ -948,6 +956,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
this.SetEdgeConstraintsViewInfo(view, tableDesigner);
|
this.SetEdgeConstraintsViewInfo(view, tableDesigner);
|
||||||
this.SetTemporalTableViewInfo(view, tableDesigner);
|
this.SetTemporalTableViewInfo(view, tableDesigner);
|
||||||
this.SetMemoryOptimizedTableViewInfo(view, tableDesigner);
|
this.SetMemoryOptimizedTableViewInfo(view, tableDesigner);
|
||||||
|
view.UseAdvancedSaveMode = tableInfo.ProjectFilePath == null;
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1450,11 +1459,19 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Dac.TableDesigner CreateTableDesigner(TableInfo tableInfo)
|
private Dac.TableDesigner CreateTableDesigner(TableInfo tableInfo)
|
||||||
|
{
|
||||||
|
Dac.TableDesigner tableDesigner;
|
||||||
|
if (tableInfo.TableScriptPath == null)
|
||||||
{
|
{
|
||||||
var connectionStringbuilder = new SqlConnectionStringBuilder(tableInfo.ConnectionString);
|
var connectionStringbuilder = new SqlConnectionStringBuilder(tableInfo.ConnectionString);
|
||||||
connectionStringbuilder.InitialCatalog = tableInfo.Database;
|
connectionStringbuilder.InitialCatalog = tableInfo.Database;
|
||||||
var connectionString = connectionStringbuilder.ToString();
|
var connectionString = connectionStringbuilder.ToString();
|
||||||
var tableDesigner = new Dac.TableDesigner(connectionString, tableInfo.AccessToken, tableInfo.Schema, tableInfo.Name, tableInfo.IsNewTable);
|
tableDesigner = new Dac.TableDesigner(connectionString, tableInfo.AccessToken, tableInfo.Schema, tableInfo.Name, tableInfo.IsNewTable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tableDesigner = new Dac.TableDesigner(tableInfo.ProjectFilePath, tableInfo.TableScriptPath, tableInfo.AllScripts, tableInfo.TargetVersion);
|
||||||
|
}
|
||||||
this.idTableMap[tableInfo.Id] = tableDesigner;
|
this.idTableMap[tableInfo.Id] = tableDesigner;
|
||||||
return tableDesigner;
|
return tableDesigner;
|
||||||
}
|
}
|
||||||
@@ -1472,6 +1489,14 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateTableTitleInfo(TableInfo tableInfo)
|
||||||
|
{
|
||||||
|
var td = GetTableDesigner(tableInfo);
|
||||||
|
tableInfo.Title = td.TableViewModel.FullName;
|
||||||
|
var tableParent = tableInfo.Server == null ? tableInfo.ProjectFilePath : string.Format("{0} - {1}", tableInfo.Server, tableInfo.Database);
|
||||||
|
tableInfo.Tooltip = string.Format("{0} - {1}", tableParent, tableInfo.Title);
|
||||||
|
}
|
||||||
|
|
||||||
private Dictionary<string, string> GetMetadata(TableInfo tableInfo)
|
private Dictionary<string, string> GetMetadata(TableInfo tableInfo)
|
||||||
{
|
{
|
||||||
var tableDesigner = this.GetTableDesigner(tableInfo);
|
var tableDesigner = this.GetTableDesigner(tableInfo);
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
new TableMustHaveAtLeastOneColumnRule(),
|
new TableMustHaveAtLeastOneColumnRule(),
|
||||||
new MemoryOptimizedTableIdentityColumnRule(),
|
new MemoryOptimizedTableIdentityColumnRule(),
|
||||||
new TableShouldAvoidHavingMultipleEdgeConstraintsRule(),
|
new TableShouldAvoidHavingMultipleEdgeConstraintsRule(),
|
||||||
new ColumnCannotBeListedMoreThanOnceInPrimaryKeyRule()
|
new ColumnCannotBeListedMoreThanOnceInPrimaryKeyRule(),
|
||||||
|
new MutipleCreateTableStatementsInScriptRule()
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -578,4 +579,20 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MutipleCreateTableStatementsInScriptRule : ITableDesignerValidationRule
|
||||||
|
{
|
||||||
|
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||||
|
{
|
||||||
|
var errors = new List<TableDesignerIssue>();
|
||||||
|
if(designer.ScriptContainsMultipleTableDefinition)
|
||||||
|
{
|
||||||
|
errors.Add(new TableDesignerIssue(){
|
||||||
|
Description = "There are multiple table definitions in the script, only the first table can be edited in the designer.",
|
||||||
|
Severity = Contracts.IssueSeverity.Information
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user