2017-06-30 16:23:28 +08:00
|
|
|
class AddCurrentOrganizationToUser < ActiveRecord::Migration[4.2]
|
2016-10-11 17:40:14 +08:00
|
|
|
def up
|
2017-01-26 23:30:31 +08:00
|
|
|
add_column :users, :current_team_id, :integer
|
|
|
|
add_foreign_key :users, :teams, column: :current_team_id
|
2016-10-11 17:40:14 +08:00
|
|
|
|
|
|
|
User.find_each do |user|
|
2017-01-26 23:30:31 +08:00
|
|
|
if user.teams.count > 0
|
|
|
|
user.update(current_team_id: user.teams.first.id)
|
2016-10-18 18:52:14 +08:00
|
|
|
end
|
2016-10-11 17:40:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2017-01-26 23:30:31 +08:00
|
|
|
remove_column :users, :current_team_id
|
2016-10-11 17:40:14 +08:00
|
|
|
end
|
|
|
|
end
|