- 修复 pgsql varchar(120) CodeFirst 迁移不修改长度;

This commit is contained in:
2881099
2022-05-25 15:58:59 +08:00
parent 71ba136e08
commit 97975b5ab5
7 changed files with 173 additions and 8 deletions

View File

@ -229,7 +229,19 @@ where ns.nspname = {0} and c.relname = {1}", tboldname ?? tbname);
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
{
var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? "");
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false ||
var sqlTypeSize = tbstructcol.sqlType;
if (sqlTypeSize.Contains("(") == false)
{
switch (sqlTypeSize.ToLower())
{
case "bit":
case "varbit":
case "bpchar":
case "varchar":
sqlTypeSize = $"{sqlTypeSize}({tbstructcol.max_length})"; break;
}
}
if (tbcol.Attribute.DbType.StartsWith(sqlTypeSize, StringComparison.CurrentCultureIgnoreCase) == false ||
tbcol.Attribute.DbType.Contains("[]") != (tbstructcol.attndims > 0))
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TYPE ").Append(tbcol.Attribute.DbType.Split(' ').First()).Append(";\r\n");
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)

View File

@ -241,7 +241,19 @@ where ns.nspname = {0} and c.relname = {1}", tboldname ?? tbname);
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
{
var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? "");
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false ||
var sqlTypeSize = tbstructcol.sqlType;
if (sqlTypeSize.Contains("(") == false)
{
switch (sqlTypeSize.ToLower())
{
case "bit":
case "varbit":
case "bpchar":
case "varchar":
sqlTypeSize = $"{sqlTypeSize}({tbstructcol.max_length})"; break;
}
}
if (tbcol.Attribute.DbType.StartsWith(sqlTypeSize, StringComparison.CurrentCultureIgnoreCase) == false ||
tbcol.Attribute.DbType.Contains("[]") != (tbstructcol.attndims > 0))
sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TYPE ").Append(tbcol.Attribute.DbType.Split(' ').First()).Append(";\r\n");
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)