Documentation
¶
Index ¶
- func GetMockTypeMapping(sourceType string) string
- func ParseTypeWithParams(fullType string) (string, []string)
- func SplitWithBalance(s string, sep rune) []string
- type AnalysisResult
- type CompatibilityIssue
- type Condition
- type ContextMappingRule
- type ConverterFactory
- type FloatPolicy
- type IntelligentTypeMapper
- type MappingRuleLoader
- type MappingRules
- type MySQLConverter
- func (c *MySQLConverter) ConvertDDL(sourceDDL string, targetDB string) (string, error)
- func (c *MySQLConverter) ConvertTable(sourceTable *models.TableSchema, targetDB string) (*models.TableSchema, error)
- func (c *MySQLConverter) GenerateWarningReport(format string) (string, error)
- func (c *MySQLConverter) GetTypeMapping(sourceType string, targetDB string) (string, error)
- type PostgresConverter
- func (c *PostgresConverter) ConvertDDL(sourceDDL string, targetDB string) (string, error)
- func (c *PostgresConverter) ConvertTable(sourceTable *models.TableSchema, targetDB string) (*models.TableSchema, error)
- func (c *PostgresConverter) GetTypeMapping(sourceType string, targetDB string) (string, error)
- type PrecisionHandler
- type PrecisionPolicy
- type PrecisionResult
- type SchemaConverter
- type TableContext
- type TiDBConverter
- type TypeAnalyzer
- type TypeMapping
- type TypeMappingContext
- type TypeMappingResult
- type TypeWarning
- type WarningCollector
- type WarningStatistics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMockTypeMapping ¶
GetMockTypeMapping returns a passthrough mapping for testing.
func ParseTypeWithParams ¶
ParseTypeWithParams parses a type string into base type and parameters. e.g. "DECIMAL(10, 2)" -> "DECIMAL", ["10", "2"]
func SplitWithBalance ¶
SplitWithBalance splits a string by a separator, respecting parenthesis balance.
Types ¶
type AnalysisResult ¶
type AnalysisResult struct {
IsCompatible bool
Warnings []TypeWarning
Suggestions []string
RiskLevel string // "LOW", "MEDIUM", "HIGH"
}
AnalysisResult holds the result of type compatibility analysis.
type CompatibilityIssue ¶
type CompatibilityIssue struct {
SourcePattern string
TargetType string
IssueType string // "OVERFLOW", "PRECISION_LOSS", "DATA_LOSS"
Description string
Mitigation string
}
CompatibilityIssue describes a known compatibility issue.
type ContextMappingRule ¶
type ConverterFactory ¶
type ConverterFactory struct {
// contains filtered or unexported fields
}
ConverterFactory creates and manages SchemaConverters.
func NewConverterFactory ¶
func NewConverterFactory() *ConverterFactory
NewConverterFactory creates a new ConverterFactory with registered converters.
func (*ConverterFactory) GetConverter ¶
func (f *ConverterFactory) GetConverter(sourceDB string) (SchemaConverter, error)
GetConverter returns the converter for the specified source database.
type FloatPolicy ¶
type IntelligentTypeMapper ¶
type IntelligentTypeMapper struct {
// contains filtered or unexported fields
}
IntelligentTypeMapper implements context-aware type mapping.
func NewIntelligentTypeMapper ¶
func NewIntelligentTypeMapper( ruleLoader *MappingRuleLoader, analyzer *TypeAnalyzer, precision *PrecisionHandler, ) *IntelligentTypeMapper
NewIntelligentTypeMapper creates a new IntelligentTypeMapper.
func (*IntelligentTypeMapper) MapType ¶
func (m *IntelligentTypeMapper) MapType(ctx *TypeMappingContext) (*TypeMappingResult, error)
MapType performs intelligent type mapping.
type MappingRuleLoader ¶
type MappingRuleLoader struct {
// contains filtered or unexported fields
}
MappingRuleLoader loads and manages mapping rules.
func NewMappingRuleLoader ¶
func NewMappingRuleLoader(rulesPath string) (*MappingRuleLoader, error)
NewMappingRuleLoader creates a new loader.
func (*MappingRuleLoader) GetRules ¶
func (l *MappingRuleLoader) GetRules() *MappingRules
GetRules returns the current rules.
func (*MappingRuleLoader) Load ¶
func (l *MappingRuleLoader) Load() error
Load loads the rules from file.
func (*MappingRuleLoader) MatchContextRules ¶
func (l *MappingRuleLoader) MatchContextRules(ctx *TypeMappingContext) string
MatchContextRules finds the best matching rule for the context.
func (*MappingRuleLoader) Subscribe ¶
func (l *MappingRuleLoader) Subscribe() <-chan bool
Subscribe returns a channel for updates.
type MappingRules ¶
type MappingRules struct {
Version string `yaml:"version"`
UpdatedAt time.Time `yaml:"updated_at"`
DefaultRules map[string]map[string]string `yaml:"default_rules"`
CustomRules map[string]map[string]string `yaml:"custom_rules"`
ContextRules []ContextMappingRule `yaml:"context_rules"`
}
MappingRules defines the structure of the rules file.
type MySQLConverter ¶
type MySQLConverter struct {
// contains filtered or unexported fields
}
MySQLConverter implements SchemaConverter for MySQL.
func NewMySQLConverter ¶
func NewMySQLConverter() *MySQLConverter
NewMySQLConverter creates a new MySQLConverter.
func NewMySQLConverterWithSource ¶
func NewMySQLConverterWithSource(sourceDB string) *MySQLConverter
NewMySQLConverterWithSource creates a new MySQLConverter with specific source DB.
func (*MySQLConverter) ConvertDDL ¶
func (c *MySQLConverter) ConvertDDL(sourceDDL string, targetDB string) (string, error)
ConvertDDL converts MySQL DDL to target DB format.
func (*MySQLConverter) ConvertTable ¶
func (c *MySQLConverter) ConvertTable(sourceTable *models.TableSchema, targetDB string) (*models.TableSchema, error)
ConvertTable converts a single table structure.
func (*MySQLConverter) GenerateWarningReport ¶
func (c *MySQLConverter) GenerateWarningReport(format string) (string, error)
GenerateWarningReport generates warnings.
func (*MySQLConverter) GetTypeMapping ¶
func (c *MySQLConverter) GetTypeMapping(sourceType string, targetDB string) (string, error)
GetTypeMapping gets the type mapping.
type PostgresConverter ¶
type PostgresConverter struct {
// contains filtered or unexported fields
}
PostgresConverter implements SchemaConverter for PostgreSQL.
func NewPostgresConverter ¶
func NewPostgresConverter() *PostgresConverter
NewPostgresConverter creates a new PostgresConverter.
func (*PostgresConverter) ConvertDDL ¶
func (c *PostgresConverter) ConvertDDL(sourceDDL string, targetDB string) (string, error)
ConvertDDL converts Postgres DDL to target DB format.
func (*PostgresConverter) ConvertTable ¶
func (c *PostgresConverter) ConvertTable(sourceTable *models.TableSchema, targetDB string) (*models.TableSchema, error)
ConvertTable converts a single table structure.
func (*PostgresConverter) GetTypeMapping ¶
func (c *PostgresConverter) GetTypeMapping(sourceType string, targetDB string) (string, error)
GetTypeMapping gets the type mapping.
type PrecisionHandler ¶
type PrecisionHandler struct {
// contains filtered or unexported fields
}
PrecisionHandler handles precision logic for types like DECIMAL and TIMESTAMP.
func NewPrecisionHandler ¶
func NewPrecisionHandler(policyPath string) *PrecisionHandler
NewPrecisionHandler creates a new PrecisionHandler.
func (*PrecisionHandler) HandlePrecision ¶
func (h *PrecisionHandler) HandlePrecision(baseType string, params []string, targetDB string) *PrecisionResult
HandlePrecision handles precision for a given type.
type PrecisionPolicy ¶
type PrecisionPolicy struct {
MaxPrecision int `yaml:"max_precision"`
MaxScale int `yaml:"max_scale"`
OverflowStrategy string `yaml:"overflow_strategy"` // "TRUNCATE"/"ERROR"/"WARN"
RoundingMode string `yaml:"rounding_mode"` // "ROUND_HALF_UP"/"FLOOR"/"CEIL"
}
PrecisionPolicy defines policy for handling precision.
type PrecisionResult ¶
type PrecisionResult struct {
TargetType string
HasLoss bool
Warnings []TypeWarning
Adjustments map[string]any
}
PrecisionResult holds the result of precision handling.
type SchemaConverter ¶
type SchemaConverter interface {
// ConvertDDL converts DDL statements to the target database format.
ConvertDDL(sourceDDL string, targetDB string) (string, error)
// ConvertTable converts a single table structure.
ConvertTable(sourceTable *models.TableSchema, targetDB string) (*models.TableSchema, error)
// GetTypeMapping gets the type mapping (source type -> target type).
GetTypeMapping(sourceType string, targetDB string) (string, error)
}
SchemaConverter defines the interface for converting schema DDLs between databases.
type TableContext ¶
TableContext holds table-level information.
type TiDBConverter ¶
type TiDBConverter struct {
// contains filtered or unexported fields
}
TiDBConverter implements SchemaConverter for TiDB. Since TiDB is MySQL compatible, it reuses MySQLConverter logic but handles TiDB specifics.
func NewTiDBConverter ¶
func NewTiDBConverter() *TiDBConverter
NewTiDBConverter creates a new TiDBConverter.
func (*TiDBConverter) ConvertDDL ¶
func (c *TiDBConverter) ConvertDDL(sourceDDL string, targetDB string) (string, error)
ConvertDDL converts TiDB DDL to target DB format.
func (*TiDBConverter) ConvertTable ¶
func (c *TiDBConverter) ConvertTable(sourceTable *models.TableSchema, targetDB string) (*models.TableSchema, error)
ConvertTable converts a single table structure.
func (*TiDBConverter) GetTypeMapping ¶
func (c *TiDBConverter) GetTypeMapping(sourceType string, targetDB string) (string, error)
GetTypeMapping gets the type mapping.
type TypeAnalyzer ¶
type TypeAnalyzer struct {
// contains filtered or unexported fields
}
TypeAnalyzer implements compatibility analysis.
func NewTypeAnalyzer ¶
func NewTypeAnalyzer() *TypeAnalyzer
NewTypeAnalyzer creates a new TypeAnalyzer.
func (*TypeAnalyzer) Analyze ¶
func (a *TypeAnalyzer) Analyze(sourceType, targetType string, ctx *TypeMappingContext) *AnalysisResult
Analyze performs compatibility analysis.
type TypeMapping ¶
TypeMapping defines the mapping from source types to target types.
type TypeMappingContext ¶
type TypeMappingContext struct {
SourceType string // e.g. "VARCHAR(255)"
SourceDB string // e.g. "mysql"
TargetDB string // e.g. "clickhouse"
ColumnName string // Column name for semantic analysis
IsPrimaryKey bool // Is this a primary key column?
IsIndexColumn bool // Is this an index column?
IsNullable bool // Is this column nullable?
DefaultValue string // Default value
TableContext *TableContext // Table level context
CustomRules map[string]string // Custom user rules
}
TypeMappingContext holds context information for intelligent type mapping.
type TypeMappingResult ¶
type TypeMappingResult struct {
TargetType string // e.g. "String"
Warnings []TypeWarning // Warnings generated during mapping
Suggestions []string // Optimization suggestions
PrecisionLoss bool // Indicates if precision loss occurred
RequiresManual bool // Indicates if manual review is required
Metadata map[string]any // Additional metadata (e.g., original precision)
}
TypeMappingResult holds the result of type mapping.
type TypeWarning ¶
type TypeWarning struct {
Level string // "INFO", "WARNING", "ERROR"
Message string
Suggestion string
AffectedColumn string
}
TypeWarning represents a warning during type conversion.
type WarningCollector ¶
type WarningCollector struct {
// contains filtered or unexported fields
}
WarningCollector collects and manages conversion warnings.
func NewWarningCollector ¶
func NewWarningCollector() *WarningCollector
NewWarningCollector creates a new WarningCollector.
func (*WarningCollector) Add ¶
func (c *WarningCollector) Add(warning TypeWarning)
Add adds a warning to the collector.
func (*WarningCollector) GenerateReport ¶
func (c *WarningCollector) GenerateReport(format string) (string, error)
GenerateReport generates a report in the specified format.