Created
February 13, 2018 13:41
-
-
Save mccun934/6711c249ab077dfa8d7d526dcc501a8a to your computer and use it in GitHub Desktop.
delete orphan dynflow data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat <<EOF | foreman-rake console | |
persistence = ForemanTasks.dynflow.world.persistence | |
adapter = persistence.adapter | |
batch_size = 5 | |
total = adapter.db.fetch("select count(dynflow_execution_plans.uuid) from dynflow_execution_plans left join foreman_tasks_tasks on (dynflow_execution_plans.uuid = foreman_tasks_tasks.external_id) where foreman_tasks_tasks.id IS NULL").first[:count] | |
deleted = 0 | |
puts "about to delete #{total} execution plans" | |
while (plans_without_tasks = adapter.db.fetch("select dynflow_execution_plans.uuid from dynflow_execution_plans left join foreman_tasks_tasks on (dynflow_execution_plans.uuid = foreman_tasks_tasks.external_id) where foreman_tasks_tasks.id IS NULL LIMIT #{batch_size}").all.map { |x| x[:uuid] }) && !plans_without_tasks.empty? | |
persistence.delete_execution_plans({ 'uuid' => plans_without_tasks }, batch_size) | |
deleted += plans_without_tasks.count | |
puts "deleted #{deleted} out of #{total}" | |
end | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment