1
0
Fork 0

Organize migration

This commit is contained in:
Alex Kotov 2019-07-26 06:58:07 +05:00
parent 84085fb3ba
commit c0996f90d3
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -2,6 +2,15 @@
class InitialMigration < ActiveRecord::Migration[6.0]
def change
change_types
change_functions
change_tables
change_constraints
end
private
def change_types
enum :sex, %i[male female]
enum :relationship_status, %i[supporter excluded member]
@ -17,7 +26,9 @@ class InitialMigration < ActiveRecord::Migration[6.0]
aid_at_2014_elections
aid_at_2015_elections
]
end
def change_functions
func :is_guest_token, <<~SQL
(str text) RETURNS boolean IMMUTABLE LANGUAGE plpgsql AS
$$
@ -73,7 +84,9 @@ class InitialMigration < ActiveRecord::Migration[6.0]
END;
$$;
SQL
end
def change_tables
create_table :contacts_lists do |t|
t.timestamps null: false
end
@ -261,7 +274,9 @@ class InitialMigration < ActiveRecord::Migration[6.0]
t.index %i[person_id from_date], unique: true
end
end
def change_constraints
constraint :relationships, :dates, <<~SQL
until_date IS NULL OR from_date < until_date
SQL
@ -363,8 +378,6 @@ class InitialMigration < ActiveRecord::Migration[6.0]
SQL
end
private
def func(name, sql)
reversible do |dir|
dir.up do