Add database constraints

This commit is contained in:
Artur Beljajev 2019-10-04 13:28:25 +03:00
parent 840f1db5c9
commit ba33f5740e
10 changed files with 345 additions and 225 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,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

File diff suppressed because it is too large Load diff

View file

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

View file

@ -21,9 +21,9 @@ class DomainVersionsTest < ApplicationSystemTestCase
INSERT INTO contacts (id, code, email, auth_info, registrar_id) INSERT INTO contacts (id, code, email, auth_info, registrar_id)
VALUES (54, 'test_code', 'test@inbox.test', '8b4d462aa04194ca78840a', #{@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) 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, INSERT INTO log_domains (item_type, item_id, event, whodunnit, object,
object_changes, created_at, session, children) object_changes, created_at, session, children)