mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-08-03 10:07:59 +08:00
- 优化 CodeFirst 字段变化对比逻辑
This commit is contained in:
@ -229,6 +229,7 @@ where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname);
|
||||
if (istmpatler && Regex.IsMatch(tbcol.Attribute.DbType, @"\(\d+") == false && Regex.IsMatch(tbstructcol.sqlType, @"\(\d+")
|
||||
&& string.Compare(tbcol.Attribute.DbType, Regex.Replace(tbstructcol.sqlType, @"\([^\)]+\)", ""), StringComparison.CurrentCultureIgnoreCase) == 0)
|
||||
istmpatler = false;
|
||||
if (istmpatler) break;
|
||||
}
|
||||
//sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY (").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n");
|
||||
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
|
||||
@ -262,7 +263,9 @@ where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname);
|
||||
if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NaviteTuple.Create(tbcol, tbname, tbcol.Attribute.IsIdentity == true));
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n");
|
||||
}
|
||||
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
var dsuksql = _commonUtils.FormatSql(@"
|
||||
select
|
||||
c.column_name,
|
||||
|
@ -353,9 +353,10 @@ namespace FreeSql.MsAccess
|
||||
{
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
if (istmpatler) break;
|
||||
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"NOT\s+NULL", "NULL");
|
||||
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
|
||||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||
{
|
||||
if (tbstructcol.sqlType != "LONG" && tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
|
||||
istmpatler = true;
|
||||
@ -371,6 +372,9 @@ namespace FreeSql.MsAccess
|
||||
//添加列
|
||||
istmpatler = true;
|
||||
}
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
var dsuk = getIndexesByTableName(tbtmp);
|
||||
foreach (var uk in tb.Indexes)
|
||||
{
|
||||
|
@ -229,6 +229,7 @@ where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname);
|
||||
if (istmpatler && Regex.IsMatch(tbcol.Attribute.DbType, @"\(\d+") == false && Regex.IsMatch(tbstructcol.sqlType, @"\(\d+")
|
||||
&& string.Compare(tbcol.Attribute.DbType, Regex.Replace(tbstructcol.sqlType, @"\([^\)]+\)", ""), StringComparison.CurrentCultureIgnoreCase) == 0)
|
||||
istmpatler = false;
|
||||
if (istmpatler) break;
|
||||
}
|
||||
//sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY (").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n");
|
||||
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
|
||||
@ -262,7 +263,9 @@ where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname);
|
||||
if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NaviteTuple.Create(tbcol, tbname, tbcol.Attribute.IsIdentity == true));
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n");
|
||||
}
|
||||
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
var dsuksql = _commonUtils.FormatSql(@"
|
||||
select
|
||||
c.column_name,
|
||||
|
@ -226,6 +226,7 @@ where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname);
|
||||
if (tbcol.Attribute.DbType.StartsWith("varchar", StringComparison.CurrentCultureIgnoreCase) && tbstructcol.sqlType.StartsWith("varchar2", StringComparison.CurrentCultureIgnoreCase)
|
||||
&& Regex.Match(tbcol.Attribute.DbType, @"\(\d+").Groups[0].Value == Regex.Match(tbstructcol.sqlType, @"\(\d+").Groups[0].Value)
|
||||
istmpatler = false;
|
||||
if (istmpatler) break;
|
||||
}
|
||||
//sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY (").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n");
|
||||
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
|
||||
@ -259,7 +260,9 @@ where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname);
|
||||
if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NaviteTuple.Create(tbcol, tbname, tbcol.Attribute.IsIdentity == true));
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n");
|
||||
}
|
||||
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
CreateOracleFunction(_orm);
|
||||
var dsuksql = _commonUtils.FormatSql(@"
|
||||
select
|
||||
|
@ -323,6 +323,9 @@ use [" + database + "];", tboldname ?? tbname);
|
||||
sbalter.Append(";\r\n");
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) AddOrUpdateMS_Description(sbalter, tbname[1], tbname[2], tbcol.Attribute.Name, tbcol.Comment);
|
||||
}
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
var dsuksql = string.Format(@"
|
||||
use [{0}];
|
||||
select
|
||||
|
@ -227,6 +227,7 @@ where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname);
|
||||
if (tbcol.Attribute.DbType.StartsWith("varchar", StringComparison.CurrentCultureIgnoreCase) && tbstructcol.sqlType.StartsWith("varchar2", StringComparison.CurrentCultureIgnoreCase)
|
||||
&& Regex.Match(tbcol.Attribute.DbType, @"\(\d+").Groups[0].Value == Regex.Match(tbstructcol.sqlType, @"\(\d+").Groups[0].Value)
|
||||
istmpatler = false;
|
||||
if (istmpatler) break;
|
||||
}
|
||||
//sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY (").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n");
|
||||
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
|
||||
@ -260,7 +261,9 @@ where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname);
|
||||
if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NaviteTuple.Create(tbcol, tbname, tbcol.Attribute.IsIdentity == true));
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n");
|
||||
}
|
||||
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
CreateOracleFunction(_orm);
|
||||
var dsuksql = _commonUtils.FormatSql(@"
|
||||
select
|
||||
|
@ -322,6 +322,9 @@ use [" + database + "];", tboldname ?? tbname);
|
||||
sbalter.Append(";\r\n");
|
||||
if (string.IsNullOrEmpty(tbcol.Comment) == false) AddOrUpdateMS_Description(sbalter, tbname[1], tbname[2], tbcol.Attribute.Name, tbcol.Comment);
|
||||
}
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
var dsuksql = string.Format(@"
|
||||
use [{0}];
|
||||
select
|
||||
|
@ -184,9 +184,10 @@ namespace FreeSql.Sqlite
|
||||
{
|
||||
foreach (var tbcol in tb.ColumnsByPosition)
|
||||
{
|
||||
if (istmpatler) break;
|
||||
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"NOT\s+NULL", "NULL");
|
||||
if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) ||
|
||||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||
string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol))
|
||||
{
|
||||
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
|
||||
istmpatler = true;
|
||||
@ -202,6 +203,9 @@ namespace FreeSql.Sqlite
|
||||
//添加列
|
||||
istmpatler = true;
|
||||
}
|
||||
}
|
||||
if (istmpatler == false)
|
||||
{
|
||||
var dsuk = new List<string[]>();
|
||||
var dbIndexes = _orm.Ado.ExecuteArray(CommandType.Text, $"PRAGMA {_commonUtils.QuoteSqlName(tbtmp[0])}.INDEX_LIST(\"{tbtmp[1]}\")");
|
||||
foreach (var dbIndex in dbIndexes)
|
||||
|
Reference in New Issue
Block a user