- 增加 ICodeFirst.SyncStructure(TableInfo) 重载方法迁移表结构;

This commit is contained in:
2881099 2023-11-24 22:39:27 +08:00
parent 2ed254d496
commit aad91e2172
29 changed files with 151 additions and 138 deletions

View File

@ -62,6 +62,7 @@ namespace FreeSql
/// <param name="tableName">指定表名对比</param>
/// <returns></returns>
string GetComparisonDDLStatements(Type entityType, string tableName);
string GetComparisonDDLStatements(TableInfo tableSchema, string tableName);
/// <summary>
/// 同步实体类型到数据库<para></para>
/// 注意:生产环境中谨慎使用
@ -82,6 +83,7 @@ namespace FreeSql
/// <param name="tableName">指定表名对比</param>
/// <param name="isForceSync">强制同步结构,无视缓存每次都同步</param>
void SyncStructure(Type entityType, string tableName, bool isForceSync = false);
void SyncStructure(TableInfo tableSchema, string tableName, bool isForceSync = false);
/// <summary>
/// 根据 System.Type 获取数据库信息

View File

@ -50,19 +50,21 @@ namespace FreeSql.Internal.CommonProvider
return tableName;
}
public string GetComparisonDDLStatements<TEntity>() =>
this.GetComparisonDDLStatements(new TypeAndName(typeof(TEntity), ""));
this.GetComparisonDDLStatements(new TypeSchemaAndName(GetTableByEntity(typeof(TEntity)), ""));
public string GetComparisonDDLStatements(params Type[] entityTypes) => entityTypes == null ? null :
this.GetComparisonDDLStatements(entityTypes.Distinct().Select(a => new TypeAndName(a, "")).ToArray());
this.GetComparisonDDLStatements(entityTypes.Distinct().Select(a => new TypeSchemaAndName(GetTableByEntity(a), "")).ToArray());
public string GetComparisonDDLStatements(Type entityType, string tableName) =>
this.GetComparisonDDLStatements(new TypeAndName(entityType, GetTableNameLowerOrUpper(tableName)));
protected abstract string GetComparisonDDLStatements(params TypeAndName[] objects);
public class TypeAndName
this.GetComparisonDDLStatements(new TypeSchemaAndName(GetTableByEntity(entityType), GetTableNameLowerOrUpper(tableName)));
public string GetComparisonDDLStatements(TableInfo tableSchema, string tableName) =>
this.GetComparisonDDLStatements(new TypeSchemaAndName(tableSchema, GetTableNameLowerOrUpper(tableName)));
protected abstract string GetComparisonDDLStatements(params TypeSchemaAndName[] objects);
public class TypeSchemaAndName
{
public Type entityType { get; }
public TableInfo tableSchema { get; }
public string tableName { get; }
public TypeAndName(Type entityType, string tableName)
public TypeSchemaAndName(TableInfo tableSchema, string tableName)
{
this.entityType = entityType;
this.tableSchema = tableSchema;
this.tableName = tableName;
}
}
@ -82,24 +84,33 @@ namespace FreeSql.Internal.CommonProvider
_dicSycedGetOrAdd(entityType).TryAdd(GetTableNameLowerOrUpper(tableName), true);
public void SyncStructure<TEntity>() =>
this.SyncStructure(new TypeAndName(typeof(TEntity), ""));
this.SyncStructure(new TypeSchemaAndName(GetTableByEntity(typeof(TEntity)), ""));
public void SyncStructure(params Type[] entityTypes) =>
this.SyncStructure(entityTypes?.Distinct().Select(a => new TypeAndName(a, "")).ToArray());
public void SyncStructure(Type entityType, string tableName, bool isForceSync)
this.SyncStructure(entityTypes?.Distinct().Select(a => new TypeSchemaAndName(GetTableByEntity(a), "")).ToArray());
public void SyncStructure(Type entityType, string tableName, bool isForceSync) =>
this.SyncStructure(GetTableByEntity(entityType), tableName, isForceSync);
public void SyncStructure(TableInfo tableSchema, string tableName, bool isForceSync = false)
{
tableName = GetTableNameLowerOrUpper(tableName);
if (isForceSync && _dicSynced.TryGetValue(entityType, out var dic)) dic.TryRemove(tableName, out var old);
this.SyncStructure(new TypeAndName(entityType, tableName));
if (isForceSync && tableSchema?.Type != null && _dicSynced.TryGetValue(tableSchema.Type, out var dic)) dic.TryRemove(tableName, out var old);
this.SyncStructure(new TypeSchemaAndName(tableSchema, tableName));
}
protected void SyncStructure(params TypeAndName[] objects)
protected void SyncStructure(params TypeSchemaAndName[] objects)
{
if (objects == null) return;
var syncObjects = objects.Where(a => a.entityType != null && a.entityType != typeof(object) && _dicSycedGetOrAdd(a.entityType).ContainsKey(GetTableNameLowerOrUpper(a.tableName)) == false && GetTableByEntity(a.entityType)?.DisableSyncStructure == false)
.Select(a => new TypeAndName(a.entityType, GetTableNameLowerOrUpper(a.tableName)))
.Where(a => !(string.IsNullOrEmpty(a.tableName) == true && GetTableByEntity(a.entityType)?.AsTableImpl != null))
var syncObjects = objects.Where(a => a.tableSchema?.Type != null &&
(
a.tableSchema.Type.Name == "DynamicRepository" && a.tableSchema.Columns.Any()
||
a.tableSchema.Type != typeof(object) && _dicSycedGetOrAdd(a.tableSchema.Type).ContainsKey(GetTableNameLowerOrUpper(a.tableName)) == false
) &&
a.tableSchema?.DisableSyncStructure == false)
.Select(a => new TypeSchemaAndName(a.tableSchema, GetTableNameLowerOrUpper(a.tableName)))
.Where(a => !(string.IsNullOrEmpty(a.tableName) == true && a.tableSchema?.AsTableImpl != null))
.ToArray();
if (syncObjects.Any() == false) return;
var before = new Aop.SyncStructureBeforeEventArgs(syncObjects.Select(a => a.entityType).ToArray());
var before = new Aop.SyncStructureBeforeEventArgs(syncObjects.Select(a => a.tableSchema.Type).ToArray());
_orm.Aop.SyncStructureBeforeHandler?.Invoke(this, before);
Exception exception = null;
string ddl = null;
@ -110,11 +121,11 @@ namespace FreeSql.Internal.CommonProvider
ddl = this.GetComparisonDDLStatements(syncObjects);
if (string.IsNullOrEmpty(ddl))
{
foreach (var syncObject in syncObjects) _dicSycedTryAdd(syncObject.entityType, syncObject.tableName);
foreach (var syncObject in syncObjects) _dicSycedTryAdd(syncObject.tableSchema.Type, syncObject.tableName);
return;
}
var affrows = ExecuteDDLStatements(ddl);
foreach (var syncObject in syncObjects) _dicSycedTryAdd(syncObject.entityType, syncObject.tableName);
foreach (var syncObject in syncObjects) _dicSycedTryAdd(syncObject.tableSchema.Type, syncObject.tableName);
return;
}
}

View File

@ -85,7 +85,7 @@ namespace FreeSql.ClickHouse
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
Object<DbConnection> conn = null;
string database = null;
@ -100,11 +100,11 @@ namespace FreeSql.ClickHouse
{
if (sb.Length > 0)
sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
var tb = obj.tableSchema;
if (tb == null)
throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false)
throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1)
tbname = new[] { database, tbname[0] };

View File

@ -90,6 +90,6 @@ namespace FreeSql.Custom
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects) => throw new NotImplementedException($"FreeSql.Provider.Custom {CoreStrings.S_Not_Implemented_Feature}");
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects) => throw new NotImplementedException($"FreeSql.Provider.Custom {CoreStrings.S_Not_Implemented_Feature}");
}
}

View File

@ -74,7 +74,7 @@ namespace FreeSql.Custom.MySql
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
Object<DbConnection> conn = null;
string database = null;
@ -88,9 +88,9 @@ namespace FreeSql.Custom.MySql
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { database, tbname[0] };

View File

@ -74,7 +74,7 @@ namespace FreeSql.Custom.Oracle
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var userId = (_orm.Ado as CustomOracleAdo)?.UserId;
if (string.IsNullOrEmpty(userId))
@ -90,15 +90,15 @@ namespace FreeSql.Custom.Oracle
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { userId, tbname[0] };
var tboldname = _commonUtils.SplitTableName(tb.DbOldName); //旧表名
if (tboldname?.Length == 1) tboldname = new[] { userId, tboldname[0] };
var primaryKeyName = (obj.entityType.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
var primaryKeyName = (obj.tableSchema.Type.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
if (string.IsNullOrEmpty(obj.tableName) == false)
{
var tbtmpname = _commonUtils.SplitTableName(obj.tableName);

View File

@ -79,7 +79,7 @@ namespace FreeSql.Custom.PostgreSQL
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var sb = new StringBuilder();
var seqcols = new List<NativeTuple<ColumnInfo, string[], bool>>(); //序列
@ -96,9 +96,9 @@ namespace FreeSql.Custom.PostgreSQL
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { "public", tbname[0] };

View File

@ -134,7 +134,7 @@ ELSE
, @level2type = 'COLUMN', @level2name = N'{2}'
", schema.Replace("'", "''"), table.Replace("'", "''"), column.Replace("'", "''"), comment?.Replace("'", "''") ?? "");
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
Object<DbConnection> conn = null;
string database = null;
@ -148,9 +148,9 @@ ELSE
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { database, "dbo", tbname[0] };
if (tbname?.Length == 2) tbname = new[] { database, tbname[0], tbname[1] };

View File

@ -75,7 +75,7 @@ namespace FreeSql.Dameng
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var userId = (_orm.Ado.MasterPool as DamengConnectionPool)?.UserId;
if (string.IsNullOrEmpty(userId))
@ -91,15 +91,15 @@ namespace FreeSql.Dameng
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { userId, tbname[0] };
var tboldname = _commonUtils.SplitTableName(tb.DbOldName); //旧表名
if (tboldname?.Length == 1) tboldname = new[] { userId, tboldname[0] };
var primaryKeyName = (obj.entityType.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
var primaryKeyName = (obj.tableSchema.Type.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
if (string.IsNullOrEmpty(obj.tableName) == false)
{
var tbtmpname = _commonUtils.SplitTableName(obj.tableName);

View File

@ -81,16 +81,16 @@ namespace FreeSql.Firebird
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var sb = new StringBuilder();
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = tb.DbName;
var tboldname = tb.DbOldName; //旧表名
if (string.IsNullOrEmpty(obj.tableName) == false)

View File

@ -77,7 +77,7 @@ namespace FreeSql.GBase
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
Object<DbConnection> conn = null;
string database = null;
@ -91,9 +91,9 @@ namespace FreeSql.GBase
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { database, tbname[0] };

View File

@ -98,7 +98,7 @@ namespace FreeSql.KingbaseES
}
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
InitIsSysV8R3();
var pg_ = _isSysV8R3 == true ? "sys_" : "pg_";
@ -109,9 +109,9 @@ namespace FreeSql.KingbaseES
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { public_, tbname[0] };

View File

@ -72,16 +72,16 @@ namespace FreeSql.MsAccess
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var sb = new StringBuilder();
var sbDeclare = new StringBuilder();
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = tb.DbName;
var tboldname = tb.DbOldName; //旧表名
if (string.Compare(tbname, tboldname, true) == 0) tboldname = null;

View File

@ -86,7 +86,7 @@ namespace FreeSql.MySql
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
Object<DbConnection> conn = null;
string database = null;
@ -100,9 +100,9 @@ namespace FreeSql.MySql
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { database, tbname[0] };

View File

@ -76,7 +76,7 @@ namespace FreeSql.Odbc.Dameng
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var userId = (_orm.Ado.MasterPool as OdbcDamengConnectionPool)?.UserId;
if (string.IsNullOrEmpty(userId))
@ -92,15 +92,15 @@ namespace FreeSql.Odbc.Dameng
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { userId, tbname[0] };
var tboldname = _commonUtils.SplitTableName(tb.DbOldName); //旧表名
if (tboldname?.Length == 1) tboldname = new[] { userId, tboldname[0] };
var primaryKeyName = (obj.entityType.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
var primaryKeyName = (obj.tableSchema.Type.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
if (string.IsNullOrEmpty(obj.tableName) == false)
{
var tbtmpname = _commonUtils.SplitTableName(obj.tableName);

View File

@ -90,6 +90,6 @@ namespace FreeSql.Odbc.Default
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects) => throw new NotImplementedException($"FreeSql.Odbc.Default {CoreStrings.S_Not_Implemented_Feature}");
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects) => throw new NotImplementedException($"FreeSql.Odbc.Default {CoreStrings.S_Not_Implemented_Feature}");
}
}

View File

@ -102,7 +102,7 @@ namespace FreeSql.Odbc.KingbaseES
}
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
InitIsSysV8R3();
var pg_ = _isSysV8R3 == true ? "sys_" : "pg_";
@ -113,9 +113,9 @@ namespace FreeSql.Odbc.KingbaseES
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { public_, tbname[0] };

View File

@ -75,7 +75,7 @@ namespace FreeSql.Odbc.MySql
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
Object<DbConnection> conn = null;
string database = null;
@ -89,9 +89,9 @@ namespace FreeSql.Odbc.MySql
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { database, tbname[0] };

View File

@ -76,7 +76,7 @@ namespace FreeSql.Odbc.Oracle
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var userId = (_orm.Ado.MasterPool as OdbcOracleConnectionPool)?.UserId;
if (string.IsNullOrEmpty(userId))
@ -92,15 +92,15 @@ namespace FreeSql.Odbc.Oracle
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { userId, tbname[0] };
var tboldname = _commonUtils.SplitTableName(tb.DbOldName); //旧表名
if (tboldname?.Length == 1) tboldname = new[] { userId, tboldname[0] };
var primaryKeyName = (obj.entityType.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
var primaryKeyName = (obj.tableSchema.Type.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
if (string.IsNullOrEmpty(obj.tableName) == false)
{
var tbtmpname = _commonUtils.SplitTableName(obj.tableName);

View File

@ -80,7 +80,7 @@ namespace FreeSql.Odbc.PostgreSQL
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var sb = new StringBuilder();
var seqcols = new List<NativeTuple<ColumnInfo, string[], bool>>(); //序列
@ -97,9 +97,9 @@ namespace FreeSql.Odbc.PostgreSQL
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { "public", tbname[0] };

View File

@ -135,7 +135,7 @@ ELSE
, @level2type = 'COLUMN', @level2name = N'{2}'
", schema.Replace("'", "''"), table.Replace("'", "''"), column.Replace("'", "''"), comment?.Replace("'", "''") ?? "");
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
Object<DbConnection> conn = null;
string database = null;
@ -149,9 +149,9 @@ ELSE
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { database, "dbo", tbname[0] };
if (tbname?.Length == 2) tbname = new[] { database, tbname[0], tbname[1] };

View File

@ -111,7 +111,7 @@ namespace FreeSql.Oracle
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var userId = (_orm.Ado.MasterPool as OracleConnectionPool)?.UserId;
if (string.IsNullOrEmpty(userId))
@ -127,15 +127,15 @@ namespace FreeSql.Oracle
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { userId, tbname[0] };
var tboldname = _commonUtils.SplitTableName(tb.DbOldName); //旧表名
if (tboldname?.Length == 1) tboldname = new[] { userId, tboldname[0] };
var primaryKeyName = (obj.entityType.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
var primaryKeyName = (obj.tableSchema.Type.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name;
if (string.IsNullOrEmpty(obj.tableName) == false)
{
var tbtmpname = _commonUtils.SplitTableName(obj.tableName);

View File

@ -130,7 +130,7 @@ namespace FreeSql.PostgreSQL
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var sb = new StringBuilder();
var seqcols = new List<NativeTuple<ColumnInfo, string[], bool>>(); //序列
@ -147,9 +147,9 @@ namespace FreeSql.PostgreSQL
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { "public", tbname[0] };

View File

@ -79,7 +79,7 @@ namespace FreeSql.QuestDb
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var sb = new StringBuilder();
var seqcols = new List<NativeTuple<ColumnInfo, string[], bool>>(); //序列
@ -87,10 +87,10 @@ namespace FreeSql.QuestDb
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false)
throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = tb.DbName;
var tboldname = tb.DbOldName;
if (string.IsNullOrEmpty(obj.tableName) == false)
@ -147,7 +147,7 @@ namespace FreeSql.QuestDb
sbalter.Remove(sbalter.Length - 1, 1);
//是否存在分表
foreach (var propety in obj.entityType.GetProperties())
foreach (var propety in obj.tableSchema.Type.GetProperties())
{
var timeAttr = propety.GetCustomAttribute<AutoSubtableAttribute>();
if (timeAttr != null)

View File

@ -86,7 +86,7 @@ namespace FreeSql.ShenTong
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var sb = new StringBuilder();
var seqcols = new List<NativeTuple<ColumnInfo, string[], bool>>(); //序列
@ -94,9 +94,9 @@ namespace FreeSql.ShenTong
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { "PUBLIC", tbname[0] };

View File

@ -137,7 +137,7 @@ ELSE
, @level2type = 'COLUMN', @level2name = N'{2}'
", schema.Replace("'", "''"), table.Replace("'", "''"), column.Replace("'", "''"), comment?.Replace("'", "''") ?? "");
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
Object<DbConnection> conn = null;
string database = null;
@ -151,9 +151,9 @@ ELSE
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { database, "dbo", tbname[0] };
if (tbname?.Length == 2) tbname = new[] { database, tbname[0], tbname[1] };

View File

@ -71,16 +71,16 @@ namespace FreeSql.Sqlite
return null;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var sb = new StringBuilder();
var sbDeclare = new StringBuilder();
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { "main", tbname[0] };

View File

@ -129,7 +129,7 @@ namespace FreeSql.Xugu
sqlType += $"({data_length})";
return sqlType;
}
protected override string GetComparisonDDLStatements(params TypeAndName[] objects)
protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects)
{
var sb = new StringBuilder();
var seqcols = new List<NativeTuple<ColumnInfo, string[], bool>>(); //序列
@ -137,9 +137,9 @@ namespace FreeSql.Xugu
foreach (var obj in objects)
{
if (sb.Length > 0) sb.Append("\r\n");
var tb = _commonUtils.GetTableByEntity(obj.entityType);
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.entityType.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.entityType.FullName));
var tb = obj.tableSchema;
if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName));
if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName));
var tbname = _commonUtils.SplitTableName(tb.DbName);
if (tbname?.Length == 1) tbname = new[] { DefaultSchema, tbname[0] };

View File

@ -384,7 +384,7 @@ where IS_SYS=false and {loc8.ToString().Replace("a.table_name", "ns.SCHEMA_NAME
var index_id = string.Concat(row[2]);
var is_unique = string.Concat(row[3]) == "1";
var is_primary_key = string.Concat(row[4]) == "1";
var is_clustered = false;//= string.Concat(row[5]) == "1";
//var is_clustered = false;//= string.Concat(row[5]) == "1";
var is_desc = false;//string.Concat(row[6]) == "1";
//var inkey = string.Concat(row[7]).Split(' ');
//var attnum = int.Parse(string.Concat(row[8]));