From c704f4894a16ac45ed8c719db609316a3bb45b13 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 5 May 2015 14:22:44 +0300 Subject: [PATCH] Update all contact code to upcase --- app/controllers/epp/contacts_controller.rb | 2 +- app/models/contact.rb | 2 +- app/models/epp/contact.rb | 1 + .../20150505111437_upcase_all_contact_codes.rb | 14 ++++++++++++++ db/schema.rb | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20150505111437_upcase_all_contact_codes.rb diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 697cfdb18..78f1a6c22 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -59,7 +59,7 @@ class Epp::ContactsController < EppController end def find_contact - code = params[:parsed_frame].css('id').text.strip + code = params[:parsed_frame].css('id').text.strip.upcase @contact = Epp::Contact.find_by(code: code) if @contact.blank? diff --git a/app/models/contact.rb b/app/models/contact.rb index 91e047b98..ce36d9676 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -112,7 +112,7 @@ class Contact < ActiveRecord::Base end def generate_code - self.code = SecureRandom.hex(4) if code.blank? || code_overwrite_allowed + self.code = SecureRandom.hex(4).upcase if code.blank? || code_overwrite_allowed end def generate_auth_info diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index f8a9e691d..dd3a06f51 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -59,6 +59,7 @@ class Epp::Contact < Contact prefix = custom_code.split(':').first custom_code = "#{registrar.code}:#{custom_code}" if prefix != registrar.code custom_code = nil if custom_code == registrar.code + custom_code.upcase! if custom_code.present? end super( diff --git a/db/migrate/20150505111437_upcase_all_contact_codes.rb b/db/migrate/20150505111437_upcase_all_contact_codes.rb new file mode 100644 index 000000000..c237adfbd --- /dev/null +++ b/db/migrate/20150505111437_upcase_all_contact_codes.rb @@ -0,0 +1,14 @@ +class UpcaseAllContactCodes < ActiveRecord::Migration + def change + puts 'Update contact code to upcase...' + @i = 0 + puts @i + Contact.find_in_batches(batch_size: 10000) do |batch| + batch.each do |c| + c.update_column(:code, c.code.upcase) + end + GC.start + puts @i += 10000 + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5285ccc6c..f24eb3a64 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150504110926) do +ActiveRecord::Schema.define(version: 20150505111437) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"