config

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config defines the YAML-backed configuration for the transformation engine: directories, rule toggles, and charset/collation mappings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoRandomConfig added in v1.3.0

type AutoRandomConfig struct {
	// Tables lists table names to convert, or "*" for every eligible table;
	// empty disables the conversion.
	Tables []string `yaml:"tables"`

	// ShardBits is AUTO_RANDOM's S (1-15).
	ShardBits int `yaml:"shard_bits"`

	// RangeBits is AUTO_RANDOM's R (32-64). The default 54 keeps every ID
	// below 2^53, so it stays exact in JavaScript and below PHP_INT_MAX; 64
	// is TiDB's own default and produces IDs up to 2^63-1.
	RangeBits int `yaml:"range_bits"`
}

AutoRandomConfig selects tables for AUTO_RANDOM conversion. https://docs.pingcap.com/tidb/stable/auto-random

type CharsetMapping

type CharsetMapping struct {
	TargetCharset   string `yaml:"target_charset"`
	TargetCollation string `yaml:"target_collation"`
}

CharsetMapping defines target charset and collation for a source charset

type Config

type Config struct {
	// InputDir specifies the directory to read SQL files from
	InputDir string `yaml:"input_dir"`

	// OutputDir specifies the directory to write transformed SQL files
	OutputDir string `yaml:"output_dir"`

	// EnabledRules is a list of rule names to enable
	EnabledRules []string `yaml:"enabled_rules"`

	// DisabledRules is a list of rule names to disable
	DisabledRules []string `yaml:"disabled_rules"`

	// FormattingOptions controls output formatting
	FormattingOptions FormattingConfig `yaml:"formatting"`

	// CharsetMappings defines how to convert character sets
	CharsetMappings map[string]CharsetMapping `yaml:"charset_mappings"`

	// CollationMappings defines how to convert collations
	CollationMappings map[string]string `yaml:"collation_mappings"`

	// AllowedDefaultFunctions lists function names the FunctionDefault rule
	// keeps in DEFAULT clauses; anything else is stripped.
	// https://docs.pingcap.com/tidb/stable/data-type-default-values
	AllowedDefaultFunctions []string `yaml:"allowed_default_functions"`

	// ZeroDateDefaults controls DEFAULT '0000-00-00...' on date/time columns,
	// which TiDB rejects under its default sql_mode (NO_ZERO_DATE,
	// NO_ZERO_IN_DATE): "keep" (default) leaves them and warns, "drop"
	// removes the DEFAULT clause.
	ZeroDateDefaults string `yaml:"zero_date_defaults"`

	// AutoRandom converts BIGINT AUTO_INCREMENT primary keys of the listed
	// tables to AUTO_RANDOM to avoid write hotspots. Opt-in.
	AutoRandom AutoRandomConfig `yaml:"auto_random"`

	// ShardRowIDBits adds SHARD_ROW_ID_BITS to tables without a clustered
	// primary key (no PRIMARY KEY, or NONCLUSTERED); 0 disables it.
	ShardRowIDBits uint64 `yaml:"shard_row_id_bits"`

	// PreSplitRegions adds PRE_SPLIT_REGIONS next to SHARD_ROW_ID_BITS; 0
	// leaves it out.
	PreSplitRegions uint64 `yaml:"pre_split_regions"`

	// Removed in v1.2.0 (never implemented); still accepted so existing
	// config files load. They have no effect.
	LegacyStrictMode       *bool `yaml:"strict_mode,omitempty"`
	LegacyPreserveComments *bool `yaml:"preserve_comments,omitempty"`
}

Config holds configuration for the transformation engine

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads configuration from a YAML file. If path is empty, returns DefaultConfig. Unknown keys and out-of-range values are errors: a typo would otherwise silently fall back to a default.

func (*Config) IsRuleEnabled

func (c *Config) IsRuleEnabled(ruleName string) bool

IsRuleEnabled checks if a rule is enabled based on configuration

func (*Config) Validate added in v1.3.0

func (c *Config) Validate() error

Validate checks values against what TiDB accepts.

type FormattingConfig

type FormattingConfig struct {
	// IndentSize specifies the number of spaces for indentation
	IndentSize int `yaml:"indent_size"`

	// UppercaseKeywords determines if SQL keywords should be uppercase
	UppercaseKeywords bool `yaml:"uppercase_keywords"`

	// BackquoteIdentifiers determines if identifiers should be backtick-quoted.
	// Disabling it emits bare names, which breaks DDL for reserved words.
	BackquoteIdentifiers bool `yaml:"backquote_identifiers"`

	// SingleQuoteStrings determines if strings should use single quotes
	SingleQuoteStrings bool `yaml:"single_quote_strings"`
}

FormattingConfig controls SQL output formatting

Jump to

Keyboard shortcuts

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