1
0
Fork 0

Improve migration

This commit is contained in:
Alex Kotov 2019-07-22 09:04:26 +05:00
parent 0e3403636f
commit 9ecb8e4474
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -195,19 +195,13 @@ class InitialMigration < ActiveRecord::Migration[6.0]
add_foreign_key :accounts, :contacts_lists add_foreign_key :accounts, :contacts_lists
add_foreign_key :people, :contacts_lists add_foreign_key :people, :contacts_lists
reversible do |dir| constraint :relationships, :dates, <<~SQL
dir.up do
execute <<~SQL
ALTER TABLE relationships ADD CONSTRAINT dates CHECK (
until_date IS NULL OR from_date < until_date until_date IS NULL OR from_date < until_date
);
ALTER TABLE relationships ADD CONSTRAINT role CHECK (
status = 'member' OR role IS NULL
);
SQL SQL
end
end constraint :relationships, :role, <<~SQL
status = 'member' OR role IS NULL
SQL
constraint :accounts, :guest_token, <<~SQL constraint :accounts, :guest_token, <<~SQL
guest_token ~ '^[0-9a-f]{32}$' guest_token ~ '^[0-9a-f]{32}$'
@ -251,7 +245,9 @@ class InitialMigration < ActiveRecord::Migration[6.0]
native_name !~ '[[:space:]]{1,}$' native_name !~ '[[:space:]]{1,}$'
SQL SQL
constraint :federal_subjects, :number, 'number > 0' constraint :federal_subjects, :number, <<~SQL
number > 0
SQL
end end
private private