scinote-web/db/migrate/20151215103642_add_foreign_keys_to_tables.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

2017-06-30 16:23:28 +08:00
class AddForeignKeysToTables < ActiveRecord::Migration[4.2]
2016-02-12 23:52:43 +08:00
def change
2017-01-26 23:30:31 +08:00
tables = [:assets, :checklists, :checklist_items, :my_module_groups,
:my_module_tags, :my_modules, :teams, :projects,
2016-02-12 23:52:43 +08:00
:sample_groups, :sample_types, :tables, :tags]
tables.each do |table_name|
add_foreign_key table_name, :users, column: :created_by_id
end
tables = [:assets, :checklists, :checklist_items, :comments,
2017-01-26 23:30:31 +08:00
:custom_fields, :my_modules, :teams, :projects,
2016-02-12 23:52:43 +08:00
:reports, :results, :sample_groups, :sample_types, :samples,
:steps, :tables, :tags]
tables.each do |table_name|
add_foreign_key table_name, :users, column: :last_modified_by_id
end
tables = [:my_modules, :projects, :results]
tables.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
tables = [:sample_my_modules, :user_my_modules,
2017-01-26 23:30:31 +08:00
:user_teams, :user_projects]
2016-02-12 23:52:43 +08:00
tables.each do |table_name|
add_foreign_key table_name, :users, column: :assigned_by_id
end
end
end