diff --git a/db/migrate/20150525075550_update_certs_add_cn_from_csr.rb b/db/migrate/20150525075550_update_certs_add_cn_from_csr.rb new file mode 100644 index 000000000..505d475b9 --- /dev/null +++ b/db/migrate/20150525075550_update_certs_add_cn_from_csr.rb @@ -0,0 +1,12 @@ +class UpdateCertsAddCnFromCsr < ActiveRecord::Migration + def change + Certificate.all.each do |x| + if x.crt.blank? && x.csr.present? + pc = x.parsed_crt.try(:subject).try(:to_s) || '' + cn = pc.scan(/\/CN=(.+)/).flatten.first + x.common_name = cn.split('/').first + end + x.save + end + end +end