Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to delete inconsistent vizs #3286 #3342

Merged
merged 1 commit into from
Apr 23, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions lib/tasks/viz_maintenance.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace :cartodb do
namespace :vizs do

desc "Purges broken visualizations due to bug during deletion."
task :delete_inconsistent, [:username] => :environment do |t, args|
username = args[:username]
raise "You should pass a username param" unless username
user = User[username: username]
collection = CartoDB::Visualization::Collection.new.fetch(user_id: user.id)

collection.each do |viz|
if is_inconsistent?(viz)
delete_with_confirmation(viz)
end
end
end

def is_inconsistent?(viz)
(viz.table? && viz.related_tables.empty?) || (viz.derived? && viz.map.nil?)
end

def delete_with_confirmation(viz)
display_info(viz)
if ok_to_delete?
viz.delete
STDOUT.puts "deleted!"
end
end

def display_info(viz)
STDOUT.puts "\nviz.name = #{viz.name}"
STDOUT.puts "viz.type = #{viz.type}"
STDOUT.puts "viz.related_tables = #{viz.related_tables.map {|t| t.name}}"
STDOUT.puts "viz.map_id = #{viz.map_id}"
end

def ok_to_delete?
STDOUT.puts "About to delete. Are you sure? (y/n)"
input = STDIN.gets.strip
return input == 'y'
end

end
end