Skip to content

Commit a534286

Browse files
committed
HintGenerator creates new RecreateTableHint
It does it when some removed types and new types have tables conflicted by name
1 parent 973ea7f commit a534286

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Orm/Xtensive.Orm/Orm/Upgrade/Internals/HintGenerator.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ internal sealed class HintGenerator
3535
private readonly Dictionary<StoredTypeInfo, StoredFieldInfo[]> extractedModelFields;
3636

3737
private readonly NativeTypeClassifier<UpgradeHint> hints;
38+
private readonly HashSet<StoredTypeInfo> suspiciousTypes;
3839

3940
private readonly List<Hint> schemaHints = new List<Hint>();
4041

@@ -49,6 +50,7 @@ public HintGenerationResult Run()
4950
GenerateCopyColumnHints(copyFieldHints);
5051

5152
var removedTypes = GetRemovedTypes(extractedModel);
53+
GenerateRecreateHints(removedTypes);
5254
GenerateRecordCleanupHints(removedTypes, false);
5355

5456
var movedTypes = GetMovedTypes(extractedModel);
@@ -190,6 +192,21 @@ private void GenerateCopyColumnHint(CopyFieldHint hint)
190192
}
191193
}
192194

195+
private void GenerateRecreateHints(ICollection<StoredTypeInfo> removedTypes)
196+
{
197+
var capacity = currentModel.Types.Length - typeMapping.Count;
198+
var newTypes = new Dictionary<string, StoredTypeInfo>(capacity, StringComparer.Ordinal);
199+
processingResults.CurrentNonConnectorTypes.Where(t => !reverseTypeMapping.ContainsKey(t))
200+
.ForEach(t => newTypes.Add($"{t.MappingDatabase}.{t.MappingSchema}.{t.MappingName}", t));
201+
202+
foreach (var rType in removedTypes) {
203+
if (!suspiciousTypes.Contains(rType)
204+
|| !newTypes.TryGetValue($"{rType.MappingDatabase}.{rType.MappingSchema}.{rType.MappingName}", out var conflictedNewType))
205+
continue;
206+
schemaHints.Add(new RecreateTableHint(GetTablePath(rType)));
207+
}
208+
}
209+
193210
private void GenerateRecordCleanupHints(List<StoredTypeInfo> removedTypes, bool isMovedToAnotherHierarchy)
194211
{
195212
if (!isMovedToAnotherHierarchy)
@@ -742,6 +759,7 @@ public HintGenerator(UpgradeHintsProcessingResult hintsProcessingResult,
742759
reverseTypeMapping = hintsProcessingResult.ReverseTypeMapping;
743760
fieldMapping = hintsProcessingResult.FieldMapping;
744761
hints = hintsProcessingResult.Hints;
762+
suspiciousTypes = hintsProcessingResult.SuspiciousTypes;
745763

746764
this.extractedStorageModel = extractedStorageModel;
747765
this.resolver = resolver;

0 commit comments

Comments
 (0)