|
|
@@ -333,22 +333,54 @@ internal class Update_8_58 : DatabaseUpdateScript
|
|
|
filter: Filter<DigitalForm>.Where(x => x.ID).InList(qaQuestions.ToArray(x => x.FormID)));
|
|
|
}
|
|
|
|
|
|
+ private class ExtraMap<TFrom, TTo>
|
|
|
+ {
|
|
|
+ public IProperty From { get; }
|
|
|
+
|
|
|
+ public IProperty To { get; }
|
|
|
+
|
|
|
+ public Func<object?, object?>? Map { get; init; } = null;
|
|
|
+
|
|
|
+ public ExtraMap(Expression<Func<TFrom, object?>> from, Expression<Func<TTo, object?>> to)
|
|
|
+ {
|
|
|
+ From = DatabaseSchema.PropertyStrict(from);
|
|
|
+ To = DatabaseSchema.PropertyStrict(to);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ExtraMap(IProperty from, IProperty to)
|
|
|
+ {
|
|
|
+ From = from;
|
|
|
+ To = to;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ExtraMap<TFrom, TTo> New<TFromValue, TToValue>(
|
|
|
+ Expression<Func<TFrom, TFromValue>> from,
|
|
|
+ Expression<Func<TTo, TToValue>> to,
|
|
|
+ Func<TFromValue, TToValue> map)
|
|
|
+ {
|
|
|
+ return new(
|
|
|
+ DatabaseSchema.PropertyStrict(from),
|
|
|
+ DatabaseSchema.PropertyStrict(to))
|
|
|
+ {
|
|
|
+ Map = x => x is TFromValue tFrom ? map(tFrom) : default
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static void RenameTable<TFrom, TTo>(IProvider provider,
|
|
|
- Dictionary<Expression<Func<TFrom, object?>>, Expression<Func<TTo, object?>>>? extraMaps = null)
|
|
|
+ List<ExtraMap<TFrom, TTo>>? extraMaps = null)
|
|
|
where TFrom : Entity, new()
|
|
|
where TTo : Entity, new()
|
|
|
{
|
|
|
var currentMaps = new HashSet<string>();
|
|
|
|
|
|
- var maps = new List<(IProperty from, IProperty to)>();
|
|
|
+ var maps = new List<(IProperty from, IProperty to, Func<object?, object?>? map)>();
|
|
|
|
|
|
- foreach(var (from, to) in extraMaps ?? [])
|
|
|
+ foreach(var map in extraMaps ?? [])
|
|
|
{
|
|
|
- var fromProperty = DatabaseSchema.PropertyStrict(from);
|
|
|
- var toProperty = DatabaseSchema.PropertyStrict(to);
|
|
|
- currentMaps.Add(fromProperty.Name);
|
|
|
+ currentMaps.Add(map.From.Name);
|
|
|
|
|
|
- maps.Add((fromProperty, toProperty));
|
|
|
+ maps.Add((map.From, map.To, map.Map));
|
|
|
}
|
|
|
|
|
|
foreach(var fromProperty in DatabaseSchema.LocalProperties(typeof(TFrom)))
|
|
|
@@ -361,7 +393,7 @@ internal class Update_8_58 : DatabaseUpdateScript
|
|
|
{
|
|
|
throw new Exception($"Cannot migrate {typeof(TFrom).Name}.{fromProperty.Name} -> {typeof(TTo).Name}.{toProperty.Name}: type mismatch");
|
|
|
}
|
|
|
- maps.Add((fromProperty, toProperty));
|
|
|
+ maps.Add((fromProperty, toProperty, null));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -389,9 +421,16 @@ internal class Update_8_58 : DatabaseUpdateScript
|
|
|
var newItem = new TTo();
|
|
|
newItem.SetObserving(false);
|
|
|
newItem.ID = item.ID;
|
|
|
- foreach(var (from, to) in maps)
|
|
|
+ foreach(var (from, to, map) in maps)
|
|
|
{
|
|
|
- to.Setter()(newItem, from.Getter()(item));
|
|
|
+ if(map is not null)
|
|
|
+ {
|
|
|
+ to.Setter()(newItem, map(from.Getter()(item)));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ to.Setter()(newItem, from.Getter()(item));
|
|
|
+ }
|
|
|
}
|
|
|
newItem.SetObserving(true);
|
|
|
newItems.Add(newItem);
|
|
|
@@ -400,6 +439,9 @@ internal class Update_8_58 : DatabaseUpdateScript
|
|
|
},
|
|
|
1000,
|
|
|
percentage => Logger.Send(LogType.Information, "", $"Migrating {typeof(TFrom).Name}: {percentage:F2}%"));
|
|
|
+
|
|
|
+ ConvertColumnsTag(provider, typeof(TFrom).Name, typeof(TTo).Name);
|
|
|
+ UpdateAutoSecurityTokens<TFrom, TTo>(provider);
|
|
|
}
|
|
|
|
|
|
private static void ConvertLinks(IProvider provider)
|
|
|
@@ -517,10 +559,9 @@ internal class Update_8_58 : DatabaseUpdateScript
|
|
|
|
|
|
RenameTable<Requisition, PickingList>(provider);
|
|
|
RenameTable<RequisitionItem, PickingListItem>(provider,
|
|
|
- new()
|
|
|
- {
|
|
|
- { x => x.Requisition.ID, x => x.PickingList.ID }
|
|
|
- });
|
|
|
+ [
|
|
|
+ new(x => x.Requisition.ID, x => x.PickingList.ID)
|
|
|
+ ]);
|
|
|
RenameTable<RequisitionDestination, PickingListDestination>(provider);
|
|
|
RenameTable<RequisitionDocument, PickingListDocument>(provider);
|
|
|
RenameTable<RequisitionKanban, PickingListKanban>(provider);
|
|
|
@@ -639,12 +680,6 @@ internal class Update_8_58 : DatabaseUpdateScript
|
|
|
UpdateSecurityToken(provider, "CanSkipRequisitionPhotos", nameof(CanSkipPickingListPhotos));
|
|
|
UpdateSecurityToken(provider, "CanUpdateRequisitionStockMovements", nameof(CanUpdatePickingListStockMovements));
|
|
|
UpdateSecurityToken(provider, "CanArchiveRequisitions", nameof(CanArchivePickingLists));
|
|
|
-
|
|
|
- UpdateAutoSecurityTokens<Requisition, PickingList>(provider);
|
|
|
- UpdateAutoSecurityTokens<RequisitionItem, PickingListItem>(provider);
|
|
|
- UpdateAutoSecurityTokens<RequisitionDestination, PickingListDestination>(provider);
|
|
|
- UpdateAutoSecurityTokens<RequisitionDocument, PickingListDocument>(provider);
|
|
|
- UpdateAutoSecurityTokens<RequisitionKanban, PickingListKanban>(provider);
|
|
|
}
|
|
|
|
|
|
private static void ConvertSettings<T>(IProvider provider, string fromSection, string toSection)
|
|
|
@@ -707,12 +742,6 @@ internal class Update_8_58 : DatabaseUpdateScript
|
|
|
|
|
|
ConvertSettings<UserSettings>(provider, "RequisitionSettings", "PickingListSettings");
|
|
|
|
|
|
- ConvertColumnsTag(provider, nameof(Requisition), nameof(PickingList));
|
|
|
- ConvertColumnsTag(provider, nameof(RequisitionItem), nameof(PickingListItem));
|
|
|
- ConvertColumnsTag(provider, nameof(RequisitionDestination), nameof(PickingListDestination));
|
|
|
- ConvertColumnsTag(provider, nameof(RequisitionDocument), nameof(PickingListDocument));
|
|
|
- ConvertColumnsTag(provider, nameof(RequisitionKanban), nameof(PickingListKanban));
|
|
|
-
|
|
|
ConvertColumnsTag(provider, "PickingList.DeliveryRequi", "PickingList.DeliveryPickingList");
|
|
|
ConvertColumnsTag(provider, "RequisitionItem.RequisitionItem_Logistics", "PickingListItem.PickingListItem_Logistics");
|
|
|
|