Class: ProjectUnification::ModelClassifier
- Inherits:
-
Object
- Object
- ProjectUnification::ModelClassifier
- Defined in:
- lib/project_unification/model_classifier.rb
Constant Summary collapse
- FAST_TRACK =
Bulk SQL UPDATE — no per-record validation. Safe only when the model has no project-scoped uniqueness validators, OR when every such validator's scope includes a FK to a project-specific model (making cross-project collisions impossible). See model_classifier_spec.rb for the tripwire.
%w[ Container Tag Note Citation DataAttribute Identifier AlternateValue Confidence Depiction Documentation Attribution Conveyance ProtocolRelationship DwcOccurrence BiologicalAssociationIndex TaxonNameClassification TaxonNameRelationship PinboardItem ImportAttribute InternalAttribute News Observation TaggedSectionKeyword Role Label Protocol SqedDepiction CollectionObjectObservation AnatomicalPart AssertedDistribution BiologicalRelationshipType BiologicalAssociation BiologicalRelationship BiologicalAssociationsGraph CollectionProfile ContainerItem PublicContent Gazetteer GazetteerImport Georeference Lead LeadItem Loan Sound CommonName OriginRelationship Sequence SequenceRelationship Extract ObservationMatrixColumnItem ObservationMatrixRow ObservationMatrixRowItem FieldOccurrence CollectionObject Otu Descriptor Download DatasetRecordField DatasetRecord OtuPageLayoutSection TaxonDetermination BiocurationClassification CharacterState GeneAttribute LoanItem ObservationMatrixColumn DerivedCollectionObject TypeMaterial OtuRelationship Content SledImage CitationTopic BiologicalAssociationsBiologicalAssociationsGraph ].freeze
- SLOW_TRACK =
Per-record validation required to detect uniqueness conflicts against target. Conflicts are reported to the user and the unify fails — the user must resolve (e.g. rename) before retrying.
!! If any model here uses acts_as_list, its positions can be reshuffled by acts_as_list callbacks when save! fires during conflict handling. Fast-track models avoid this entirely (update_all bypasses callbacks). If a slow-track model has position-sensitive semantics, it may need a handle_unify_conflict that bypasses acts_as_list via update_columns — see the now-removed TaxonDetermination#handle_unify_conflict for the pattern.
%w[ ObservationMatrix ImportDataset ].freeze
- SPECIAL_HANDLING =
Special handling required - custom migration logic.
%w[ TaxonName CollectingEvent ProjectSource RangedLotCategory OtuPageLayout Image Document ControlledVocabularyTerm ].freeze
- CACHED_TABLES =
Cached tables - use direct SQL update without validation.
%w[ CachedMap CachedMapItem CachedMapRegister ].freeze
- EXCLUDED =
Never migrate these.
%w[ProjectMember].freeze
Class Method Summary collapse
-
.should_migrate?(model_class) ⇒ Boolean
True if model should be migrated.
-
.statistics ⇒ Hash
Statistics about model distribution.
-
.track_for(model_class) ⇒ Symbol
:fast, :slow, :special, :cached, or :excluded.
Class Method Details
.should_migrate?(model_class) ⇒ Boolean
Returns true if model should be migrated.
153 154 155 |
# File 'lib/project_unification/model_classifier.rb', line 153 def self.should_migrate?(model_class) track_for(model_class) != :excluded end |
.statistics ⇒ Hash
Returns Statistics about model distribution.
142 143 144 145 146 147 148 149 |
# File 'lib/project_unification/model_classifier.rb', line 142 def self.statistics { fast_track: FAST_TRACK.length, slow_track: SLOW_TRACK.length, special: SPECIAL_HANDLING.length, excluded: EXCLUDED.length } end |
.track_for(model_class) ⇒ Symbol
Returns :fast, :slow, :special, :cached, or :excluded.
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/project_unification/model_classifier.rb', line 128 def self.track_for(model_class) name = model_class.name return :excluded if EXCLUDED.include?(name) return :cached if CACHED_TABLES.include?(name) return :cached if model_class.table_name.to_s.start_with?('cached_') return :special if SPECIAL_HANDLING.include?(name) return :fast if FAST_TRACK.include?(name) return :slow if SLOW_TRACK.include?(name) raise ArgumentError, "#{name} is not classified in ModelClassifier — add it to the appropriate track" end |