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
Generated
+4 -4
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2023_10_07_144031) do
ActiveRecord::Schema[7.1].define(version: 2023_10_07_145018) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -50,14 +50,15 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_07_144031) do
end
create_table "tracked_time_entries", force: :cascade do |t|
t.bigint "lecture_id", null: false
t.integer "kind"
t.jsonb "toggl_data"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "associated_toggl_entry_id", null: false
t.string "subject_type", null: false
t.bigint "subject_id", null: false
t.index ["associated_toggl_entry_id"], name: "index_tracked_time_entries_on_associated_toggl_entry_id", unique: true
t.index ["lecture_id"], name: "index_tracked_time_entries_on_lecture_id"
t.index ["subject_type", "subject_id"], name: "index_tracked_time_entries_on_subject"
end
create_table "work_items", force: :cascade do |t|
@@ -70,6 +71,5 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_07_144031) do
end
add_foreign_key "recordings", "courses"
add_foreign_key "tracked_time_entries", "lectures"
add_foreign_key "work_items", "courses"
end