Add raw_data to heartbeats

This commit is contained in:
Max Wofford
2025-05-09 12:32:58 -04:00
parent a3c885463f
commit fdb7f3e211
4 changed files with 12 additions and 4 deletions

View File

@@ -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)
}
{

View File

@@ -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

View File

@@ -0,0 +1,5 @@
class AddRawDataToHeartbeats < ActiveRecord::Migration[8.0]
def change
add_column :heartbeats, :raw_data, :jsonb
end
end

3
db/schema.rb generated
View File

@@ -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)"