From 44332ffb1f477550528fe02af1e071257aa2fe83 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 23 Jan 2018 17:49:03 +0200 Subject: [PATCH] Rename `contacts.copy_from_id` to `original_id` Add association #660 --- app/models/concerns/domain/transferable.rb | 2 +- app/models/contact.rb | 1 + ...123154407_rename_contacts_copy_from_id_to_original_id.rb | 5 +++++ db/structure.sql | 6 ++++-- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20180123154407_rename_contacts_copy_from_id_to_original_id.rb diff --git a/app/models/concerns/domain/transferable.rb b/app/models/concerns/domain/transferable.rb index 954370e76..c7b36c4bd 100644 --- a/app/models/concerns/domain/transferable.rb +++ b/app/models/concerns/domain/transferable.rb @@ -57,7 +57,7 @@ module Concerns::Domain::Transferable oc = c.deep_clone oc.code = nil oc.registrar_id = registrar_id - oc.copy_from_id = c.id + oc.original = c oc.generate_code oc.remove_address unless Contact.address_processing? oc.save!(validate: false) diff --git a/app/models/contact.rb b/app/models/contact.rb index 59ead2d77..7edef09ea 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -3,6 +3,7 @@ class Contact < ActiveRecord::Base include EppErrors include UserEvents + belongs_to :original, class_name: self.name belongs_to :registrar, required: true has_many :domain_contacts has_many :domains, through: :domain_contacts diff --git a/db/migrate/20180123154407_rename_contacts_copy_from_id_to_original_id.rb b/db/migrate/20180123154407_rename_contacts_copy_from_id_to_original_id.rb new file mode 100644 index 000000000..347137507 --- /dev/null +++ b/db/migrate/20180123154407_rename_contacts_copy_from_id_to_original_id.rb @@ -0,0 +1,5 @@ +class RenameContactsCopyFromIdToOriginalId < ActiveRecord::Migration + def change + rename_column :contacts, :copy_from_id, :original_id + end +end diff --git a/db/structure.sql b/db/structure.sql index 85377cf65..1ba85fc02 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -668,7 +668,7 @@ CREATE TABLE contacts ( statuses character varying[] DEFAULT '{}'::character varying[], status_notes hstore, legacy_history_id integer, - copy_from_id integer, + original_id integer, ident_updated_at timestamp without time zone, upid integer, up_date timestamp without time zone @@ -4489,7 +4489,7 @@ ALTER TABLE ONLY account_activities -- ALTER TABLE ONLY contacts - ADD CONSTRAINT fk_rails_c107909cf3 FOREIGN KEY (copy_from_id) REFERENCES contacts(id); + ADD CONSTRAINT fk_rails_c107909cf3 FOREIGN KEY (original_id) REFERENCES contacts(id); -- @@ -5060,3 +5060,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180122105335'); INSERT INTO schema_migrations (version) VALUES ('20180123124342'); +INSERT INTO schema_migrations (version) VALUES ('20180123154407'); +