refactor: type-safe schema mapping with built-in defaults#21
Merged
Conversation
Introduces TypeRegistry in src/migrate/type_registry.rs with defaults for all 29 MssqlType variants, override support via set_override(), and 9 unit tests covering exhaustiveness, specific mappings, and override behavior.
Adds UserOverrides struct and parse_to_type helper to mappings.rs for type-safe TOML-driven MSSQL→MySQL type override parsing, including length/precision validation. Adds with_user_overrides method to TypeRegistry for applying user overrides to the registry.
Parse DATA_TYPE from MSSQL rows into the typed MssqlType enum at the boundary in ColumnSchema::from_row, and propagate the type-safe value through table_schema_mapper and query builders, replacing all &str comparisons and push_str calls with .as_str() / enum variants.
…dation Replace Mappings-based schema mapping with TypeRegistry-driven mapping that produces Vec<TargetColumn> (with MySqlType) instead of Vec<ColumnSchema>. Adds length/precision validation including MAX (-1) and overflow detection. Updates all downstream consumers (inserter, query, migrator, main) to use TargetColumn throughout the pipeline.
…at quoting, datetime2 precision, SmallDateTime crash)
- Task 11: Binary values now emit unquoted hex literals (0xffab) instead of quoted strings ('0xffab')
- Task 12: Bit(None) and U8(None) now correctly emit NULL instead of defaulting to false/0
- Task 13: F32 and F64 values now emit unquoted numbers via format_number_value instead of quoted strings
- Task 14: datetime2, time, and datetimeoffset now preserve sub-second precision using %.f format specifier
- Task 15: SmallDateTime no longer multiplies seconds_fragments by 60 (it already holds minutes)
9fd60fe to
cac4a67
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MssqlType,MySqlBaseType,MySqlType)TypeRegistrywith built-in exhaustive defaults for all 29 MSSQL types — no mandatory config file neededmappings.tomlto optional key-value overrides:nvarchar = "varchar(500)"ColumnSchema(source) fromTargetColumn(output) with validatedMySqlTypeTypeRegistryacross concurrent tasks viaArcTest plan
cargo test— 163 tests pass, 0 failurescargo clippy -- -D warnings— cleancargo build --release— succeeds