/
lsm
executable file
·58 lines (47 loc) · 1.17 KB
/
lsm
1
2
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
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
#!/usr/bin/ruby
#Util to show migrations in a nice to read format
require 'date'
require 'rubygems'
require 'term/ansicolor'
include Term::ANSIColor
version = `rake db:version`
sort_alphabetically = ARGV[0] == "s"
time = version.split(":")[1]
current_version = time.chomp!.strip!
time = DateTime.parse(time).to_s
date = time.split("T")[0]
time = time.split("T")[1][0..7]
puts green
puts "Current version: " + date + " " + time
puts reset
list = `ls db/migrate`
arr = []
longest=0
list.each do |i|
name= i[15..-5]
time=i[0..13]
longest = name.length if name.length > longest
arr << [name,time]
end
if sort_alphabetically
arr.sort! do |a,b|
a[0].downcase <=> b[0].downcase
end
end
arr.each do |details|
name,time = details[0], details[1]
name.gsub! "_"," "
spaces=(longest - name.length)+5
colorize = true if time==current_version
date_time = DateTime.parse(time)
date = date_time.to_s.split("T")[0]
time = date_time.to_s.split("T")[1][0..7]
ago = date_time.ago DateTime.now
puts red if colorize
puts name + (" "*spaces) + "| " + date + " " + time + reset + " " + ago.to_s
#reset colors
if colorize
colorize = false
puts reset
end
end