Add ip address to heartbeats

This commit is contained in:
Max Wofford
2025-03-14 23:07:08 -04:00
parent 1491c80e40
commit 8c5a6434b7
3 changed files with 11 additions and 2 deletions

View File

@@ -61,7 +61,11 @@ class Api::Hackatime::V1::HackatimeController < ApplicationController
source_type = :test_entry
end
attrs = heartbeat.merge({ user_id: @user.id, source_type: source_type })
attrs = heartbeat.merge({
user_id: @user.id,
source_type: source_type,
ip_address: request.remote_ip
})
new_heartbeat = Heartbeat.find_or_create_by(attrs)
results << [ new_heartbeat.attributes, 201 ]
rescue => e

View File

@@ -0,0 +1,5 @@
class AddIpAddressToHeartbeats < ActiveRecord::Migration[8.0]
def change
add_column :heartbeats, :ip_address, :inet
end
end

2
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_03_13_205725) do
ActiveRecord::Schema[8.0].define(version: 2025_03_14_153542) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"