table designer - support second level entities (#1381)

* support secondary entities

* new table info for existing table scenario

* delete column confirmation

* vbump Dacfx
This commit is contained in:
Alan Ren
2022-02-02 13:40:45 -08:00
committed by GitHub
parent f57d6b59f6
commit 3c93d57730
10 changed files with 82 additions and 46 deletions

View File

@@ -20,7 +20,7 @@
<PackageReference Update="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="1.1.1" />
<PackageReference Update="Microsoft.Data.SqlClient" Version="3.0.0"/>
<PackageReference Update="Microsoft.SqlServer.SqlManagementObjects" Version="161.46367.54" />
<PackageReference Update="Microsoft.SqlServer.DACFx" Version="160.5400.1-preview" GeneratePathProperty="true" />
<PackageReference Update="Microsoft.SqlServer.DACFx" Version="160.5415.1-preview" GeneratePathProperty="true" />
<PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" />
<PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4"/>
<PackageReference Update="Microsoft.SqlServer.Assessment" Version="[1.0.305]" />

View File

@@ -8645,6 +8645,14 @@ namespace Microsoft.SqlTools.ServiceLayer
}
}
public static string TableDesignerDeleteColumnConfirmationMessage
{
get
{
return Keys.GetString(Keys.TableDesignerDeleteColumnConfirmationMessage);
}
}
public static string ConnectionServiceListDbErrorNotConnected(string uri)
{
return Keys.GetString(Keys.ConnectionServiceListDbErrorNotConnected, uri);
@@ -12372,6 +12380,9 @@ namespace Microsoft.SqlTools.ServiceLayer
public const string TableDesignerColumnsDisplayValueTitle = "TableDesignerColumnsDisplayValueTitle";
public const string TableDesignerDeleteColumnConfirmationMessage = "TableDesignerDeleteColumnConfirmationMessage";
private Keys()
{ }

View File

@@ -4734,4 +4734,8 @@ The Query Processor estimates that implementing the following index could improv
<value>Columns</value>
<comment></comment>
</data>
<data name="TableDesignerDeleteColumnConfirmationMessage" xml:space="preserve">
<value>Removing a column will also remove it from the indexes and foreign keys. Are you sure you want to continue?</value>
<comment></comment>
</data>
</root>

View File

@@ -2256,3 +2256,4 @@ TableDesignerIsUniquePropertyTitle = Is Unique
IndexColumnIsAscendingPropertyDescription = Specifies the sort order of the column.
IndexColumnIsAscendingPropertyTitle = Is Ascending
TableDesignerColumnsDisplayValueTitle = Columns
TableDesignerDeleteColumnConfirmationMessage = Removing a column will also remove it from the indexes and foreign keys. Are you sure you want to continue?

View File

@@ -5742,6 +5742,11 @@
<target state="new">Columns</target>
<note></note>
</trans-unit>
<trans-unit id="TableDesignerDeleteColumnConfirmationMessage">
<source>Removing a column will also remove it from the indexes and foreign keys. Are you sure you want to continue?</source>
<target state="new">Removing a column will also remove it from the indexes and foreign keys. Are you sure you want to continue?</target>
<note></note>
</trans-unit>
<trans-unit id="MissingIndexFormat">
<source>Missing Index (Impact {0}): {1}</source>
<target state="new">Missing Index (Impact {0}): {1}</target>

View File

@@ -37,8 +37,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
public const string Enabled = "enabled";
public const string OnDeleteAction = "onDeleteAction";
public const string OnUpdateAction = "onUpdateAction";
public const string ColumnMapping = "columnMapping";
public const string PrimaryKeyTable = "primaryKeyTable";
public const string ColumnMapping = "columns";
public const string ForeignTable = "foreignTable";
public const string IsNotForReplication = "isNotForReplication";
}
@@ -51,8 +51,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
public static class ForeignKeyColumnMappingPropertyNames
{
public const string PrimaryKeyColumn = "primaryKeyColumn";
public const string ForeignKeyColumn = "foreignKeyColumn";
public const string Column = "column";
public const string ForeignColumn = "foreignColumn";
}
public static class IndexPropertyNames

View File

@@ -10,6 +10,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
{
public class PublishTableChangesResponse
{
public TableInfo NewTableInfo;
}
/// <summary>

View File

@@ -25,8 +25,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
{
public bool ShowTable { get; set; } = true;
public List<string> PropertiesToDisplay { get; set; } = new List<string>();
public bool canAddRows { get; set; } = true;
public bool canRemoveRows { get; set; } = true;
public bool CanAddRows { get; set; } = true;
public bool CanRemoveRows { get; set; } = true;
public List<DesignerDataPropertyInfo> AdditionalProperties { get; set; } = new List<DesignerDataPropertyInfo>();
public string RemoveRowConfirmationMessage { get; set; }
public bool ShowRemoveRowConfirmation { get; set;} = false;
}
}

View File

@@ -18,7 +18,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
public DropdownProperties OnUpdateAction { get; set; } = new DropdownProperties();
public DropdownProperties PrimaryKeyTable { get; set; } = new DropdownProperties();
public DropdownProperties ForeignTable { get; set; } = new DropdownProperties();
public CheckBoxProperties IsNotForReplication { get; set; } = new CheckBoxProperties();
@@ -27,8 +27,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
public class ForeignKeyColumnMapping
{
public DropdownProperties PrimaryKeyColumn { get; set; } = new DropdownProperties();
public DropdownProperties Column { get; set; } = new DropdownProperties();
public DropdownProperties ForeignKeyColumn { get; set; } = new DropdownProperties();
public DropdownProperties ForeignColumn { get; set; } = new DropdownProperties();
}
}

View File

@@ -84,7 +84,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
connectinStringbuilder.InitialCatalog = tableInfo.Database;
var connectionString = connectinStringbuilder.ToString();
var table = new Dac.TableDesigner(connectionString, tableInfo.Schema, tableInfo.Name, tableInfo.IsNewTable);
this.idTableMap.Add(tableInfo.Id, table);
this.idTableMap[tableInfo.Id] = table;
var viewModel = this.GetTableViewModel(tableInfo);
var view = this.GetDesignerViewInfo(tableInfo);
await requestContext.SendResult(new TableDesignerInfo()
@@ -130,7 +130,18 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
{
var tableDesigner = this.GetTableDesigner(tableInfo);
tableDesigner.CommitChanges();
await requestContext.SendResult(new PublishTableChangesResponse());
string newId = string.Format("{0}|{1}|{2}|{3}", tableInfo.ConnectionString, tableInfo.Database, tableDesigner.TableViewModel.Schema, tableDesigner.TableViewModel.Name);
string oldId = tableInfo.Id;
if (newId != oldId)
{
this.idTableMap[newId] = tableDesigner;
this.idTableMap.Remove(oldId);
tableInfo.Name = tableDesigner.TableViewModel.Name;
tableInfo.Schema = tableDesigner.TableViewModel.Schema;
tableInfo.IsNewTable = false;
tableInfo.Id = newId;
}
await requestContext.SendResult(new PublishTableChangesResponse() { NewTableInfo = tableInfo });
});
}
@@ -200,7 +211,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
switch (propertyNameL2)
{
case ForeignKeyPropertyNames.ColumnMapping:
// TODO: handle add item to foreign key's column mapping
table.ForeignKeys.Items[indexL1].AddNewColumnMapping();
break;
default:
break;
@@ -210,7 +221,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
switch (propertyNameL2)
{
case IndexPropertyNames.Columns:
// TODO: handle add item to index's column specification
table.Indexes.Items[indexL1].AddNewColumnSpecification();
break;
default:
break;
@@ -261,7 +272,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
switch (propertyNameL2)
{
case ForeignKeyPropertyNames.ColumnMapping:
// TODO: handle remove item from foreign key's column mapping
table.ForeignKeys.Items[indexL1].RemoveColumnMapping(indexL2);
break;
default:
break;
@@ -271,7 +282,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
switch (propertyNameL2)
{
case IndexPropertyNames.Columns:
// TODO: handle remove item from index's column specification
table.Indexes.Items[indexL1].RemoveColumnSpecification(indexL2);
break;
default:
break;
@@ -390,8 +401,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
case ForeignKeyPropertyNames.OnUpdateAction:
foreignKey.OnUpdateAction = SqlForeignKeyActionUtil.GetValue(GetStringValue(newValue));
break;
case ForeignKeyPropertyNames.PrimaryKeyTable:
foreignKey.PrimaryKeyTable = GetStringValue(newValue);
case ForeignKeyPropertyNames.ForeignTable:
foreignKey.ForeignTable = GetStringValue(newValue);
break;
default:
break;
@@ -431,16 +442,17 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
switch (propertyNameL1)
{
case TablePropertyNames.ForeignKeys:
// TODO: handle foreign key collection property update
// changes need to be made in DACFX to support it.
switch (propertyNameL2)
{
case ForeignKeyPropertyNames.ColumnMapping:
var foreignKey = table.ForeignKeys.Items[indexL1];
switch (propertyNameL3)
{
case ForeignKeyColumnMappingPropertyNames.ForeignKeyColumn:
case ForeignKeyColumnMappingPropertyNames.ForeignColumn:
foreignKey.UpdateForeignColumn(indexL2, GetStringValue(newValue));
break;
case ForeignKeyColumnMappingPropertyNames.PrimaryKeyColumn:
case ForeignKeyColumnMappingPropertyNames.Column:
foreignKey.UpdateColumn(indexL2, GetStringValue(newValue));
break;
default:
break;
@@ -455,14 +467,13 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
switch (propertyNameL2)
{
case IndexPropertyNames.Columns:
var columnSpec = sqlIndex.Columns[indexL2];
switch (propertyNameL3)
{
case IndexColumnSpecificationPropertyNames.Column:
columnSpec.Column = GetStringValue(newValue);
sqlIndex.UpdateColumnName(indexL2, GetStringValue(newValue));
break;
case IndexColumnSpecificationPropertyNames.Ascending:
columnSpec.isAscending = GetBooleanValue(newValue);
sqlIndex.UpdateIsAscending(indexL2, GetBooleanValue(newValue));
break;
default:
break;
@@ -539,18 +550,18 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
foreignKeyViewModel.OnDeleteAction.Values = SqlForeignKeyActionUtil.ActionNames;
foreignKeyViewModel.OnUpdateAction.Value = SqlForeignKeyActionUtil.GetName(foreignKey.OnUpdateAction);
foreignKeyViewModel.OnUpdateAction.Values = SqlForeignKeyActionUtil.ActionNames;
foreignKeyViewModel.PrimaryKeyTable.Value = foreignKey.PrimaryKeyTable;
foreignKeyViewModel.PrimaryKeyTable.Values = tableDesigner.AllTables.ToList();
foreignKeyViewModel.ForeignTable.Value = foreignKey.ForeignTable;
foreignKeyViewModel.ForeignTable.Values = tableDesigner.AllTables.ToList();
foreignKeyViewModel.IsNotForReplication.Checked = foreignKey.IsNotForReplication;
for (int i = 0; i < foreignKey.ForeignKeyColumns.Count; i++)
for (int i = 0; i < foreignKey.ForeignColumns.Count; i++)
{
var foreignKeyColumn = foreignKey.ForeignKeyColumns[i];
var primaryKeyColumn = foreignKey.PrimaryKeyColumns[i];
var foreignColumn = foreignKey.ForeignColumns[i];
var column = foreignKey.Columns[i];
var mapping = new ForeignKeyColumnMapping();
mapping.ForeignKeyColumn.Value = foreignKeyColumn;
mapping.ForeignKeyColumn.Values = table.Columns.Items.Select(c => c.Name).ToList();
mapping.PrimaryKeyColumn.Value = primaryKeyColumn;
mapping.PrimaryKeyColumn.Values = tableDesigner.GetColumnsForTable(foreignKey.PrimaryKeyTable).ToList();
mapping.ForeignColumn.Value = foreignColumn;
mapping.ForeignColumn.Values = tableDesigner.GetColumnsForTable(foreignKey.ForeignTable).ToList();
mapping.Column.Value = column;
mapping.Column.Values = tableDesigner.GetColumnsForTable(table.FullName).ToList();
foreignKeyViewModel.Columns.Data.Add(mapping);
}
tableViewModel.ForeignKeys.Data.Add(foreignKeyViewModel);
@@ -577,7 +588,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
var columnSpecVM = new IndexedColumnSpecification();
columnSpecVM.Ascending.Checked = columnSpec.isAscending;
columnSpecVM.Column.Value = columnSpec.Column;
columnSpecVM.Column.Values = table.Columns.Items.Select(c => c.Name).ToList();
columnSpecVM.Column.Values = tableDesigner.GetColumnsForTable(table.FullName).ToList();
indexVM.Columns.Data.Add(columnSpecVM);
}
indexVM.ColumnsDisplayValue.Value = index.ColumnsDisplayValue;
@@ -586,7 +597,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
}
tableViewModel.Script.Enabled = false;
tableViewModel.Script.Value = tableDesigner.Script;
// TODO: set other properties of the table
return tableViewModel;
}
@@ -637,8 +647,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
}
}
});
view.ColumnTableOptions.canAddRows = true;
view.ColumnTableOptions.canRemoveRows = true;
view.ColumnTableOptions.CanAddRows = true;
view.ColumnTableOptions.CanRemoveRows = true;
view.ColumnTableOptions.RemoveRowConfirmationMessage = SR.TableDesignerDeleteColumnConfirmationMessage;
view.ColumnTableOptions.ShowRemoveRowConfirmation = true;
}
private void SetForeignKeysViewInfo(TableDesignerView view)
@@ -665,8 +677,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
}
}
});
view.ForeignKeyTableOptions.canAddRows = true;
view.ForeignKeyTableOptions.canRemoveRows = true;
view.ForeignKeyTableOptions.CanAddRows = true;
view.ForeignKeyTableOptions.CanRemoveRows = true;
}
private void SetCheckConstraintsViewInfo(TableDesignerView view)
@@ -682,8 +694,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
Title = SR.TableDesignerIsEnabledPropertyTitle
}
});
view.CheckConstraintTableOptions.canAddRows = true;
view.CheckConstraintTableOptions.canRemoveRows = true;
view.CheckConstraintTableOptions.CanAddRows = true;
view.CheckConstraintTableOptions.CanRemoveRows = true;
}
private void SetIndexesViewInfo(TableDesignerView view)
@@ -732,8 +744,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
}
});
view.IndexTableOptions.PropertiesToDisplay = new List<string>() { IndexPropertyNames.Name, IndexPropertyNames.ColumnsDisplayValue, IndexPropertyNames.IsClustered, IndexPropertyNames.IsUnique };
view.IndexTableOptions.canAddRows = true;
view.IndexTableOptions.canRemoveRows = true;
view.IndexTableOptions.CanAddRows = true;
view.IndexTableOptions.CanRemoveRows = true;
view.IndexColumnSpecificationTableOptions.AdditionalProperties.Add(
new DesignerDataPropertyInfo()
@@ -747,8 +759,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
}
});
view.IndexColumnSpecificationTableOptions.PropertiesToDisplay.AddRange(new string[] { IndexColumnSpecificationPropertyNames.Column, IndexColumnSpecificationPropertyNames.Ascending });
view.IndexColumnSpecificationTableOptions.canAddRows = true;
view.IndexColumnSpecificationTableOptions.canRemoveRows = true;
view.IndexColumnSpecificationTableOptions.CanAddRows = true;
view.IndexColumnSpecificationTableOptions.CanRemoveRows = true;
}
private Dac.TableDesigner GetTableDesigner(TableInfo tableInfo)