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
This commit is contained in:
2023-10-07 15:53:31 +01:00
parent f121c990e8
commit 6a2f053bb6
11 changed files with 158 additions and 8 deletions
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,7 @@
class RemoveLectureAssociation < ActiveRecord::Migration[7.1]
def change
remove_reference :tracked_time_entries, :lecture, null: false, foreign_key: true
change_column_null :tracked_time_entries, :subject_id, false
change_column_null :tracked_time_entries, :subject_type, false
end
end