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_records(options = {}) ⇒ Object



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
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/stagehand/auditor.rb', line 23

def mismatched_records(options = {})
  output = {}

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

    min_id = [
      Database.staging_connection.select_value("SELECT MIN(id) FROM #{table_name}").to_i,
      Database.production_connection.select_value("SELECT MIN(id) FROM #{table_name}").to_i
    ].min

    index = min_id / limit

    max_id = [
      Database.staging_connection.select_value("SELECT MAX(id) FROM #{table_name}").to_i,
      Database.production_connection.select_value("SELECT MAX(id) FROM #{table_name}").to_i
    ].max

    loop do
      production_records = Database.production_connection.select_all("SELECT * FROM #{table_name} WHERE id BETWEEN #{limit * index} AND #{limit * (index + 1)}")
      staging_records = Database.staging_connection.select_all("SELECT * FROM #{table_name} WHERE id BETWEEN #{limit * index} AND #{limit * (index + 1)}")
      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 if index * limit > max_id
    end

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

  return output
end

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



81
82
83
# File 'lib/stagehand/auditor.rb', line 81

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



85
86
87
# File 'lib/stagehand/auditor.rb', line 85

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