Update TableDifference

This commit is contained in:
sunkaixuan 2022-05-06 12:55:30 +08:00
parent fc6e5ef8ad
commit fbbc5fcd82

View File

@ -86,7 +86,7 @@ namespace SqlSugar
z.DecimalDigits != y.DecimalDigits
))).Select(it => new DiffColumsInfo()
{
Message=GetColumnString(it)
Message= GetUpdateColumnString(it, tableInfo.OldColumnInfos.FirstOrDefault(y => y.DbColumnName.EqualCase(it.DbColumnName)))
}).ToList();
return result;
}
@ -102,6 +102,40 @@ namespace SqlSugar
{
return $"{it.DbColumnName} {it.DataType} {it.Length} {it.Scale} default:{it.DefaultValue} description:{it.ColumnDescription} pk:{it.IsPrimarykey} nullable:{it.IsNullable} identity:{it.IsIdentity} ";
}
private static string GetUpdateColumnString(DbColumnInfo it,DbColumnInfo old)
{
var result= $"{it.DbColumnName} changes: ";
if (it.DataType != old.DataType)
{
result += $" [DataType:{old.DataType}->{it.DataType}] ";
}
if (it.Length != old.Length)
{
result += $" [Length:{old.Length}->{it.Length}] ";
}
if (it.Scale != old.Scale)
{
result += $" [Scale:{old.Scale}->{it.Scale}] ";
}
if (it.ColumnDescription != old.ColumnDescription)
{
result += $" [Description:{old.ColumnDescription}->{it.ColumnDescription}] ";
}
if (it.IsPrimarykey != old.IsPrimarykey)
{
result += $" [Pk:{old.IsPrimarykey}->{it.IsPrimarykey}] ";
}
if (it.IsNullable != old.IsNullable)
{
result += $" [Nullable:{old.IsNullable}->{it.IsNullable}] ";
}
if (it.IsIdentity != old.IsIdentity)
{
result += $" [Identity:{old.IsIdentity}->{it.IsIdentity}] ";
}
return result;
}
}
public class TableDifferenceInfo
{