Merge pull request #1338 from internetee/add-db-constraints

Add database constraints
This commit is contained in:
Timo Võhmar 2019-10-10 12:00:02 +03:00 committed by GitHub
commit fc181d3623
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 149 additions and 28 deletions

View file

@ -0,0 +1,5 @@
class ChangeReservedDomainsNameToNotNull < ActiveRecord::Migration
def change
change_column_null :reserved_domains, :name, false
end
end

View file

@ -0,0 +1,13 @@
class AddReservedDomainsNameUniqConstraint < ActiveRecord::Migration
def up
execute <<-SQL
ALTER TABLE reserved_domains ADD CONSTRAINT uniq_reserved_domains_name UNIQUE (name);
SQL
end
def down
execute <<-SQL
ALTER TABLE reserved_domains DROP CONSTRAINT uniq_reserved_domains_name;
SQL
end
end

View file

@ -0,0 +1,5 @@
class ChangeBlockedDomainsNameToNotNull < ActiveRecord::Migration
def change
change_column_null :blocked_domains, :name, false
end
end

View file

@ -0,0 +1,13 @@
class AddBlockedDomainsNameUniqConstraint < ActiveRecord::Migration
def up
execute <<-SQL
ALTER TABLE blocked_domains ADD CONSTRAINT uniq_blocked_domains_name UNIQUE (name);
SQL
end
def down
execute <<-SQL
ALTER TABLE blocked_domains DROP CONSTRAINT uniq_blocked_domains_name;
SQL
end
end

View file

@ -0,0 +1,5 @@
class RemoveBlockedDomainsNameIndex < ActiveRecord::Migration
def change
remove_index :blocked_domains, name: 'index_blocked_domains_on_name'
end
end

View file

@ -0,0 +1,19 @@
class AddConstraints < ActiveRecord::Migration
def change
change_column_null :registrant_verifications, :domain_name, false
change_column_null :registrant_verifications, :verification_token, false
change_column_null :registrant_verifications, :action, false
change_column_null :registrant_verifications, :domain_id, false
change_column_null :registrant_verifications, :action_type, false
add_foreign_key :registrant_verifications, :domains
change_column_null :zones, :origin, false
change_column_null :zones, :ttl, false
change_column_null :zones, :refresh, false
change_column_null :zones, :retry, false
change_column_null :zones, :expire, false
change_column_null :zones, :minimum_ttl, false
change_column_null :zones, :email, false
change_column_null :zones, :master_nameserver, false
end
end

View file

@ -0,0 +1,6 @@
class AddConstraintsPartIi < ActiveRecord::Migration
def change
change_column_null :white_ips, :registrar_id, false
add_foreign_key :white_ips, :registrars
end
end

View file

@ -0,0 +1,7 @@
class AddConstraintsPartIii < ActiveRecord::Migration
def change
change_column_null :domains, :name, false
change_column_null :domains, :name_puny, false
change_column_null :domains, :name_dirty, false
end
end

View file

@ -525,7 +525,7 @@ CREATE TABLE public.blocked_domains (
updated_at timestamp without time zone,
creator_str character varying,
updator_str character varying,
name character varying
name character varying NOT NULL
);
@ -801,7 +801,7 @@ ALTER SEQUENCE public.domain_transfers_id_seq OWNED BY public.domain_transfers.i
CREATE TABLE public.domains (
id integer NOT NULL,
name character varying,
name character varying NOT NULL,
registrar_id integer NOT NULL,
registered_at timestamp without time zone,
valid_to timestamp without time zone NOT NULL,
@ -809,8 +809,8 @@ CREATE TABLE public.domains (
transfer_code character varying NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
name_dirty character varying,
name_puny character varying,
name_dirty character varying NOT NULL,
name_puny character varying NOT NULL,
period integer,
period_unit character varying(1),
creator_str character varying,
@ -2030,13 +2030,13 @@ ALTER SEQUENCE public.que_jobs_job_id_seq OWNED BY public.que_jobs.job_id;
CREATE TABLE public.registrant_verifications (
id integer NOT NULL,
domain_name character varying,
verification_token character varying,
domain_name character varying NOT NULL,
verification_token character varying NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
action character varying,
domain_id integer,
action_type character varying
action character varying NOT NULL,
domain_id integer NOT NULL,
action_type character varying NOT NULL
);
@ -2123,7 +2123,7 @@ CREATE TABLE public.reserved_domains (
creator_str character varying,
updator_str character varying,
legacy_id integer,
name character varying,
name character varying NOT NULL,
password character varying NOT NULL
);
@ -2285,7 +2285,7 @@ ALTER SEQUENCE public.versions_id_seq OWNED BY public.versions.id;
CREATE TABLE public.white_ips (
id integer NOT NULL,
registrar_id integer,
registrar_id integer NOT NULL,
ipv4 character varying,
ipv6 character varying,
interfaces character varying[],
@ -2356,14 +2356,14 @@ ALTER SEQUENCE public.whois_records_id_seq OWNED BY public.whois_records.id;
CREATE TABLE public.zones (
id integer NOT NULL,
origin character varying,
ttl integer,
refresh integer,
retry integer,
expire integer,
minimum_ttl integer,
email character varying,
master_nameserver character varying,
origin character varying NOT NULL,
ttl integer NOT NULL,
refresh integer NOT NULL,
retry integer NOT NULL,
expire integer NOT NULL,
minimum_ttl integer NOT NULL,
email character varying NOT NULL,
master_nameserver character varying NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
creator_str character varying,
@ -3148,6 +3148,14 @@ ALTER TABLE ONLY public.settings
ADD CONSTRAINT settings_pkey PRIMARY KEY (id);
--
-- Name: uniq_blocked_domains_name; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY public.blocked_domains
ADD CONSTRAINT uniq_blocked_domains_name UNIQUE (name);
--
-- Name: uniq_contact_uuid; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
@ -3164,6 +3172,14 @@ ALTER TABLE ONLY public.domains
ADD CONSTRAINT uniq_domain_uuid UNIQUE (uuid);
--
-- Name: uniq_reserved_domains_name; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY public.reserved_domains
ADD CONSTRAINT uniq_reserved_domains_name UNIQUE (name);
--
-- Name: uniq_uuid; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
@ -3304,13 +3320,6 @@ CREATE INDEX index_account_activities_on_invoice_id ON public.account_activities
CREATE INDEX index_accounts_on_registrar_id ON public.accounts USING btree (registrar_id);
--
-- Name: index_blocked_domains_on_name; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_blocked_domains_on_name ON public.blocked_domains USING btree (name);
--
-- Name: index_certificates_on_api_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
@ -3919,6 +3928,14 @@ ALTER TABLE ONLY public.invoices
ADD CONSTRAINT fk_rails_242b91538b FOREIGN KEY (buyer_id) REFERENCES public.registrars(id);
--
-- Name: fk_rails_36cff3de9c; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.white_ips
ADD CONSTRAINT fk_rails_36cff3de9c FOREIGN KEY (registrar_id) REFERENCES public.registrars(id);
--
-- Name: fk_rails_59c422f73d; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -4023,6 +4040,14 @@ ALTER TABLE ONLY public.account_activities
ADD CONSTRAINT fk_rails_d2cc3c2fa9 FOREIGN KEY (price_id) REFERENCES public.prices(id);
--
-- Name: fk_rails_f41617a0e9; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.registrant_verifications
ADD CONSTRAINT fk_rails_f41617a0e9 FOREIGN KEY (domain_id) REFERENCES public.domains(id);
--
-- Name: invoice_items_invoice_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -4835,5 +4860,21 @@ INSERT INTO schema_migrations (version) VALUES ('20190811202711');
INSERT INTO schema_migrations (version) VALUES ('20190811205406');
INSERT INTO schema_migrations (version) VALUES ('20191004095229');
INSERT INTO schema_migrations (version) VALUES ('20191004103144');
INSERT INTO schema_migrations (version) VALUES ('20191004105643');
INSERT INTO schema_migrations (version) VALUES ('20191004105732');
INSERT INTO schema_migrations (version) VALUES ('20191004110234');
INSERT INTO schema_migrations (version) VALUES ('20191004154844');
INSERT INTO schema_migrations (version) VALUES ('20191005162437');
INSERT INTO schema_migrations (version) VALUES ('20191007123000');
INSERT INTO schema_migrations (version) VALUES ('20191008024334');

View file

@ -1,5 +1,6 @@
shop:
name: shop.test
name_puny: shop.test
name_dirty: shop.test
registrar: bestnames
registrant: john
@ -15,6 +16,7 @@ shop:
airport:
name: airport.test
name_puny: airport.test
name_dirty: airport.test
registrar: bestnames
registrant: john
@ -26,6 +28,7 @@ airport:
library:
name: library.test
name_puny: library.test
name_dirty: library.test
registrar: bestnames
registrant: acme_ltd
@ -37,6 +40,7 @@ library:
metro:
name: metro.test
name_puny: metro.test
name_dirty: metro.test
registrar: goodnames
registrant: jack
@ -48,6 +52,7 @@ metro:
hospital:
name: hospital.test
name_puny: hospital.test
name_dirty: hospital.test
registrar: goodnames
registrant: john
@ -59,6 +64,8 @@ hospital:
invalid:
name: invalid.test
name_puny: invalid.test
name_dirty: invalid.test
transfer_code: 1438d6
valid_to: <%= Time.zone.parse('2010-07-05').utc.to_s(:db) %>
registrar: bestnames

View file

@ -21,9 +21,9 @@ class DomainVersionsTest < ApplicationSystemTestCase
INSERT INTO contacts (id, code, email, auth_info, registrar_id)
VALUES (54, 'test_code', 'test@inbox.test', '8b4d462aa04194ca78840a', #{@registrar.id});
INSERT INTO domains (id, registrar_id, valid_to, registrant_id,
INSERT INTO domains (id, name, name_puny, name_dirty, registrar_id, valid_to, registrant_id,
transfer_code)
VALUES (54, #{@registrar.id}, '2018-06-23T12:14:02.732+03:00', 54, 'transfer_code');
VALUES (54, 'any.test', 'any.test', 'any.test', #{@registrar.id}, '2018-06-23T12:14:02.732+03:00', 54, 'transfer_code');
INSERT INTO log_domains (item_type, item_id, event, whodunnit, object,
object_changes, created_at, session, children)