Class: SchemaTransformer::Analyze
- Inherits:
-
Base
- Object
- Base
- SchemaTransformer::Analyze
show all
- Defined in:
- lib/schema_transformer/analyze.rb
Instance Attribute Summary
Attributes inherited from Base
#options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Class Method Details
.run(options) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/schema_transformer/analyze.rb', line 3
def self.run(options)
@analyze = Analyze.new(options[:base] || Dir.pwd, options)
puts "Analyzing your database schema..."
if @analyze.no_timestamps.empty?
puts "There are no tables without the updated_at timestamp. GOOD"
else
puts "These tables do not have updated_at timestamps: "
puts " #{@analyze.no_timestamps.join("\n ")}"
end
if @analyze.no_indexes.empty?
puts "There are no tables with updated_at timestamp but no indexes. GOOD"
else
puts "These tables do have an updated_at timestamp, but no index: "
puts " #{@analyze.no_indexes.join("\n ")}"
end
if @analyze.no_timestamps.empty? or @analyze.no_timestamps.empty?
"Everything looks GOOD!"
else
puts "You should add the missing columns or indexes."
end
end
|
Instance Method Details
#indexes ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/schema_transformer/analyze.rb', line 39
def indexes
tables = []
timestamps.each do |table|
has_index = @conn.indexes(table).detect {|col| col.columns == ["updated_at"] }
tables << table if has_index
end
tables
end
|
#no_indexes ⇒ Object
48
49
50
|
# File 'lib/schema_transformer/analyze.rb', line 48
def no_indexes
timestamps - indexes
end
|
#no_timestamps ⇒ Object
tells which tables are missing updated_at and index on updated_at
26
27
28
|
# File 'lib/schema_transformer/analyze.rb', line 26
def no_timestamps
@conn.tables - timestamps
end
|
#timestamps ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/schema_transformer/analyze.rb', line 30
def timestamps
tables = []
@conn.tables.each do |table|
has_updated_at = @conn.columns(table).detect {|col| col.name == "updated_at" }
tables << table if has_updated_at
end
tables
end
|