scinote-web/db/migrate/20161011074804_add_current_organization_to_user.rb

17 lines
393 B
Ruby
Raw Normal View History

2017-06-30 16:23:28 +08:00
class AddCurrentOrganizationToUser < ActiveRecord::Migration[4.2]
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
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
end
end
def down
2017-01-26 23:30:31 +08:00
remove_column :users, :current_team_id
end
end