scinote-web/db/migrate/20161011074804_add_current_organization_to_user.rb
2017-06-30 10:23:28 +02:00

16 lines
393 B
Ruby

class AddCurrentOrganizationToUser < ActiveRecord::Migration[4.2]
def up
add_column :users, :current_team_id, :integer
add_foreign_key :users, :teams, column: :current_team_id
User.find_each do |user|
if user.teams.count > 0
user.update(current_team_id: user.teams.first.id)
end
end
end
def down
remove_column :users, :current_team_id
end
end