refactor(database): share Tauri SQL provider lifecycle - #779
Closed
beruro wants to merge 1 commit into
Closed
Conversation
Collaborator
Author
|
Superseded by #780, which preserves this change as an independent commit and has passed the consolidated CI suite. The source branch is retained for recovery. |
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.
Problem
The PostgreSQL and MySQL providers independently implemented the same connection state machine, Tauri command mapping, metadata conversion, pagination, query result shaping, mutation error handling, and CRUD flow. Roughly 340 lines per provider were duplicated, so fixes to the shared sqlx-backed boundary could drift while the real dialect differences remained difficult to review.
Solution
Introduce a generic
TauriSqlProviderthat owns the common lifecycle and command adapter. Each concrete provider now supplies a typed dialect containing only its database type, connection-string builder, identifier quoting, and value formatting. The public provider classes, Tauri command names and payloads, connection status behavior, generated PostgreSQL/MySQL SQL, and remotesave()behavior remain unchanged.Add focused regression coverage for both dialects: connection payloads, pagination/count SQL, CRUD SQL/value formatting, metadata conversion, disconnect cleanup, pre-connect rejection, and connection failure state.
Potential risks
A defect in the new shared base could affect both PostgreSQL and MySQL instead of one provider. Exact command payload and SQL-generation tests cover that coupling, and the refactor does not change persisted connection formats, IPC command names, or Rust handlers. Live PostgreSQL/MySQL connectivity through the native Tauri runtime was not exercised locally, so native driver/environment behavior remains an unverified path; rollback is a normal revert because there is no migration or data rewrite.
Architecture audit
Covered type ownership, provider boundaries, connection-state transitions, Tauri IPC contracts, error mapping, initialization parity, test topology, naming, and removed duplication. Persistence/migration and unrelated database providers were inspected for boundary compatibility but intentionally left unchanged.
Verification
pnpm exec vitest run src/engines/DatabaseCore/providers/__tests__/TauriSqlProvider.test.ts src/engines/DatabaseCore/__tests__/types.test.ts— passed, 19 tests.pnpm exec eslint src/engines/DatabaseCore/providers/TauriSqlProvider.ts src/engines/DatabaseCore/providers/PostgresProvider.ts src/engines/DatabaseCore/providers/MySQLProvider.ts src/engines/DatabaseCore/providers/__tests__/TauriSqlProvider.test.ts— passed.pnpm typecheck— executed and passed.lint-staged, scoped TypeScript check) — passed.verify:quick/verify:final, so the focused Vitest/ESLint commands and fullpnpm typecheckabove were used as the equivalent verification path.