3 # This is a utility to delete the "dead" columns
4 # from various tables in GForge. When run,
5 # it queries all the tables in the database, checks
6 # all their columns, and deletes the columns that
7 # start with the word "dead". Then it runs vacuumdb
8 # to reclaim the space.
10 # Usage: ./dead_column_cleaner.rb
13 USER_STR = "-U gforge gforge"
16 `psql -t -q #{USER_STR} -c "\dt"`.split("\n").each {|line|
17 tables << line.split("|")[1].delete(" ")
21 puts "Checking table " + t
22 cmd = "psql -t -q #{USER_STR} -c "
24 `#{cmd}`.split("\n").each {|line|
25 col = line.split("|")[0].delete(" ")
26 if col.index("dead") == 0
27 puts "Removing column " + col + " from table " + t
28 cmd = "psql #{USER_STR} -c "
29 cmd += "\"alter table #{t} drop column #{col}\""
36 `vacuumdb #{USER_STR}`