Skip to content

Instantly share code, notes, and snippets.

@toreriklinnerud
Created July 29, 2011 16:13
Show Gist options
  • Save toreriklinnerud/1114138 to your computer and use it in GitHub Desktop.
Save toreriklinnerud/1114138 to your computer and use it in GitHub Desktop.
Drop and recreate all views after database migrations
desc "Drop and create all views"
task 'db:reload_views' => :environment do
ActiveRecord::Migration.verbose = false
Logger.new(STDOUT).debug('Rebuilding Views...')
ActiveRecord::Migrator.down('db/views/')
ActiveRecord::Migrator.up('db/views/')
ActiveRecord::Migration.verbose = true
end
Rake::Task['db:migrate'].enhance do
Rake::Task['db:reload_views'].invoke
end
desc "Drop all views"
task 'db:drop_views' => :environment do
ActiveRecord::Migration.verbose = false
Logger.new(STDOUT).debug('Drop Views...')
ActiveRecord::Migrator.down('db/views/')
ActiveRecord::Migration.verbose = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment