3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/localtower/status.rb', line 3
def run
files = Dir["#{Rails.root}/db/migrate/*.rb"].sort.reverse
db_migrations = begin
ActiveRecord::Base.connection.execute("select * from schema_migrations;")
rescue => e
[]
end
db_migrations = db_migrations.map { |e| e["version"].to_s }
files.map do |file_full_path|
name = file_full_path.split("/")[-1] time = name.split("_")[0] status = db_migrations.include?(time) ? :done : :todo
content = File.open(file_full_path).read
{
"file_full_path" => file_full_path,
"name" => name,
"time" => time.to_i,
"status" => status,
"content" => content
}
end
end
|