mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 20:19:05 +08:00
17 lines
542 B
Ruby
17 lines
542 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
class AddTeamReferenceToUserAssignments < ActiveRecord::Migration[6.1]
|
||
|
def up
|
||
|
add_reference :user_assignments, :team, index: true, foreign_key: true
|
||
|
|
||
|
UserAssignment.preload(:assignable).find_each do |user_assignment|
|
||
|
team = user_assignment.assignable.is_a?(Team) ? user_assignment.assignable : user_assignment.assignable.team
|
||
|
user_assignment.update_column(:team_id, team.id)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def down
|
||
|
remove_reference :user_assignments, :team, index: true, foreign_key: true
|
||
|
end
|
||
|
end
|