Improve migration
This commit is contained in:
parent
0e3403636f
commit
9ecb8e4474
1 changed files with 9 additions and 13 deletions
|
@ -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
|
||||||
|
|
Reference in a new issue