diff --git a/app/controllers/api/hackatime/v1/hackatime_controller.rb b/app/controllers/api/hackatime/v1/hackatime_controller.rb index 5b43ffe..96d9025 100644 --- a/app/controllers/api/hackatime/v1/hackatime_controller.rb +++ b/app/controllers/api/hackatime/v1/hackatime_controller.rb @@ -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 diff --git a/db/migrate/20250315030446_add_ip_address_to_heartbeats.rb b/db/migrate/20250315030446_add_ip_address_to_heartbeats.rb new file mode 100644 index 0000000..5c14c8c --- /dev/null +++ b/db/migrate/20250315030446_add_ip_address_to_heartbeats.rb @@ -0,0 +1,5 @@ +class AddIpAddressToHeartbeats < ActiveRecord::Migration[8.0] + def change + add_column :heartbeats, :ip_address, :inet + end +end diff --git a/db/schema.rb b/db/schema.rb index 75a5cd1..8cac114 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_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"