I'm working to create a rake task to remove a few tables and triggers.
My rake task:
task :remove_rubyrep do
sql = <<-SQL
DROP TABLE rr_logged_events, rr_running_flags, rr_pending_changes;
SQL
ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.execute(sql)
end
I tried running this like so:
rake remove_rubyrep
RAILS_ENV=development rake remove_rubyrep
Problem is the rake tasks errors with:
rake aborted!
ActiveRecord::ConnectionNotEstablished
Any suggestions on how to allow the rake task to connect to the DB to execute the raw sql? Thanks
You're not loading the rails application in your rake task, so ActiveRecord never creates a database connection.
Change your rake task to:
task :remove_rubyrep => :environment do
After doing that, you'll no longer need the "establish_connection" line
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