Skip to content

Instantly share code, notes, and snippets.

@maxim
Created April 12, 2009 07:20
Show Gist options
  • Select an option

  • Save maxim/93906 to your computer and use it in GitHub Desktop.

Select an option

Save maxim/93906 to your computer and use it in GitHub Desktop.
desc "Removes all tables from the current database"
task(:wipe => :environment) do
conf = ActiveRecord::Base.configurations
tables = `psql #{conf[RAILS_ENV]["database"]} #{conf[RAILS_ENV]["username"]} -c "\\d" -A | grep table`.split("\n").collect{|l| l.split('|')[1]}
tables.each do |table|
if system("psql #{conf[RAILS_ENV]["database"]} #{conf[RAILS_ENV]["username"]} -c \"DROP TABLE #{table}\"")
puts "Dropped table #{table}"
else
puts "ERROR: Couldn't drop #{table}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment