Module: Stagehand::Auditor

Extended by:
Auditor
Included in:
Auditor
Defined in:
lib/stagehand/auditor.rb,
lib/stagehand/auditor/checklist_visualizer.rb

Defined Under Namespace

Classes: ChecklistVisualizer

Instance Method Summary collapse

Instance Method Details

#incomplete_commitsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stagehand/auditor.rb', line 7

def incomplete_commits
  incomplete = []

  incomplete_start_operations.each do |start_operation|
    entries = records_until_match(start_operation, :asc, :operation => Staging::CommitEntry::START_OPERATION).to_a
    incomplete << [start_operation.id, entries]
  end

  incomplete_end_operations.each do |end_operation|
    entries = records_through_match(end_operation, :desc, :operation => Staging::CommitEntry::START_OPERATION).to_a
    incomplete << [entries.last.id, entries]
  end

  return incomplete.to_h
end

#mismatched_recordsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/stagehand/auditor.rb', line 23

def mismatched_records
  output = {}

  tables = Database.staging_connection.tables.select {|table_name| Schema::has_stagehand?(table_name) }
  tables.each do |table_name|
    print "\nChecking #{table_name} "
    mismatched = {}
    limit = 1000
    index = 0

    loop do
      production_records = Database.production_connection.select_all("SELECT * FROM #{table_name} LIMIT #{limit} OFFSET #{limit * index}")
      staging_records = Database.staging_connection.select_all("SELECT * FROM #{table_name} LIMIT #{limit} OFFSET #{limit * index}")
      id_column = production_records.columns.index('id')

      production_differences = production_records.rows - staging_records.rows
      staging_differences = staging_records.rows - production_records.rows

      production_differences.each do |row|
        id = row[id_column]
        mismatched[id] = {:production => row}
      end
      staging_differences.each do |row|
        id = row[id_column]
        mismatched[id] ||= {:staging => row}
      end

      if production_differences.present? || staging_differences.present?
        print '!'
      else
        print '.'
      end

      index += 1
      break unless staging_records.present? || production_records.present?
    end

    if mismatched.present?
      print " #{mismatched.count} mismatched"
      output[table_name] = mismatched
    end
  end

  return output
end

#visualize(subject, output_file_name, options = {}) ⇒ Object



69
70
71
# File 'lib/stagehand/auditor.rb', line 69

def visualize(subject, output_file_name, options = {})
  visualize_checklist(Staging::Checklist.new(subject), output_file_name, options)
end

#visualize_checklist(checklist, output_file_name, options = {}) ⇒ Object



73
74
75
# File 'lib/stagehand/auditor.rb', line 73

def visualize_checklist(checklist, output_file_name, options = {})
  ChecklistVisualizer.new(checklist, options).output(output_file_name)
end