mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
[Table Designer] Add validators for computed col in PK and FK (#1653)
This commit is contained in:
@@ -9804,6 +9804,16 @@ namespace Microsoft.SqlTools.ServiceLayer
|
|||||||
return Keys.GetString(Keys.ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription, columnName, indexName, rowNumber);
|
return Keys.GetString(Keys.ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription, columnName, indexName, rowNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRuleDescription(string columnName)
|
||||||
|
{
|
||||||
|
return Keys.GetString(Keys.ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRuleDescription, columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ComputedColumnNeedToBePersistedInForeignKeyRuleDescription(string columnName, string foreignKeyName)
|
||||||
|
{
|
||||||
|
return Keys.GetString(Keys.ComputedColumnNeedToBePersistedInForeignKeyRuleDescription, columnName, foreignKeyName);
|
||||||
|
}
|
||||||
|
|
||||||
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
public class Keys
|
public class Keys
|
||||||
{
|
{
|
||||||
@@ -13562,6 +13572,12 @@ namespace Microsoft.SqlTools.ServiceLayer
|
|||||||
public const string ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription = "ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription";
|
public const string ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription = "ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription";
|
||||||
|
|
||||||
|
|
||||||
|
public const string ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRuleDescription = "ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRuleDescription";
|
||||||
|
|
||||||
|
|
||||||
|
public const string ComputedColumnNeedToBePersistedInForeignKeyRuleDescription = "ComputedColumnNeedToBePersistedInForeignKeyRuleDescription";
|
||||||
|
|
||||||
|
|
||||||
private Keys()
|
private Keys()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|||||||
@@ -5196,4 +5196,14 @@ The Query Processor estimates that implementing the following index could improv
|
|||||||
<comment>.
|
<comment>.
|
||||||
Parameters: 0 - columnName (string), 1 - indexName (string), 2 - rowNumber (int) </comment>
|
Parameters: 0 - columnName (string), 1 - indexName (string), 2 - rowNumber (int) </comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRuleDescription" xml:space="preserve">
|
||||||
|
<value>The computed column with name '{0}' has to be persisted and not nullable to be part of a primary key.</value>
|
||||||
|
<comment>.
|
||||||
|
Parameters: 0 - columnName (string) </comment>
|
||||||
|
</data>
|
||||||
|
<data name="ComputedColumnNeedToBePersistedInForeignKeyRuleDescription" xml:space="preserve">
|
||||||
|
<value>The computed column with name '{0}' has to be persisted to be part of the foreign key '{1}'.</value>
|
||||||
|
<comment>.
|
||||||
|
Parameters: 0 - columnName (string), 1 - foreignKeyName (string) </comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
@@ -2379,4 +2379,6 @@ MutipleCreateTableStatementsInScriptRuleDescription = There are multiple table d
|
|||||||
ClusteredIndexCannotHaveIncludedColumnsRuleDescription = Included columns are not supported for a clustered index.
|
ClusteredIndexCannotHaveIncludedColumnsRuleDescription = Included columns are not supported for a clustered index.
|
||||||
ClusteredIndexCannotHaveFilterPredicateRuleDescription = Filter predicate is not supported for a clustered index.
|
ClusteredIndexCannotHaveFilterPredicateRuleDescription = Filter predicate is not supported for a clustered index.
|
||||||
ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription(string columnName, string indexName, int rowNumber) = Column with name '{0}' has already been included to the index '{1}'. Row number: {2}.
|
ColumnCanOnlyAppearOnceInIndexIncludedColumnsRuleDescription(string columnName, string indexName, int rowNumber) = Column with name '{0}' has already been included to the index '{1}'. Row number: {2}.
|
||||||
ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription(string columnName, string indexName, int rowNumber) = Included column with name '{0}' has already been part of the index '{1}' and it cannot be included. Row number: {2}.
|
ColumnCannotDuplicateWitIndexKeyColumnsRuleDescription(string columnName, string indexName, int rowNumber) = Included column with name '{0}' has already been part of the index '{1}' and it cannot be included. Row number: {2}.
|
||||||
|
ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRuleDescription(string columnName) = The computed column with name '{0}' has to be persisted and not nullable to be part of a primary key.
|
||||||
|
ComputedColumnNeedToBePersistedInForeignKeyRuleDescription(string columnName, string foreignKeyName) = The computed column with name '{0}' has to be persisted to be part of the foreign key '{1}'.
|
||||||
@@ -6331,6 +6331,18 @@ The Query Processor estimates that implementing the following index could improv
|
|||||||
<target state="new">Dropped Ledger Views</target>
|
<target state="new">Dropped Ledger Views</target>
|
||||||
<note></note>
|
<note></note>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRuleDescription">
|
||||||
|
<source>The computed column with name '{0}' has to be persisted and not nullable to be part of a primary key.</source>
|
||||||
|
<target state="new">The computed column with name '{0}' has to be persisted and not nullable to be part of a primary key.</target>
|
||||||
|
<note>.
|
||||||
|
Parameters: 0 - columnName (string) </note>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="ComputedColumnNeedToBePersistedInForeignKeyRuleDescription">
|
||||||
|
<source>The computed column with name '{0}' has to be persisted to be part of the foreign key '{1}'.</source>
|
||||||
|
<target state="new">The computed column with name '{0}' has to be persisted to be part of the foreign key '{1}'.</target>
|
||||||
|
<note>.
|
||||||
|
Parameters: 0 - columnName (string), 1 - foreignKeyName (string) </note>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
@@ -37,7 +37,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
new ClusteredIndexCannotHaveFilterPredicate(),
|
new ClusteredIndexCannotHaveFilterPredicate(),
|
||||||
new ClusteredIndexCannotHaveIncludedColumnsRule(),
|
new ClusteredIndexCannotHaveIncludedColumnsRule(),
|
||||||
new ColumnCanOnlyAppearOnceInIndexIncludedColumnsRule(),
|
new ColumnCanOnlyAppearOnceInIndexIncludedColumnsRule(),
|
||||||
new ColumnCannotDuplicateWitIndexKeyColumnsRule()
|
new ColumnCannotDuplicateWitIndexKeyColumnsRule(),
|
||||||
|
new ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRule(),
|
||||||
|
new ComputedColumnNeedToBePersistedInForeignKeyRule()
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -664,6 +666,57 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRule : ITableDesignerValidationRule
|
||||||
|
{
|
||||||
|
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||||
|
{
|
||||||
|
var table = designer.TableViewModel;
|
||||||
|
var errors = new List<TableDesignerIssue>();
|
||||||
|
if (table.PrimaryKey != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < table.PrimaryKey.Columns.Count; i++)
|
||||||
|
{
|
||||||
|
var columnSpec = table.PrimaryKey.Columns[i];
|
||||||
|
var col = table.Columns.Items.First(item => item.Name == columnSpec.Column);
|
||||||
|
if (col != null && col.IsComputed && !(col.IsComputedPersisted == true && col.IsComputedPersistedNullable == false))
|
||||||
|
{
|
||||||
|
errors.Add(new TableDesignerIssue()
|
||||||
|
{
|
||||||
|
Description = SR.ComputedColumnNeedToBePersistedAndNotNullInPrimaryKeyRuleDescription(col.Name),
|
||||||
|
PropertyPath = new object[] { TablePropertyNames.PrimaryKeyColumns, i, IndexColumnSpecificationPropertyNames.Column }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ComputedColumnNeedToBePersistedInForeignKeyRule : ITableDesignerValidationRule
|
||||||
|
{
|
||||||
|
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||||
|
{
|
||||||
|
var table = designer.TableViewModel;
|
||||||
|
var errors = new List<TableDesignerIssue>();
|
||||||
|
for (int i = 0; i < table.ForeignKeys.Items.Count; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < table.ForeignKeys.Items[i].Columns.Count; j++)
|
||||||
|
{
|
||||||
|
var col = table.Columns.Items.First(item => item.Name == table.ForeignKeys.Items[i].Columns[j]);
|
||||||
|
if (col != null && col.IsComputed && col.IsComputedPersisted != true)
|
||||||
|
{
|
||||||
|
errors.Add(new TableDesignerIssue()
|
||||||
|
{
|
||||||
|
Description = SR.ComputedColumnNeedToBePersistedInForeignKeyRuleDescription(col.Name, table.ForeignKeys.Items[i].SystemName),
|
||||||
|
PropertyPath = new object[] { TablePropertyNames.ForeignKeys, i, ForeignKeyPropertyNames.ColumnMapping, j, ForeignKeyColumnMappingPropertyNames.Column }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class MemoryOptimizedCannotBeEnabledWhenNotSupportedRule : ITableDesignerValidationRule
|
public class MemoryOptimizedCannotBeEnabledWhenNotSupportedRule : ITableDesignerValidationRule
|
||||||
{
|
{
|
||||||
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
public List<TableDesignerIssue> Run(Dac.TableDesigner designer)
|
||||||
|
|||||||
Reference in New Issue
Block a user