mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +02:00
Add uniquie constraints to domain_contacts & nameservers
This commit is contained in:
parent
c20be4e029
commit
68833e11ab
4 changed files with 65 additions and 12 deletions
|
@ -0,0 +1,36 @@
|
||||||
|
class AddUniqueConstraintsToDomainObjects < ActiveRecord::Migration[6.0]
|
||||||
|
def up
|
||||||
|
|
||||||
|
execute <<-SQL
|
||||||
|
alter table domain_contacts
|
||||||
|
drop constraint if exists uniq_contact_of_type_per_domain;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<-SQL
|
||||||
|
alter table nameservers
|
||||||
|
drop constraint if exists uniq_hostname_per_domain;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<-SQL
|
||||||
|
alter table domain_contacts
|
||||||
|
add constraint uniq_contact_of_type_per_domain unique (domain_id, type, contact_id);
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<-SQL
|
||||||
|
alter table nameservers
|
||||||
|
add constraint uniq_hostname_per_domain unique (domain_id, hostname);
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
execute <<-SQL
|
||||||
|
alter table domain_contacts
|
||||||
|
drop constraint if exists uniq_contact_of_type_per_domain;
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<-SQL
|
||||||
|
alter table nameservers
|
||||||
|
drop constraint if exists uniq_hostname_per_domain;
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
end
|
|
@ -3195,7 +3195,15 @@ ALTER TABLE ONLY public.blocked_domains
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: uniq_contact_uuid; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
-- Name: domain_contacts uniq_contact_of_type_per_domain; Type: CONSTRAINT; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
ALTER TABLE ONLY public.domain_contacts
|
||||||
|
ADD CONSTRAINT uniq_contact_of_type_per_domain UNIQUE (domain_id, type, contact_id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: contacts uniq_contact_uuid; Type: CONSTRAINT; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
ALTER TABLE ONLY public.contacts
|
ALTER TABLE ONLY public.contacts
|
||||||
|
@ -3203,7 +3211,7 @@ ALTER TABLE ONLY public.contacts
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: uniq_domain_uuid; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
-- Name: domains uniq_domain_uuid; Type: CONSTRAINT; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
ALTER TABLE ONLY public.domains
|
ALTER TABLE ONLY public.domains
|
||||||
|
@ -3211,7 +3219,15 @@ ALTER TABLE ONLY public.domains
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: uniq_reserved_domains_name; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
-- Name: nameservers uniq_hostname_per_domain; Type: CONSTRAINT; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
ALTER TABLE ONLY public.nameservers
|
||||||
|
ADD CONSTRAINT uniq_hostname_per_domain UNIQUE (domain_id, hostname);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: reserved_domains uniq_reserved_domains_name; Type: CONSTRAINT; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
ALTER TABLE ONLY public.reserved_domains
|
ALTER TABLE ONLY public.reserved_domains
|
||||||
|
@ -3219,7 +3235,7 @@ ALTER TABLE ONLY public.reserved_domains
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: uniq_uuid; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
-- Name: auctions uniq_uuid; Type: CONSTRAINT; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
ALTER TABLE ONLY public.auctions
|
ALTER TABLE ONLY public.auctions
|
||||||
|
@ -4535,6 +4551,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20200505150413'),
|
('20200505150413'),
|
||||||
('20200518104105'),
|
('20200518104105'),
|
||||||
('20200529115011'),
|
('20200529115011'),
|
||||||
('20200630081231');
|
('20200630081231'),
|
||||||
|
('20200714115338');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ class ContactTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_linked_when_in_use_as_domain_contact
|
def test_linked_when_in_use_as_domain_contact
|
||||||
Domain.update_all(registrant_id: contacts(:william).id)
|
Domain.update_all(registrant_id: contacts(:william).id)
|
||||||
DomainContact.update_all(contact_id: @contact.id)
|
DomainContact.first.update(contact_id: @contact.id)
|
||||||
|
|
||||||
assert @contact.linked?
|
assert @contact.linked?
|
||||||
end
|
end
|
||||||
|
|
|
@ -134,9 +134,9 @@ class DomainTest < ActiveSupport::TestCase
|
||||||
contact = contacts(:john)
|
contact = contacts(:john)
|
||||||
|
|
||||||
domain.admin_contacts << contact
|
domain.admin_contacts << contact
|
||||||
domain.admin_contacts << contact
|
assert_raise ActiveRecord::RecordNotUnique do
|
||||||
|
domain.admin_contacts << contact
|
||||||
assert domain.invalid?
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_when_the_same_tech_contact_is_linked_twice
|
def test_invalid_when_the_same_tech_contact_is_linked_twice
|
||||||
|
@ -144,9 +144,9 @@ class DomainTest < ActiveSupport::TestCase
|
||||||
contact = contacts(:john)
|
contact = contacts(:john)
|
||||||
|
|
||||||
domain.tech_contacts << contact
|
domain.tech_contacts << contact
|
||||||
domain.tech_contacts << contact
|
assert_raise ActiveRecord::RecordNotUnique do
|
||||||
|
domain.tech_contacts << contact
|
||||||
assert domain.invalid?
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_validates_name_server_count_when_name_servers_are_required
|
def test_validates_name_server_count_when_name_servers_are_required
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue