Class: ValidMdmWebVulnParams

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
db/migrate/20130515172727_valid_mdm_web_vuln_params.rb

Instance Method Summary collapse

Instance Method Details

#downvoid

This method returns an undefined value.

Don't put back the bad format because there's not way to figure our which of the [] were '' before #up and which were [] before #up.



6
7
# File 'db/migrate/20130515172727_valid_mdm_web_vuln_params.rb', line 6

def down
end

#upvoid

This method returns an undefined value.

Changes any Mdm::WebVuln#params with value '' to value [].



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'db/migrate/20130515172727_valid_mdm_web_vuln_params.rb', line 12

def up
  # Can't search serialized columns, so have to load all the Mdm::WebVulns in memory
  Mdm::WebVuln.find_each do |web_vuln|
    if web_vuln.invalid?
      # cast nil, '' and {} to correct [].
      if web_vuln.params.blank?
        web_vuln.params = []
      end

      # If its still invalid have to destroy the Mdm::WebVuln or a different export error could occur.
      if web_vuln.invalid?
        web_vuln.destroy
      else
        web_vuln.save!
      end
    end
  end
end