# 2008 John Yerhot # joyerhot@gmail.com # http://www.johnyerhot.com # This will create a file containing the table structure of your current database. # Will output to your Terminal and to a text file "table_structure_todays_date.txt" # desc "Creates a textfile with the structure of your database." task(:leaves => :environment) do text = "" ActiveRecord::Base.connection.tables.each do |table| puts "Table Name:\t#{table.to_s} \n" text << "Table Name:\t#{table.to_s} \n" begin model = eval(table.classify) cols = model.columns rescue cols = nil end unless cols == nil cols.each do |column| puts "\t#{column.name} - #{column.type}" text << "\t#{column.name} - #{column.type} \n " end puts "\n" text << "\n" end end file = File.new("table_structure_#{Date.today.strftime("%d_%b_%Y")}.txt", 'w+') file.puts(text.to_s) puts "\n\nWrote to table_structure_#{Date.today.strftime("%d_%b_%Y")}.txt" end