Class: Mighost::OrphanDetector
- Inherits:
-
Object
- Object
- Mighost::OrphanDetector
- Defined in:
- lib/mighost/orphan_detector.rb
Defined Under Namespace
Classes: OrphanedMigration
Class Attribute Summary collapse
-
.debug ⇒ Object
Returns the value of attribute debug.
Class Method Summary collapse
-
.branch_changed? ⇒ Boolean
Check if current branch/sha differs from last scan.
-
.detect(include_dismissed: false) ⇒ Object
Detect orphaned migrations using cached snapshot data only (instant).
- .orphaned_count ⇒ Object
- .recoverable_count ⇒ Object
-
.scan_metadata ⇒ Object
Get stored scan metadata.
Class Attribute Details
.debug ⇒ Object
Returns the value of attribute debug.
70 71 72 |
# File 'lib/mighost/orphan_detector.rb', line 70 def debug @debug end |
Class Method Details
.branch_changed? ⇒ Boolean
Check if current branch/sha differs from last scan
126 127 128 129 130 131 132 133 134 |
# File 'lib/mighost/orphan_detector.rb', line 126 def branch_changed? = return false unless current_branch = GitMetadata.current_branch current_sha = GitMetadata.current_sha [:branch] != current_branch || [:sha] != current_sha end |
.detect(include_dismissed: false) ⇒ Object
Detect orphaned migrations using cached snapshot data only (instant)
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/mighost/orphan_detector.rb', line 74 def detect(include_dismissed: false) # Load everything upfront for performance versions = migrated_versions file_versions = migration_file_versions dismissed_set = Snapshot.dismissed_versions.to_set snapshots_by_version = Snapshot..index_by(&:version) log "Found #{versions.count} migrated versions, #{file_versions.count} files on disk" orphaned = [] versions.each do |version| # Skip if file exists on disk next if file_versions.include?(version) # Skip dismissed unless requested is_dismissed = dismissed_set.include?(version) next if is_dismissed && !include_dismissed snapshot = snapshots_by_version[version] log " #{version} - orphaned#{", has snapshot (#{snapshot.source})" if snapshot}" orphaned << OrphanedMigration.new( version: version, filename: snapshot&.filename, branch_name: snapshot&.branch_name, git_sha: snapshot&.git_sha, migrated_at: snapshot&.migrated_at, source: snapshot&.source, dismissed: is_dismissed, author_name: snapshot&., author_email: snapshot&. ) end log "Done. Found #{orphaned.count} orphaned migrations." orphaned.sort_by(&:version).reverse end |
.orphaned_count ⇒ Object
112 113 114 |
# File 'lib/mighost/orphan_detector.rb', line 112 def orphaned_count detect.count end |
.recoverable_count ⇒ Object
116 117 118 |
# File 'lib/mighost/orphan_detector.rb', line 116 def recoverable_count detect.count(&:recoverable?) end |
.scan_metadata ⇒ Object
Get stored scan metadata
121 122 123 |
# File 'lib/mighost/orphan_detector.rb', line 121 def Snapshot. end |