Rename contacts.copy_from_id to original_id

Add association

#660
This commit is contained in:
Artur Beljajev 2018-01-23 17:49:03 +02:00
parent a5db4e3bfb
commit 44332ffb1f
4 changed files with 11 additions and 3 deletions

View file

@ -57,7 +57,7 @@ module Concerns::Domain::Transferable
oc = c.deep_clone oc = c.deep_clone
oc.code = nil oc.code = nil
oc.registrar_id = registrar_id oc.registrar_id = registrar_id
oc.copy_from_id = c.id oc.original = c
oc.generate_code oc.generate_code
oc.remove_address unless Contact.address_processing? oc.remove_address unless Contact.address_processing?
oc.save!(validate: false) oc.save!(validate: false)

View file

@ -3,6 +3,7 @@ class Contact < ActiveRecord::Base
include EppErrors include EppErrors
include UserEvents include UserEvents
belongs_to :original, class_name: self.name
belongs_to :registrar, required: true belongs_to :registrar, required: true
has_many :domain_contacts has_many :domain_contacts
has_many :domains, through: :domain_contacts has_many :domains, through: :domain_contacts

View file

@ -0,0 +1,5 @@
class RenameContactsCopyFromIdToOriginalId < ActiveRecord::Migration
def change
rename_column :contacts, :copy_from_id, :original_id
end
end

View file

@ -668,7 +668,7 @@ CREATE TABLE contacts (
statuses character varying[] DEFAULT '{}'::character varying[], statuses character varying[] DEFAULT '{}'::character varying[],
status_notes hstore, status_notes hstore,
legacy_history_id integer, legacy_history_id integer,
copy_from_id integer, original_id integer,
ident_updated_at timestamp without time zone, ident_updated_at timestamp without time zone,
upid integer, upid integer,
up_date timestamp without time zone up_date timestamp without time zone
@ -4489,7 +4489,7 @@ ALTER TABLE ONLY account_activities
-- --
ALTER TABLE ONLY contacts 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 ('20180123124342');
INSERT INTO schema_migrations (version) VALUES ('20180123154407');