scinote-web/db/migrate/20151215103642_add_foreign_keys_to_tables.rb
2019-08-05 18:22:07 +02:00

29 lines
974 B
Ruby

class AddForeignKeysToTables < ActiveRecord::Migration[4.2]
def change
%i(
assets checklists checklist_items my_module_groups
my_module_tags my_modules teams projects
sample_groups sample_types tables tags
).each do |table_name|
add_foreign_key table_name, :users, column: :created_by_id
end
%i(
assets checklists checklist_items comments
custom_fields my_modules teams projects
reports results sample_groups sample_types samples
steps tables tags
).each do |table_name|
add_foreign_key table_name, :users, column: :last_modified_by_id
end
%i(my_modules projects results).each do |table_name|
add_foreign_key table_name, :users, column: :archived_by_id
add_foreign_key table_name, :users, column: :restored_by_id
end
%i(user_my_modules user_teams user_projects).each do |table_name|
add_foreign_key table_name, :users, column: :assigned_by_id
end
end
end