Class: AnalyticsSqlAuditLog

Inherits:
ApplicationRecord show all
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

Belongs to collapse

Class Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#roleObject (readonly)



39
# File 'app/models/analytics_sql_audit_log.rb', line 39

validates :service_key, :tool_name, :role, :status, :sql_fingerprint, presence: true

#service_keyObject (readonly)



39
# File 'app/models/analytics_sql_audit_log.rb', line 39

validates :service_key, :tool_name, :role, :status, :sql_fingerprint, presence: true

#sql_fingerprintObject (readonly)



39
# File 'app/models/analytics_sql_audit_log.rb', line 39

validates :service_key, :tool_name, :role, :status, :sql_fingerprint, presence: true

#statusObject (readonly)



39
# File 'app/models/analytics_sql_audit_log.rb', line 39

validates :service_key, :tool_name, :role, :status, :sql_fingerprint, presence: true

#tool_nameObject (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

.blockedActiveRecord::Relation<AnalyticsSqlAuditLog>

A relation of AnalyticsSqlAuditLogs that are blocked. Active Record Scope

Returns:

See Also:



42
# File 'app/models/analytics_sql_audit_log.rb', line 42

scope :blocked, -> { where(status: 'blocked') }

.erroredActiveRecord::Relation<AnalyticsSqlAuditLog>

A relation of AnalyticsSqlAuditLogs that are errored. Active Record Scope

Returns:

See Also:



43
# File 'app/models/analytics_sql_audit_log.rb', line 43

scope :errored, -> { where(status: 'error') }

.recentActiveRecord::Relation<AnalyticsSqlAuditLog>

A relation of AnalyticsSqlAuditLogs that are recent. Active Record Scope

Returns:

See Also:



41
# File 'app/models/analytics_sql_audit_log.rb', line 41

scope :recent, -> { order(created_at: :desc) }

Instance Method Details

#assistant_conversationAssistantConversation



36
# File 'app/models/analytics_sql_audit_log.rb', line 36

belongs_to :assistant_conversation, optional: true

#userParty

Returns:

See Also:



37
# File 'app/models/analytics_sql_audit_log.rb', line 37

belongs_to :user, class_name: 'Party', optional: true