2020-08-17 17:09:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class RawUsageData < ApplicationRecord
|
2022-05-05 14:08:40 -04:00
|
|
|
REPORTING_CADENCE = 7.days.freeze
|
|
|
|
|
2020-08-17 17:09:56 -04:00
|
|
|
validates :payload, presence: true
|
|
|
|
validates :recorded_at, presence: true, uniqueness: true
|
|
|
|
|
2022-05-05 14:08:40 -04:00
|
|
|
scope :for_current_reporting_cycle, -> do
|
|
|
|
where('created_at >= ?', REPORTING_CADENCE.ago.beginning_of_day)
|
|
|
|
.order(created_at: :desc)
|
|
|
|
end
|
|
|
|
|
2021-03-25 17:09:13 -04:00
|
|
|
def update_version_metadata!(usage_data_id:)
|
|
|
|
self.update_columns(sent_at: Time.current, version_usage_data_id_value: usage_data_id)
|
2020-08-17 17:09:56 -04:00
|
|
|
end
|
|
|
|
end
|