lecture-attendance-manager/db/migrate/20231007144716_make_tracked_time_entry_polymorphic.rb
Joshua Coles 6a2f053bb6 Added WorkItems as a new subject for TrackedTimeEntries.
- Made TrackedTimeEntries polymorphic to belong to both Lecture and WorkItems models
- Added associated migrations for existing data
- Added to administrate UI
2023-10-07 15:53:31 +01:00

20 lines
482 B
Ruby

class MakeTrackedTimeEntryPolymorphic < ActiveRecord::Migration[7.1]
def change
add_reference :tracked_time_entries, :subject, polymorphic: true
reversible do |dir|
dir.up do
TrackedTimeEntry.all.each do |entry|
entry.update!(subject: Lecture.find(entry.lecture_id))
end
end
dir.down do
TrackedTimeEntry.all.each do |entry|
entry.update!(lecture_id: entry.subject_id)
end
end
end
end
end