diff --git a/app/jobs/migrate_user_from_hackatime_job.rb b/app/jobs/migrate_user_from_hackatime_job.rb index 40cefb5..21ef8a2 100644 --- a/app/jobs/migrate_user_from_hackatime_job.rb +++ b/app/jobs/migrate_user_from_hackatime_job.rb @@ -67,7 +67,8 @@ class MigrateUserFromHackatimeJob < ApplicationJob cursorpos: heartbeat.cursor_position, project_root_count: heartbeat.project_root_count, is_write: heartbeat.is_write, - source_type: :wakapi_import + source_type: :wakapi_import, + raw_data: heartbeat.attributes.slice(*Heartbeat.indexed_attributes) } { diff --git a/app/models/heartbeat.rb b/app/models/heartbeat.rb index 8544576..2507938 100644 --- a/app/models/heartbeat.rb +++ b/app/models/heartbeat.rb @@ -1,5 +1,6 @@ class Heartbeat < ApplicationRecord before_save :set_fields_hash! + before_save :set_raw_data! include Heartbeatable include TimeRangeFilterable @@ -107,8 +108,8 @@ class Heartbeat < ApplicationRecord %w[user_id branch category dependencies editor entity language machine operating_system project type user_agent line_additions line_deletions lineno lines cursorpos project_root_count time is_write] end - def set_raw_data - self.raw_data = self.attributes.slice(*self.class.indexed_attributes) + def set_raw_data! + self.raw_data ||= self.attributes.slice(*self.class.indexed_attributes) end def soft_delete diff --git a/db/migrate/20250509160228_add_raw_data_to_heartbeats.rb b/db/migrate/20250509160228_add_raw_data_to_heartbeats.rb new file mode 100644 index 0000000..08699b5 --- /dev/null +++ b/db/migrate/20250509160228_add_raw_data_to_heartbeats.rb @@ -0,0 +1,5 @@ +class AddRawDataToHeartbeats < ActiveRecord::Migration[8.0] + def change + add_column :heartbeats, :raw_data, :jsonb + end +end diff --git a/db/schema.rb b/db/schema.rb index b42a820..884139f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_05_07_211848) do +ActiveRecord::Schema[8.0].define(version: 2025_05_09_160228) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -208,6 +208,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_05_07_211848) do t.inet "ip_address" t.integer "ysws_program", default: 0, null: false t.datetime "deleted_at" + t.jsonb "raw_data" t.index ["category", "time"], name: "index_heartbeats_on_category_and_time" t.index ["fields_hash"], name: "index_heartbeats_on_fields_hash_when_not_deleted", unique: true, where: "(deleted_at IS NULL)" t.index ["user_id", "time"], name: "idx_heartbeats_user_time_active", where: "(deleted_at IS NULL)"