Add heartbeat source

This commit is contained in:
Max Wofford 2025-03-05 14:58:24 -05:00
parent 57b00cb950
commit 2417d596ac
3 changed files with 21 additions and 3 deletions

View file

@ -1,6 +1,11 @@
class Heartbeat < ApplicationRecord
before_save :set_fields_hash!
enum :source_type, {
direct_entry: 0,
wakapi_import: 1
}
# This is to prevent Rails from trying to use STI even though we have a "type" column
self.inheritance_column = nil

View file

@ -0,0 +1,13 @@
class Heartbeat < ApplicationRecord
end
class AddSourceToHeartbeats < ActiveRecord::Migration[8.0]
def change
add_column :heartbeats, :source_type, :integer
Heartbeat.update_all(source_type: 1)
change_column_null :heartbeats, :source_type, false
change_column_default :heartbeats, :source_type, to: 0
end
end

6
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_05_061242) do
ActiveRecord::Schema[8.0].define(version: 2025_03_05_194250) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@ -138,8 +138,8 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_05_061242) do
t.boolean "is_write"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "fields_hash", null: false
t.index ["fields_hash"], name: "index_heartbeats_on_fields_hash", unique: true
t.text "fields_hash"
t.integer "source_type", default: 0, null: false
t.index ["user_id"], name: "index_heartbeats_on_user_id"
end