Module: Mighost::GitRecovery

Defined in:
lib/mighost/git_recovery.rb

Overview

Searches git history to find migration files that exist in other branches/commits

Class Method Summary collapse

Class Method Details

.find_migration(version) ⇒ Object

Find migration file content from git history Returns { content:, filename:, branch:, sha:, commit_date: } or nil



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mighost/git_recovery.rb', line 13

def find_migration(version)
  return nil unless GitMetadata.git_available?

  # Search for the migration file across all branches using --all
  pattern = "db/migrate/#{version}_*.rb"

  result = find_latest_commit_with_file(pattern)
  return nil unless result

  content = get_file_content(result[:sha], result[:path])
  return nil unless content

  {
    content: content,
    filename: File.basename(result[:path]),
    branch: result[:branch],
    sha: result[:sha][0, 12],
    commit_date: result[:date],
    author_name: result[:author_name],
    author_email: result[:author_email]
  }
end