Skip to content

refactor: trait abstractions for testable DB layer#19

Merged
bitalizer merged 1 commit into
masterfrom
refactor/trait-abstractions
Apr 12, 2026
Merged

refactor: trait abstractions for testable DB layer#19
bitalizer merged 1 commit into
masterfrom
refactor/trait-abstractions

Conversation

@bitalizer
Copy link
Copy Markdown
Owner

Summary

  • Define Extractor and Inserter traits behind which DatabaseExtractor and DatabaseInserter implement their DB operations
  • Make DatabaseMigrator, TableMigrator, and ConstraintsCreator generic over these traits, enabling mock-based unit testing of orchestration logic without real databases
  • stream_rows returns BoxStream<'static> via async_stream::stream!, owning its pooled connection inside the stream
  • Remove direct pool access (open_row_stream, pub pool) — all DB interaction goes through trait methods
  • Bump version to 0.3.0, edition to 2024

What changed

File Change
src/extract/traits.rs New Extractor trait
src/insert/traits.rs New Inserter trait
src/extract/extractor.rs Implements Extractor, pool now private, stream_rows rewritten
src/insert/inserter.rs Implements Inserter
src/migrate/migrator.rs DatabaseMigrator<E, I> generic
src/migrate/table_migrator.rs TableMigrator<E, I> generic, uses stream_rows
src/migrate/constraints_creator.rs ConstraintsCreator<I> generic
src/main.rs let mut migratorlet migrator
Cargo.toml version 0.3.0, edition 2024, add async-stream
Various cargo fmt import reordering (edition 2024)

What does NOT change

  • Concurrency model (semaphore + spawned tasks + fail-fast via watch channel)
  • Row batching logic (packet size limits, INSERT construction)
  • Constraint creation (best-effort, errors logged)
  • All existing 113 tests pass

Test plan

  • cargo build — compiles cleanly
  • cargo clippy -- -D warnings — no warnings
  • cargo fmt --check — formatted
  • cargo test — 113 tests pass
  • Smoke test against real MSSQL → MySQL migration (recommended before merge)

Define Extractor and Inserter traits for testable DB abstractions.
DatabaseMigrator, TableMigrator, and ConstraintsCreator are now generic
over these traits, enabling mock-based testing without real databases.

- Add Extractor trait with fetch_tables, get_table_schema, stream_rows
- Add Inserter trait with all MySQL insertion operations
- stream_rows returns BoxStream<'static> via async_stream, owning its connection
- Remove open_row_stream free function and direct pool access
- Change &mut self to &self on all migrator methods (pools are ref-counted)
- Make DatabaseExtractor.pool private
- Bump version to 0.3.0, edition to 2024
- Fix collapsible_if clippy lint from edition 2024
- Apply cargo fmt (edition 2024 import ordering)
@bitalizer bitalizer merged commit c85154f into master Apr 12, 2026
6 checks passed
@bitalizer bitalizer deleted the refactor/trait-abstractions branch April 12, 2026 09:34
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