Class: AnalyticsSqlAuditLog
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AnalyticsSqlAuditLog
- Defined in:
- app/models/analytics_sql_audit_log.rb
Overview
Audit trail for SQL tool calls executed by the AI assistant.
Stores normalized SQL metadata, execution outcome, and safety blocks.
== Schema Information
Table name: analytics_sql_audit_logs
Database name: primary
id :bigint not null, primary key
duration_ms :integer default(0), not null
error_message :text
referenced_objects :jsonb not null
returned_column_count :integer default(0), not null
returned_row_count :integer default(0), not null
role :string not null
service_key :string not null
sql_fingerprint :string not null
sql_query :text not null
status :string not null
tool_name :string not null
created_at :datetime not null
updated_at :datetime not null
assistant_conversation_id :bigint
user_id :bigint
Indexes
idx_sql_audit_logs_on_conversation_id (assistant_conversation_id)
idx_sql_audit_logs_service_status_created (service_key,status,created_at)
index_analytics_sql_audit_logs_on_created_at (created_at)
index_analytics_sql_audit_logs_on_sql_fingerprint (sql_fingerprint)
index_analytics_sql_audit_logs_on_status (status)
index_analytics_sql_audit_logs_on_user_id (user_id)
Instance Attribute Summary collapse
- #role ⇒ Object readonly
- #service_key ⇒ Object readonly
- #sql_fingerprint ⇒ Object readonly
- #status ⇒ Object readonly
- #tool_name ⇒ Object readonly
Belongs to collapse
Class Method Summary collapse
-
.blocked ⇒ ActiveRecord::Relation<AnalyticsSqlAuditLog>
A relation of AnalyticsSqlAuditLogs that are blocked.
-
.errored ⇒ ActiveRecord::Relation<AnalyticsSqlAuditLog>
A relation of AnalyticsSqlAuditLogs that are errored.
-
.recent ⇒ ActiveRecord::Relation<AnalyticsSqlAuditLog>
A relation of AnalyticsSqlAuditLogs that are recent.
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#role ⇒ Object (readonly)
39 |
# File 'app/models/analytics_sql_audit_log.rb', line 39 validates :service_key, :tool_name, :role, :status, :sql_fingerprint, presence: true |
#service_key ⇒ Object (readonly)
39 |
# File 'app/models/analytics_sql_audit_log.rb', line 39 validates :service_key, :tool_name, :role, :status, :sql_fingerprint, presence: true |
#sql_fingerprint ⇒ Object (readonly)
39 |
# File 'app/models/analytics_sql_audit_log.rb', line 39 validates :service_key, :tool_name, :role, :status, :sql_fingerprint, presence: true |
#status ⇒ Object (readonly)
39 |
# File 'app/models/analytics_sql_audit_log.rb', line 39 validates :service_key, :tool_name, :role, :status, :sql_fingerprint, presence: true |
#tool_name ⇒ Object (readonly)
39 |
# File 'app/models/analytics_sql_audit_log.rb', line 39 validates :service_key, :tool_name, :role, :status, :sql_fingerprint, presence: true |
Class Method Details
.blocked ⇒ ActiveRecord::Relation<AnalyticsSqlAuditLog>
A relation of AnalyticsSqlAuditLogs that are blocked. Active Record Scope
42 |
# File 'app/models/analytics_sql_audit_log.rb', line 42 scope :blocked, -> { where(status: 'blocked') } |
.errored ⇒ ActiveRecord::Relation<AnalyticsSqlAuditLog>
A relation of AnalyticsSqlAuditLogs that are errored. Active Record Scope
43 |
# File 'app/models/analytics_sql_audit_log.rb', line 43 scope :errored, -> { where(status: 'error') } |
.recent ⇒ ActiveRecord::Relation<AnalyticsSqlAuditLog>
A relation of AnalyticsSqlAuditLogs that are recent. Active Record Scope
41 |
# File 'app/models/analytics_sql_audit_log.rb', line 41 scope :recent, -> { order(created_at: :desc) } |
Instance Method Details
#assistant_conversation ⇒ AssistantConversation
36 |
# File 'app/models/analytics_sql_audit_log.rb', line 36 belongs_to :assistant_conversation, optional: true |
#user ⇒ Party
37 |
# File 'app/models/analytics_sql_audit_log.rb', line 37 belongs_to :user, class_name: 'Party', optional: true |