Refactor checksummed and not_checksummed scopes to reduce confusion and improve maintainability
Problem
Currently, our Geo verification scopes are confusing and inconsistent. The checksummed
and not_checksummed
scopes are defined in VerificationState
but are overridden in all primary models, while registries don't override them. This creates confusion about where these scopes should live and how they should work.
Current Issues:
-
VerificationState
is included inVerifiableModel
, which is then included in parent models - The base
checksummed
scope inVerificationState
doesn't work for parent models, requiring overrides - All primary models override these scopes with nearly identical implementations
- Registry models don't override them, creating inconsistency
- The abstractions are confusing and hard to understand
Example of Current Duplication:
Every primary model has similar scope overrides like:
scope :checksummed, -> { joins(:model_state).where.not(model_states: { verification_checksum: nil }) }
scope :not_checksummed, -> { joins(:model_state).where(model_states: { verification_checksum: nil }) }
Proposed Solution
Move the checksummed
and not_checksummed
scopes from VerificationState
to VerifiableModel
where they can be implemented generically to work for both:
- Models with separate state tables (using joins)
- Models with inline verification state (using direct column queries)
This would:
- Eliminate the need for model-specific overrides
- Reduce code duplication
- Make the abstractions clearer and more maintainable
- Ensure consistent behavior across all verifiable models
Context
The concept of "checksum" in Geo should only apply to primary models, not secondary registries, which are verified. This refactoring aligns with that principle by moving the scopes to the appropriate abstraction layer.
References
- Related Slack discussion: https://gitlab.slack.com/archives/C7U95P909/p1760015976915399
- Related MR: !208471 (merged) (Draft implementation)
- Related work: !208182 (Adding state tables support)
Edited by 🤖 GitLab Bot 🤖