Skip to content

Commit b4c07bd

Browse files
committed
Adds detection of recreated table data cleanup
1 parent 44c4a25 commit b4c07bd

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Orm/Xtensive.Orm/Orm/Upgrade/Internals/SchemaComparer.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private static IList<NodeAction> GetUnsafeActions(ICollection<NodeAction> action
125125
GetUnsafeColumnTypeChanges(actions, hints, unsafeActions);
126126
GetUnsafeColumnRemovals(actions, hints, unsafeActions);
127127
GetUnsafeTableRemovals(actions, hints, unsafeActions);
128-
GetCrossHierarchicalMovements(actions, hints, unsafeActions);
128+
GetUnsafeDataActions(actions, hints, unsafeActions);
129129

130130
return unsafeActions;
131131
}
@@ -225,14 +225,33 @@ private static void GetUnsafeTableRemovals(IEnumerable<NodeAction> actions, IEnu
225225
.ForEach(output.Add);
226226
}
227227

228-
private static void GetCrossHierarchicalMovements(IEnumerable<NodeAction> actions, IEnumerable<UpgradeHint> hints, ICollection<NodeAction> output)
228+
private static void GetUnsafeDataActions(IEnumerable<NodeAction> actions, IEnumerable<UpgradeHint> hints, ICollection<NodeAction> output)
229+
{
230+
GetCrossHierarchicalMovements(actions, output);
231+
GetTableRecreateDataLossActions(actions, output);
232+
}
233+
234+
private static void GetCrossHierarchicalMovements(IEnumerable<NodeAction> actions, ICollection<NodeAction> output)
229235
{
230236
(from action in actions.OfType<DataAction>()
231237
let deleteDataHint = action.DataHint as DeleteDataHint
232238
where deleteDataHint!=null && deleteDataHint.PostCopy
233239
select action).ForEach(output.Add);
234240
}
235241

242+
private static void GetTableRecreateDataLossActions(IEnumerable<NodeAction> actions, ICollection<NodeAction> output)
243+
{
244+
actions.OfType<DataAction>()
245+
.Select(da => new {
246+
DataAction = da,
247+
Difference = da.Difference as NodeDifference,
248+
DeleteDataHint = da.DataHint as DeleteDataHint
249+
})
250+
.Where(a => a.DeleteDataHint != null && a.Difference != null && a.Difference.MovementInfo.HasFlag(MovementInfo.Removed | MovementInfo.Created))
251+
.Select(a => a.DataAction)
252+
.ForEach(output.Add);
253+
}
254+
236255
private static bool IsTypeChangeAction(PropertyChangeAction action)
237256
{
238257
return action.Properties.ContainsKey("Type")

0 commit comments

Comments
 (0)