Class: PgInsights::Generators::CleanGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/pg_insights/clean_generator.rb

Instance Method Summary collapse

Instance Method Details

#remove_initializerObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/pg_insights/clean_generator.rb', line 25

def remove_initializer
  initializer_path = "config/initializers/pg_insights.rb"
  initializer_full_path = File.join(destination_root, initializer_path)

  if File.exist?(initializer_full_path)
    puts "Removing PgInsights initializer..."
    remove_file initializer_path
    say_status("removed", initializer_path, :green)
  else
    say_status("skipped", "#{initializer_path} not found", :yellow)
  end
end

#remove_routesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/pg_insights/clean_generator.rb', line 8

def remove_routes
  routes_file = File.join(destination_root, "config", "routes.rb")
  route_to_remove = "mount PgInsights::Engine => '/pg_insights'"

  if File.exist?(routes_file)
    routes_content = File.read(routes_file)
    if routes_content.include?(route_to_remove)
      puts "Removing PgInsights engine mount from routes..."
      updated_content = routes_content.gsub(/^\s*#{Regexp.escape(route_to_remove)}\s*\n?/, "")
      File.write(routes_file, updated_content)
      say_status("removed", "PgInsights engine mount from config/routes.rb", :green)
    else
      say_status("skipped", "PgInsights engine mount not found in config/routes.rb", :yellow)
    end
  end
end

#show_migration_rollback_instructionsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/generators/pg_insights/clean_generator.rb', line 38

def show_migration_rollback_instructions
  puts "\nPgInsights has been cleaned up!"
  puts ""
  puts "To complete the uninstallation, you may also want to:"
  puts "1. Roll back the migrations:"

  migration_files = find_pg_insights_migrations
  if migration_files.any?
    puts "   rails db:rollback STEP=#{migration_files.count}"
    puts ""
    puts "2. Or manually remove the migration files:"
    migration_files.each do |file|
      puts "   rm #{file}"
    end
  else
    puts "   (No PgInsights migrations found)"
  end

  puts ""
  puts "3. Remove any PgInsights data from your database:"
  puts "   rails runner 'PgInsights::Query.destroy_all'"
  puts "   rails runner 'PgInsights::HealthCheckResult.destroy_all'"
  puts ""
  puts "4. If you want to reinstall later, run: rails generate pg_insights:install"
end