schema

package
v0.0.0-...-b8497f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2025 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMockTypeMapping

func GetMockTypeMapping(sourceType string) string

GetMockTypeMapping returns a passthrough mapping for testing.

func ParseTypeWithParams

func ParseTypeWithParams(fullType string) (string, []string)

ParseTypeWithParams parses a type string into base type and parameters. e.g. "DECIMAL(10, 2)" -> "DECIMAL", ["10", "2"]

func SplitWithBalance

func SplitWithBalance(s string, sep rune) []string

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 Condition

type Condition struct {
	Field    string `yaml:"field"`    // "column_name"/"is_primary_key"/"source_type"/"length"
	Operator string `yaml:"operator"` // "equals"/"contains"/"matches"/"range"
	Value    any    `yaml:"value"`
}

type ContextMappingRule

type ContextMappingRule struct {
	Name        string      `yaml:"name"`
	Conditions  []Condition `yaml:"conditions"`
	TargetType  string      `yaml:"target_type"`
	Priority    int         `yaml:"priority"`
	Description string      `yaml:"description"`
}

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 FloatPolicy struct {
	PreferFloat64       bool   `yaml:"prefer_float64"`
	WarnOnPrecisionLoss bool   `yaml:"warn_on_precision_loss"`
	RoundingMode        string `yaml:"rounding_mode"`
}

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

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

type TableContext struct {
	TableName string
	Engine    string
	Charset   string
	Collation string
}

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

type TypeMapping map[string]string

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.

type WarningStatistics

type WarningStatistics struct {
	TotalWarnings   int
	ByLevel         map[string]int
	ByCategory      map[string]int
	AffectedTables  int
	AffectedColumns int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL