refactor(storage): narrow backend interfaces#182
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughRefactors storage configuration and backend dispatch: adds Changes
Sequence Diagram(s)sequenceDiagram
participant Factory as Factory (component)
participant Resolver as storage.ResolveBackend
participant SQLite as SQLite backend
participant Postgres as PostgreSQL backend
participant Mongo as MongoDB backend
Factory->>Resolver: call ResolveBackend[T](store, sqliteCb, pgCb, mongoCb)
alt store implements SQLiteStorage
Resolver->>SQLite: sqliteCb(*sql.DB)
SQLite-->>Resolver: T (store-specific)
else store implements PostgreSQLStorage
Resolver->>Postgres: pgCb(*pgxpool.Pool)
Postgres-->>Resolver: T (store-specific)
else store implements MongoDBStorage
Resolver->>Mongo: mongoCb(*mongo.Database)
Mongo-->>Resolver: T (store-specific)
end
Resolver-->>Factory: returns T or error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/storage/storage.go`:
- Around line 67-83: Add a centralized backend dispatch helper in
internal/storage (e.g., func WithBackendDispatch(s Storage, sqliteFn
func(*sql.DB) error, pgFn func(*pgxpool.Pool) error, mongoFn
func(*mongo.Database) error) error or ResolveBackend returning a discriminated
result) that contains the SQLite/PostgreSQL/MongoDB type switch currently
duplicated across factory.go files; use the existing SQLiteStorage,
PostgreSQLStorage and MongoDBStorage interfaces to detect and extract
DB/Pool/Database and call the appropriate callback, then update
internal/auditlog/factory.go, internal/usage/factory.go and
internal/aliases/factory.go to call this helper instead of repeating the type
switch so future backends are added in one place.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0fb607ba-a243-4c48-8877-75fa57c47b29
📒 Files selected for processing (13)
config/config.gointernal/aliases/factory.gointernal/auditlog/factory.gointernal/auditlog/reader_factory.gointernal/batch/factory.gointernal/batch/store_sqlite_test.gointernal/executionplans/factory.gointernal/storage/mongodb.gointernal/storage/postgresql.gointernal/storage/sqlite.gointernal/storage/sqlite_test.gointernal/storage/storage.gointernal/usage/factory.go
Summary
storage.Storageto lifecycle-only and replace backend-specificType()/anyaccessors with narrow typed interfacesconfig.StorageConfig.BackendConfig()Validation
go test ./...make test-e2emake lintSummary by CodeRabbit