Move data migrations from rake tasks to gem

See #1298
This commit is contained in:
Alex Sherman 2020-02-25 14:19:24 +05:00
parent ed27152bb1
commit 4ddbb08e80
19 changed files with 111 additions and 271 deletions

View file

@ -1,16 +1,15 @@
class AddCertCommonName < ActiveRecord::Migration
class AddCertCommonName < ActiveRecord::Migration[5.1]
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
# 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

View file

@ -1,28 +1,27 @@
class AddCertMd5 < ActiveRecord::Migration
class AddCertMd5 < ActiveRecord::Migration[5.1]
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
# 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

View file

@ -1,9 +1,8 @@
class AddRenewSetting < ActiveRecord::Migration
class AddRenewSetting < ActiveRecord::Migration[5.1]
def self.up
Setting.days_to_renew_domain_before_expire = 90
# Setting.days_to_renew_domain_before_expire = 90
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end

View file

@ -1,10 +1,9 @@
class AddExpireSettings < ActiveRecord::Migration
class AddExpireSettings < ActiveRecord::Migration[5.1]
def self.up
Setting.expire_warning_period = 15
Setting.redemption_grace_period = 30
# Setting.expire_warning_period = 15
# Setting.redemption_grace_period = 30
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end

View file

@ -1,15 +1,14 @@
class RefactorDomainStatuses < ActiveRecord::Migration
class RefactorDomainStatuses < ActiveRecord::Migration[5.1]
def self.up
Domain.find_each do |x|
statuses = []
x.domain_statuses.each do |ds|
statuses << ds.value
end
x.update_column('statuses', statuses)
end
# Domain.find_each do |x|
# statuses = []
# x.domain_statuses.each do |ds|
# statuses << ds.value
# end
# x.update_column('statuses', statuses) if x.statuses.blank?
# end
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end

View file

@ -1,15 +1,14 @@
class RefactorContactStatuses < ActiveRecord::Migration
class RefactorContactStatuses < ActiveRecord::Migration[5.1]
def self.up
Contact.find_each do |contact|
statuses = []
contact.depricated_statuses.each do |ds|
statuses << ds.value
end
contact.update_column('statuses', statuses)
end
# Contact.find_each do |contact|
# statuses = []
# contact.depricated_statuses.each do |ds|
# statuses << ds.value
# end
# contact.update_column('statuses', statuses)
# end
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end

View file

@ -0,0 +1,19 @@
class ConvertDomainDeleteDate < ActiveRecord::Migration[5.1]
def up
# processed_domain_count = 0
#
# Domain.transaction do
# Domain.find_each do |domain|
# next unless domain.delete_date
#
# domain.update_columns(delete_date: domain.delete_date + 1.day)
# processed_domain_count += 1
# end
# end
#
# puts "Domains processed: #{processed_domain_count}"
end
def down
end
end

View file

@ -0,0 +1,18 @@
class DeleteOrphanedRegistrantVerifications < ActiveRecord::Migration[5.1]
def up
# orphaned_registrant_verifications = RegistrantVerification.where.not(domain_id: Domain.ids)
# orphaned_registrant_verification_count = orphaned_registrant_verifications.count
# processed_registrant_verification_count = 0
#
# orphaned_registrant_verifications.each do |registrant_verification|
# registrant_verification.destroy!
# processed_registrant_verification_count += 1
# end
#
# puts "Processed: #{processed_registrant_verification_count} out of" \
# " #{orphaned_registrant_verification_count}"
end
def down
end
end

View file

@ -0,0 +1,19 @@
class RegenerateRegistrarReferenceNumbers < ActiveRecord::Migration[5.1]
def up
# processed_registrar_count = 0
#
# Registrar.transaction do
# Registrar.all.each do |registrar|
# next unless registrar.reference_no.start_with?('RF')
#
# registrar.update_columns(reference_no: Billing::ReferenceNo.generate)
# processed_registrar_count += 1
# end
# end
#
# puts "Registrars processed: #{processed_registrar_count}"
end
def down
end
end

2
db/data_schema.rb Normal file
View file

@ -0,0 +1,2 @@
# encoding: UTF-8
DataMigrate::Data.define(version: 20150707103801)