mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Added dedicated data migartion #2659
This commit is contained in:
parent
f1ebedc234
commit
b10f62f539
5 changed files with 28 additions and 4 deletions
16
db/data/20150601083516_add_cert_common_name.rb
Normal file
16
db/data/20150601083516_add_cert_common_name.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class AddCertCommonName < ActiveRecord::Migration
|
||||
def self.up
|
||||
Certificate.all.each do |x|
|
||||
if x.crt.blank? && x.csr.present?
|
||||
pc = x.parsed_csr.try(:subject).try(:to_s) || ''
|
||||
cn = pc.scan(/\/CN=(.+)/).flatten.first
|
||||
x.common_name = cn.split('/').first
|
||||
end
|
||||
x.save
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
28
db/data/20150601083800_add_cert_md5.rb
Normal file
28
db/data/20150601083800_add_cert_md5.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
class AddCertMd5 < ActiveRecord::Migration
|
||||
def self.up
|
||||
Certificate.all.each do |x|
|
||||
if x.crt.present? && x.csr.present?
|
||||
x.interface = Certificate::REGISTRAR
|
||||
x.md5 = OpenSSL::Digest::MD5.new(x.parsed_crt.to_der).to_s
|
||||
|
||||
pc = x.parsed_crt.try(:subject).try(:to_s) || ''
|
||||
cn = pc.scan(/\/CN=(.+)/).flatten.first
|
||||
x.common_name = cn.split('/').first
|
||||
elsif x.crt.present? && x.csr.blank?
|
||||
x.interface = Certificate::API
|
||||
x.md5 = OpenSSL::Digest::MD5.new(x.parsed_crt.to_der).to_s
|
||||
|
||||
pc = x.parsed_crt.try(:subject).try(:to_s) || ''
|
||||
cn = pc.scan(/\/CN=(.+)/).flatten.first
|
||||
x.common_name = cn.split('/').first
|
||||
elsif x.crt.blank? && x.csr.present?
|
||||
x.interface = Certificate::REGISTRAR
|
||||
end
|
||||
x.save
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue