Skip to content

Commit

Permalink
Merge pull request #1272 from dradis/fix/guard-mappings-migration
Browse files Browse the repository at this point in the history
Don't run migrate templates to mappings if the mappings table doesn't exist
  • Loading branch information
caitmich committed Jun 20, 2024
2 parents d9327ba + d539c2d commit 5842f50
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions config/initializers/z_11_plugin_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
# Unless the DB is already migrated, do nothing

Rails.application.reloader.to_prepare do
if (ActiveRecord::Base.connection rescue false) && Configuration.table_exists? && Configuration.paths_templates.exist?
if (ActiveRecord::Base.connection rescue false) &&
Configuration.table_exists? &&
Configuration.paths_templates.exist? &&
Mapping.table_exists?
# ---------------------------------------------------------------- 3.1 Upload
template_dir = Configuration.paths_templates_plugins

# mappings table may not exist when migrating from an old OVA to a new one so we need this guard
Dradis::Plugins::with_feature(:upload).each do |integration|
integration.copy_samples(to: template_dir)
integration.migrate_templates_to_mappings(from: template_dir)
integration.migrate_templates_to_mappings(from: template_dir) if !Rails.env.test?
end

# ---------------------------------------------------------------- 3.2 Export
Expand Down

0 comments on commit 5842f50

Please sign in to comment.