Project

General

Profile

Revision b7c39bfa

Added by Marek Hulán over 3 years ago

Fixes #19591 - provide clean up task

View differences:

lib/tasks/cleanup.rake
1
namespace :foreman_docker do
2
  desc 'Clean default data created by this plugin, this will permanently delete the data!'
3
  task :cleanup => :environment do
4
    puts 'Cleaning data...'
5

  
6
    User.as_anonymous_admin do
7
      puts '... deleting records from taxable_taxonomies'
8
      TaxableTaxonomy.where(:taxable_type => [ 'Container', 'DockerRegistry', 'Preliminary', 'ForemanDocker::Docker' ]).delete_all
9
      puts '... deleting filters'
10
      Filter.joins(:permissions).where('permissions.resource_type' => Foreman::Plugin.find(:foreman_docker).registered_permissions.map { |p, attrs| attrs[:resource_type] }.uniq!).destroy_all
11
      puts '... deleting permissions'
12
      Permission.where(:name => Foreman::Plugin.find(:foreman_docker).registered_permissions.map(&:first)).destroy_all
13
      puts '... deleting docker compute resources'
14
      ForemanDocker::Docker.destroy_all
15
      puts 'data from all tables deleted'
16
    end
17

  
18
    tables = [
19
      :containers,
20
      :docker_registries,
21
      :docker_container_wizard_states,
22
      :docker_container_wizard_states_preliminaries,
23
      :docker_container_wizard_states_images,
24
      :docker_container_wizard_states_configurations,
25
      :docker_container_wizard_states_environments,
26
      :docker_parameters
27
    ]
28
    tables.each do |table|
29
      puts "... dropping table #{table}"
30
      ActiveRecord::Migration.drop_table table
31
    end
32

  
33
    puts 'Clean up finished, you can now remove the plugin from your system'
34
  end
35
end
36

  

Also available in: Unified diff