Skip to content

refactor(storage): decompose monolithic LocalDb into Repository pattern and MigrationRunner #1502

Open

Description

@ZhuchkaTriplesix

Problem

lib/core/storage/local_db.dart is currently 1,342 lines long and acts as a monolithic God Object. It combines multiple distinct domain responsibilities:

  1. Schema Migrations: Schema creation and incremental upgrade logic across 13 versions (_onCreate, _onUpgrade, WAL / foreign key pragmas).
  2. Connections CRUD: Querying, inserting, updating, soft/hard deleting connections, SSH tunneling configs, and secret migrations.
  3. Folders Storage: Managing folder hierarchies, nesting, reordering, and folder-connection associations.
  4. Query History: Recording, querying, filtering, and pruning SQL statement history.
  5. Pinned Objects: Managing starred/pinned tables and collections per connection.

This coupling violates the Single Responsibility Principle, makes unit testing difficult without mounting a live SQLite database, and creates concurrency contention bottlenecks.

Scope

Decompose local_db.dart into dedicated single-responsibility repositories under lib/core/storage/:

  • LocalDbMigrationRunner (or DatabaseMigrationService): Encapsulates onCreate, onUpgrade (v1 through v13) and pragma configurations.
  • ConnectionRepository: Connection CRUD, SSH tunnel associations, environment tagging, secret store synchronization.
  • FolderRepository: Hierarchical folder tree management and ordering.
  • QueryHistoryRepository: Execution history storage, capping, and search.
  • PinnedObjectsRepository: Managing pinned/favorited database objects.
  • Keep LocalDb as a lightweight facade (or gradually migrate callers to the repositories directly) to preserve backward compatibility during the transition.

Acceptance

  • local_db.dart reduced to a lightweight facade or removed in favor of repositories.
  • Schema migration logic isolated in a testable migration runner with automated upgrade tests.
  • Existing storage unit and integration tests remain 100% green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority / Parity & RefactoringcoreCore library logic and servicesstorageTheme parser epic label: storage

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions