scinote-web/db/migrate/20161011074804_add_current_organization_to_user.rb
2017-01-26 16:30:31 +01:00

17 lines
388 B
Ruby

class AddCurrentOrganizationToUser < ActiveRecord::Migration
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