diff --git a/Packages.props b/Packages.props index 34da7223..e978d129 100644 --- a/Packages.props +++ b/Packages.props @@ -20,7 +20,7 @@ - + diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index 3e75b055..e847cfbf 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -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() { } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index b6300966..0b7b21f7 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -4734,4 +4734,8 @@ The Query Processor estimates that implementing the following index could improv Columns + + Removing a column will also remove it from the indexes and foreign keys. Are you sure you want to continue? + + diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index 2b654574..5ba08580 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -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? diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf index c22c139c..818f42f5 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -5742,6 +5742,11 @@ Columns + + Removing a column will also remove it from the indexes and foreign keys. Are you sure you want to continue? + Removing a column will also remove it from the indexes and foreign keys. Are you sure you want to continue? + + Missing Index (Impact {0}): {1} Missing Index (Impact {0}): {1} diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs index dd43b83d..5772435e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs @@ -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 diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Requests/PublishTableChangesRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Requests/PublishTableChangesRequest.cs index 23c811c6..c99a7a47 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Requests/PublishTableChangesRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Requests/PublishTableChangesRequest.cs @@ -10,6 +10,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts { public class PublishTableChangesResponse { + public TableInfo NewTableInfo; } /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs index 89495abe..3feb600e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs @@ -25,8 +25,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts { public bool ShowTable { get; set; } = true; public List PropertiesToDisplay { get; set; } = new List(); - 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 AdditionalProperties { get; set; } = new List(); + public string RemoveRowConfirmationMessage { get; set; } + public bool ShowRemoveRowConfirmation { get; set;} = false; } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/ForeignKeyViewModel.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/ForeignKeyViewModel.cs index 77c222c1..281c7911 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/ForeignKeyViewModel.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/ForeignKeyViewModel.cs @@ -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(); } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs index 7e8fed72..e2d08d05 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs @@ -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() { 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)