mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-08 21:02:27 +08:00
✨ feat(sync): 扩展跨库迁移自动建表能力
- 新增 MySQL、PG-like、ClickHouse、MongoDB 同类库迁移规划器 - 支持可映射库对自动建表、补字段及兼容索引迁移 - 修复 MongoDB 创建集合时建表 SQL 为空的执行判断 - 避免 PG-like 主键索引重复迁移并保留默认值表达式 - 更新 Data Sync 自动建表能力提示与回归测试 Refs #465
This commit is contained in:
@@ -9,6 +9,14 @@ import (
|
||||
|
||||
type genericLegacyPlanner struct{}
|
||||
|
||||
type mysqlToMySQLPlanner struct{}
|
||||
|
||||
type pgLikeToPGLikePlanner struct{}
|
||||
|
||||
type clickHouseToClickHousePlanner struct{}
|
||||
|
||||
type mongoToMongoPlanner struct{}
|
||||
|
||||
type mysqlToPGLikePlanner struct{}
|
||||
|
||||
type mysqlToClickHousePlanner struct{}
|
||||
@@ -55,6 +63,10 @@ func buildSchemaMigrationPlan(config SyncConfig, tableName string, sourceDB db.D
|
||||
|
||||
func resolveMigrationPlanner(ctx MigrationBuildContext) MigrationPlanner {
|
||||
planners := []MigrationPlanner{
|
||||
mysqlToMySQLPlanner{},
|
||||
pgLikeToPGLikePlanner{},
|
||||
clickHouseToClickHousePlanner{},
|
||||
mongoToMongoPlanner{},
|
||||
mysqlToPGLikePlanner{},
|
||||
mySQLLikeToTDenginePlanner{},
|
||||
pgLikeToTDenginePlanner{},
|
||||
@@ -133,6 +145,66 @@ func (genericLegacyPlanner) BuildPlan(ctx MigrationBuildContext) (SchemaMigratio
|
||||
return buildSchemaMigrationPlanLegacy(ctx.Config, ctx.TableName, ctx.SourceDB, ctx.TargetDB)
|
||||
}
|
||||
|
||||
func (mysqlToMySQLPlanner) Name() string { return "mysql-mysql-planner" }
|
||||
|
||||
func (mysqlToMySQLPlanner) SupportLevel(ctx MigrationBuildContext) MigrationSupportLevel {
|
||||
sourceType := resolveMigrationDBType(ctx.Config.SourceConfig)
|
||||
targetType := resolveMigrationDBType(ctx.Config.TargetConfig)
|
||||
if isMySQLRowStoreType(sourceType) && isMySQLRowStoreType(targetType) {
|
||||
return MigrationSupportLevelFull
|
||||
}
|
||||
return MigrationSupportLevelUnsupported
|
||||
}
|
||||
|
||||
func (mysqlToMySQLPlanner) BuildPlan(ctx MigrationBuildContext) (SchemaMigrationPlan, []connection.ColumnDefinition, []connection.ColumnDefinition, error) {
|
||||
return buildMySQLToMySQLPlan(ctx.Config, ctx.TableName, ctx.SourceDB, ctx.TargetDB)
|
||||
}
|
||||
|
||||
func (pgLikeToPGLikePlanner) Name() string { return "pglike-pglike-planner" }
|
||||
|
||||
func (pgLikeToPGLikePlanner) SupportLevel(ctx MigrationBuildContext) MigrationSupportLevel {
|
||||
sourceType := resolveMigrationDBType(ctx.Config.SourceConfig)
|
||||
targetType := resolveMigrationDBType(ctx.Config.TargetConfig)
|
||||
if isPGLikeSameFamilyDDLType(sourceType) && isPGLikeSameFamilyDDLType(targetType) {
|
||||
return MigrationSupportLevelFull
|
||||
}
|
||||
return MigrationSupportLevelUnsupported
|
||||
}
|
||||
|
||||
func (pgLikeToPGLikePlanner) BuildPlan(ctx MigrationBuildContext) (SchemaMigrationPlan, []connection.ColumnDefinition, []connection.ColumnDefinition, error) {
|
||||
return buildPGLikeToPGLikePlan(ctx.Config, ctx.TableName, ctx.SourceDB, ctx.TargetDB)
|
||||
}
|
||||
|
||||
func (clickHouseToClickHousePlanner) Name() string { return "clickhouse-clickhouse-planner" }
|
||||
|
||||
func (clickHouseToClickHousePlanner) SupportLevel(ctx MigrationBuildContext) MigrationSupportLevel {
|
||||
sourceType := resolveMigrationDBType(ctx.Config.SourceConfig)
|
||||
targetType := resolveMigrationDBType(ctx.Config.TargetConfig)
|
||||
if sourceType == "clickhouse" && targetType == "clickhouse" {
|
||||
return MigrationSupportLevelFull
|
||||
}
|
||||
return MigrationSupportLevelUnsupported
|
||||
}
|
||||
|
||||
func (clickHouseToClickHousePlanner) BuildPlan(ctx MigrationBuildContext) (SchemaMigrationPlan, []connection.ColumnDefinition, []connection.ColumnDefinition, error) {
|
||||
return buildClickHouseToClickHousePlan(ctx.Config, ctx.TableName, ctx.SourceDB, ctx.TargetDB)
|
||||
}
|
||||
|
||||
func (mongoToMongoPlanner) Name() string { return "mongo-mongo-planner" }
|
||||
|
||||
func (mongoToMongoPlanner) SupportLevel(ctx MigrationBuildContext) MigrationSupportLevel {
|
||||
sourceType := resolveMigrationDBType(ctx.Config.SourceConfig)
|
||||
targetType := resolveMigrationDBType(ctx.Config.TargetConfig)
|
||||
if sourceType == "mongodb" && targetType == "mongodb" {
|
||||
return MigrationSupportLevelFull
|
||||
}
|
||||
return MigrationSupportLevelUnsupported
|
||||
}
|
||||
|
||||
func (mongoToMongoPlanner) BuildPlan(ctx MigrationBuildContext) (SchemaMigrationPlan, []connection.ColumnDefinition, []connection.ColumnDefinition, error) {
|
||||
return buildMongoToMongoPlan(ctx.Config, ctx.TableName, ctx.SourceDB, ctx.TargetDB)
|
||||
}
|
||||
|
||||
func (mysqlToPGLikePlanner) Name() string { return "mysql-pglike-planner" }
|
||||
|
||||
func (mysqlToPGLikePlanner) SupportLevel(ctx MigrationBuildContext) MigrationSupportLevel {
|
||||
|
||||
Reference in New Issue
Block a user