Skip to content

Commit 0604cde

Browse files
committed
Hint validation: Add check for renaming field type existance in both models
1 parent 9aed48b commit 0604cde

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

Orm/Xtensive.Orm/Orm/Upgrade/Internals/UpgradeHintValidator.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ private void ValidateRenameFieldHints(IEnumerable<RenameFieldHint> hints)
6565
var targetType = currentModel.Types.SingleOrDefault(type => type.UnderlyingType == targetTypeName);
6666
if (targetType==null)
6767
throw TypeNotFound(targetTypeName);
68-
var sourceType = reverseTypeMapping[targetType];
68+
if (!reverseTypeMapping.TryGetValue(targetType, out var sourceType))
69+
throw TypeNotFoundInStorageModel(targetTypeName, hint.OldFieldName);
6970
var sourceTypeName = sourceType.UnderlyingType;
7071
if (sourceType.GetField(hint.OldFieldName)==null)
7172
throw FieldNotFound(sourceTypeName, hint.OldFieldName);
@@ -145,20 +146,17 @@ private void ValidateRemoveTypeHints(IEnumerable<RemoveTypeHint> hints)
145146
}
146147
}
147148

148-
private static InvalidOperationException TypeNotFound(string name)
149-
{
150-
return new InvalidOperationException(string.Format(Strings.ExTypeXIsNotFound, name));
151-
}
149+
private static InvalidOperationException TypeNotFound(string name) =>
150+
new InvalidOperationException(string.Format(Strings.ExTypeXIsNotFound, name));
152151

153-
private static InvalidOperationException FieldNotFound(string typeName, string fieldName)
154-
{
155-
return new InvalidOperationException(string.Format(Strings.ExFieldXYIsNotFound, typeName, fieldName));
156-
}
152+
private static InvalidOperationException TypeNotFoundInStorageModel(string typeName, string oldFieldName) =>
153+
new InvalidOperationException(string.Format(Strings.ExTypeXWhichContainsRenamingFieldYDoesntExistInStorageModel, typeName, oldFieldName));
157154

158-
private static InvalidOperationException HintConflict(UpgradeHint hintOne, UpgradeHint hintTwo)
159-
{
160-
return new InvalidOperationException(string.Format(Strings.ExHintXIsConflictingWithHintY, hintOne, hintTwo));
161-
}
155+
private static InvalidOperationException FieldNotFound(string typeName, string fieldName) =>
156+
new InvalidOperationException(string.Format(Strings.ExFieldXYIsNotFound, typeName, fieldName));
157+
158+
private static InvalidOperationException HintConflict(UpgradeHint hintOne, UpgradeHint hintTwo) =>
159+
new InvalidOperationException(string.Format(Strings.ExHintXIsConflictingWithHintY, hintOne, hintTwo));
162160

163161
public UpgradeHintValidator(StoredDomainModel currentModel, StoredDomainModel extractedModel, Dictionary<StoredTypeInfo, StoredTypeInfo> typeMapping, Dictionary<StoredTypeInfo, StoredTypeInfo> reverseTypeMapping)
164162
{

Orm/Xtensive.Orm/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Orm/Xtensive.Orm/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3479,4 +3479,7 @@ Error: {1}</value>
34793479
<data name="ExJoinHasSameInnerAndOuterParameterInstances" xml:space="preserve">
34803480
<value>Inner and outer selector expressions have the same parameter instance. Probably you use the same lambda expression for both selectors, which is currently not supported.</value>
34813481
</data>
3482+
<data name="ExTypeXWhichContainsRenamingFieldYDoesntExistInStorageModel" xml:space="preserve">
3483+
<value>The type '{0}',which contains renaming field '{1}', doesn't exist in storage model.</value>
3484+
</data>
34823485
</root>

0 commit comments

Comments
 (0)