Skip to content

refactor: type-safe schema mapping with built-in defaults#21

Merged
bitalizer merged 15 commits into
masterfrom
refactor/type-safe-schema
Apr 12, 2026
Merged

refactor: type-safe schema mapping with built-in defaults#21
bitalizer merged 15 commits into
masterfrom
refactor/type-safe-schema

Conversation

@bitalizer
Copy link
Copy Markdown
Owner

Summary

  • Replace all stringly-typed schema handling with type-safe enums (MssqlType, MySqlBaseType, MySqlType)
  • Add TypeRegistry with built-in exhaustive defaults for all 29 MSSQL types — no mandatory config file needed
  • Simplify mappings.toml to optional key-value overrides: nvarchar = "varchar(500)"
  • Fix 8 data-correctness bugs: binary quoting, Bit/U8 NULL handling, float quoting, datetime2 precision, SmallDateTime crash
  • Separate ColumnSchema (source) from TargetColumn (output) with validated MySqlType
  • Share TypeRegistry across concurrent tasks via Arc
  • Add 163 unit tests covering type mapping, schema conversion, SQL rendering, and override parsing
  • Update README with improved structure, type mapping reference table, and usage examples

Test plan

  • cargo test — 163 tests pass, 0 failures
  • cargo clippy -- -D warnings — clean
  • cargo build --release — succeeds
  • Integration test with Docker MSSQL + MySQL containers

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)
@bitalizer bitalizer force-pushed the refactor/type-safe-schema branch from 9fd60fe to cac4a67 Compare April 12, 2026 14:28
@bitalizer bitalizer merged commit 371cae3 into master Apr 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant