mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-02 01:25:42 -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:
@@ -2,7 +2,6 @@
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||
{
|
||||
@@ -15,8 +14,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||
|
||||
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 BuiltinTableOptions PrimaryKeyColumnSpecificationTableOptions = new BuiltinTableOptions();
|
||||
public List<DesignerTabView> AdditionalTabs { get; } = new List<DesignerTabView>();
|
||||
public bool UseAdvancedSaveMode { get; set; }
|
||||
}
|
||||
|
||||
public class BuiltinTableOptions
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
// 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
|
||||
{
|
||||
/// <summary>
|
||||
@@ -10,6 +12,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||
/// </summary>
|
||||
public class TableInfo
|
||||
{
|
||||
public string Title { get; set; }
|
||||
|
||||
public string Tooltip { get; set; }
|
||||
|
||||
public string Server { get; set; }
|
||||
|
||||
public string Database { get; set; }
|
||||
@@ -25,5 +31,13 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||
public string Id { 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 viewModel = this.GetTableViewModel(tableInfo);
|
||||
var view = this.GetDesignerViewInfo(tableInfo);
|
||||
this.UpdateTableTitleInfo(tableInfo);
|
||||
var issues = TableDesignerValidator.Validate(tableDesigner);
|
||||
await requestContext.SendResult(new TableDesignerInfo()
|
||||
{
|
||||
ViewModel = viewModel,
|
||||
View = view
|
||||
View = view,
|
||||
TableInfo = tableInfo,
|
||||
Issues = issues.ToArray()
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -144,19 +148,23 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
{
|
||||
var tableDesigner = this.GetTableDesigner(tableInfo);
|
||||
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;
|
||||
this.idTableMap.Remove(oldId);
|
||||
if (newId != oldId)
|
||||
if (tableInfo.ProjectFilePath == null)
|
||||
{
|
||||
tableInfo.Name = tableDesigner.TableViewModel.Name;
|
||||
tableInfo.Schema = tableDesigner.TableViewModel.Schema;
|
||||
tableInfo.IsNewTable = false;
|
||||
tableInfo.Id = newId;
|
||||
string newId = string.Format("{0}|{1}|{2}|{3}|{4}", STSHost.ProviderName, tableInfo.Server, tableInfo.Database, tableDesigner.TableViewModel.Schema, tableDesigner.TableViewModel.Name);
|
||||
if (newId != oldId)
|
||||
{
|
||||
tableInfo.Name = tableDesigner.TableViewModel.Name;
|
||||
tableInfo.Schema = tableDesigner.TableViewModel.Schema;
|
||||
tableInfo.IsNewTable = false;
|
||||
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.
|
||||
// Todo: improve the dacfx table designer feature, so that we don't have to recreate it.
|
||||
this.CreateTableDesigner(tableInfo);
|
||||
this.UpdateTableTitleInfo(tableInfo);
|
||||
await requestContext.SendResult(new PublishTableChangesResponse()
|
||||
{
|
||||
NewTableInfo = tableInfo,
|
||||
@@ -948,6 +956,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
this.SetEdgeConstraintsViewInfo(view, tableDesigner);
|
||||
this.SetTemporalTableViewInfo(view, tableDesigner);
|
||||
this.SetMemoryOptimizedTableViewInfo(view, tableDesigner);
|
||||
view.UseAdvancedSaveMode = tableInfo.ProjectFilePath == null;
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -1451,10 +1460,18 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
|
||||
private Dac.TableDesigner CreateTableDesigner(TableInfo tableInfo)
|
||||
{
|
||||
var connectionStringbuilder = new SqlConnectionStringBuilder(tableInfo.ConnectionString);
|
||||
connectionStringbuilder.InitialCatalog = tableInfo.Database;
|
||||
var connectionString = connectionStringbuilder.ToString();
|
||||
var tableDesigner = new Dac.TableDesigner(connectionString, tableInfo.AccessToken, tableInfo.Schema, tableInfo.Name, tableInfo.IsNewTable);
|
||||
Dac.TableDesigner tableDesigner;
|
||||
if (tableInfo.TableScriptPath == null)
|
||||
{
|
||||
var connectionStringbuilder = new SqlConnectionStringBuilder(tableInfo.ConnectionString);
|
||||
connectionStringbuilder.InitialCatalog = tableInfo.Database;
|
||||
var connectionString = connectionStringbuilder.ToString();
|
||||
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;
|
||||
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)
|
||||
{
|
||||
var tableDesigner = this.GetTableDesigner(tableInfo);
|
||||
|
||||
@@ -32,7 +32,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
new TableMustHaveAtLeastOneColumnRule(),
|
||||
new MemoryOptimizedTableIdentityColumnRule(),
|
||||
new TableShouldAvoidHavingMultipleEdgeConstraintsRule(),
|
||||
new ColumnCannotBeListedMoreThanOnceInPrimaryKeyRule()
|
||||
new ColumnCannotBeListedMoreThanOnceInPrimaryKeyRule(),
|
||||
new MutipleCreateTableStatementsInScriptRule()
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -578,4 +579,20 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
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