mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-12 03:59:41 +08:00
- 统一同库同步与跨库迁移入口,补充模式区分与风险提示 - 扩展 ClickHouse 与 PG-like 双向迁移,并新增 PG-like、ClickHouse、TDengine 到 MongoDB 的迁移路由 - 完善 TDengine 目标端建表规划、回归测试与需求追踪文档 - refs #51
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package sync
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type SchemaInferenceStrategy string
|
|
|
|
const (
|
|
SchemaInferenceStrategySample SchemaInferenceStrategy = "sample"
|
|
SchemaInferenceStrategyStrict SchemaInferenceStrategy = "strict"
|
|
)
|
|
|
|
func shouldUseSchemaInference(sourceType string, targetType string) bool {
|
|
sourceModel := classifyMigrationDataModel(sourceType)
|
|
targetModel := classifyMigrationDataModel(targetType)
|
|
return sourceModel == MigrationDataModelDocument && targetModel == MigrationDataModelRelational
|
|
}
|
|
|
|
func inferMigrationObjectKind(sourceType string, targetType string) MigrationObjectKind {
|
|
sourceModel := classifyMigrationDataModel(sourceType)
|
|
targetModel := classifyMigrationDataModel(targetType)
|
|
switch {
|
|
case sourceModel == MigrationDataModelDocument || targetModel == MigrationDataModelDocument:
|
|
return MigrationObjectKindCollection
|
|
case sourceModel == MigrationDataModelKeyValue || targetModel == MigrationDataModelKeyValue:
|
|
return MigrationObjectKindKeyspace
|
|
default:
|
|
return MigrationObjectKindTable
|
|
}
|
|
}
|
|
|
|
func inferSchemaForPair(sourceType string, targetType string, objectName string) (SchemaInferenceResult, error) {
|
|
if !shouldUseSchemaInference(sourceType, targetType) {
|
|
return SchemaInferenceResult{}, fmt.Errorf("当前迁移对 %s -> %s 不需要 schema 推断", sourceType, targetType)
|
|
}
|
|
return SchemaInferenceResult{
|
|
Object: CanonicalObjectSpec{
|
|
Name: strings.TrimSpace(objectName),
|
|
Kind: MigrationObjectKindCollection,
|
|
Fields: []CanonicalFieldSpec{},
|
|
},
|
|
Issues: []SchemaInferenceIssue{
|
|
{
|
|
Level: "info",
|
|
Message: "MongoDB -> 关系型数据库的 schema 推断能力尚在建设中,当前仅提供内核入口。",
|
|
Resolution: "后续将基于样本数据生成列定义与类型降级策略。",
|
|
},
|
|
},
|
|
NeedsReview: true,
|
|
}, nil
|
|
}
|