Scope history record lookup by context key - #176
Conversation
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds an internal ChangesContext-scoped history record selection
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
SqliteDropCreateDatabaseWhenModelChanges stores the context name on each history record and documents that a database may be shared by several contexts, but GetHistoryRecord selected with SingleOrDefault and no Context filter. On a shared history table that matches multiple records: IsSameModel swallows the resulting exception and reports a model change, while SaveHistory throws. Look the record up by context.GetType().FullName, matching what SaveHistory writes.
e019947 to
c214040CompareUh oh!
There was an error while loading. Please reload this page.



Summary
SqliteDropCreateDatabaseWhenModelChangeswrites the context name onto every history record and documents that a database may be shared by more than one context. The lookup, however, usedSingleOrDefault()with noContextfilter, so it ignored that scoping entirely.On a history table that contains rows for more than one context the unscoped lookup matches multiple records:
IsSameModelcatches the resultingInvalidOperationExceptionand reports a model change (unnecessary drop/recreate).SaveHistorydoes not guard it and throws.Changes
GetHistoryRecordnow looks the record up bycontext.GetType().FullName, matching the keySaveHistorywrites.HistoryRecordSelectorhelper so the logic is unit-testable without a database.Tests
Added
HistoryRecordSelectorTest: correct record returned for a given context,nullwhen none match or the table is empty, and the one-record-per-context invariant surfaced as an exception if violated. Full suite green (51 tests).