I need to drop all the tables in my database without dropping the database because the user for this database does not have create database privileges.
What is the best way to drop all the tables but not the actual database?
Also, we use rake db:seed
to add some entries into one of the tables so I don't want to use a seed file.
This is the solution I eventually came up with after looking at the Truncate method.
namespace :db do
desc "Erase all tables"
task :clear => :environment do
conn = ActiveRecord::Base.connection
tables = conn.tables
tables.each do |table|
puts "Deleting #{table}"
conn.drop_table(table)
end
end
end
for testing, i would suggest using:
rake db:test:prepare
It will re-generate all your tables based on your db/schema.rb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With