Enhancement: Move reporting metrics to postgres (#606)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
class Account < ApplicationRecord
|
||||
include Events::Types
|
||||
include Reportable
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
@@ -18,6 +19,7 @@ class Account < ApplicationRecord
|
||||
has_many :users, through: :account_users
|
||||
has_many :inboxes, dependent: :destroy
|
||||
has_many :conversations, dependent: :destroy
|
||||
has_many :messages, dependent: :destroy
|
||||
has_many :contacts, dependent: :destroy
|
||||
has_many :facebook_pages, dependent: :destroy, class_name: '::Channel::FacebookPage'
|
||||
has_many :twitter_profiles, dependent: :destroy, class_name: '::Channel::TwitterProfile'
|
||||
|
||||
9
app/models/concerns/reportable.rb
Normal file
9
app/models/concerns/reportable.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Reportable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_many :events, dependent: :destroy
|
||||
end
|
||||
end
|
||||
33
app/models/event.rb
Normal file
33
app/models/event.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: events
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# value :float
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :integer
|
||||
# conversation_id :integer
|
||||
# inbox_id :integer
|
||||
# user_id :integer
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_events_on_account_id (account_id)
|
||||
# index_events_on_created_at (created_at)
|
||||
# index_events_on_inbox_id (inbox_id)
|
||||
# index_events_on_name (name)
|
||||
# index_events_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class Event < ApplicationRecord
|
||||
validates :account_id, presence: true
|
||||
validates :name, presence: true
|
||||
validates :value, presence: true
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :user, optional: true
|
||||
belongs_to :inbox, optional: true
|
||||
belongs_to :conversation, optional: true
|
||||
end
|
||||
@@ -19,6 +19,8 @@
|
||||
#
|
||||
|
||||
class Inbox < ApplicationRecord
|
||||
include Reportable
|
||||
|
||||
validates :account_id, presence: true
|
||||
|
||||
belongs_to :account
|
||||
|
||||
@@ -20,9 +20,12 @@
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_messages_on_account_id (account_id)
|
||||
# index_messages_on_contact_id (contact_id)
|
||||
# index_messages_on_conversation_id (conversation_id)
|
||||
# index_messages_on_inbox_id (inbox_id)
|
||||
# index_messages_on_source_id (source_id)
|
||||
# index_messages_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
|
||||
@@ -43,6 +43,7 @@ class User < ApplicationRecord
|
||||
include Events::Types
|
||||
include Pubsubable
|
||||
include Rails.application.routes.url_helpers
|
||||
include Reportable
|
||||
|
||||
devise :database_authenticatable,
|
||||
:registerable,
|
||||
|
||||
Reference in New Issue
Block a user