refactor: trait abstractions for testable DB layer#19
Merged
Conversation
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)
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
ExtractorandInsertertraits behind whichDatabaseExtractorandDatabaseInserterimplement their DB operationsDatabaseMigrator,TableMigrator, andConstraintsCreatorgeneric over these traits, enabling mock-based unit testing of orchestration logic without real databasesstream_rowsreturnsBoxStream<'static>viaasync_stream::stream!, owning its pooled connection inside the streamopen_row_stream,pub pool) — all DB interaction goes through trait methods0.3.0, edition to2024What changed
src/extract/traits.rsExtractortraitsrc/insert/traits.rsInsertertraitsrc/extract/extractor.rsExtractor,poolnow private,stream_rowsrewrittensrc/insert/inserter.rsInsertersrc/migrate/migrator.rsDatabaseMigrator<E, I>genericsrc/migrate/table_migrator.rsTableMigrator<E, I>generic, usesstream_rowssrc/migrate/constraints_creator.rsConstraintsCreator<I>genericsrc/main.rslet mut migrator→let migratorCargo.tomlcargo fmtimport reordering (edition 2024)What does NOT change
Test plan
cargo build— compiles cleanlycargo clippy -- -D warnings— no warningscargo fmt --check— formattedcargo test— 113 tests pass