Class: Dbwatcher::Storage::Api::SessionAPI
- Includes:
- Concerns::TableAnalyzer
- Defined in:
- lib/dbwatcher/storage/api/session_api.rb
Instance Method Summary collapse
-
#all ⇒ Array<Hash>
Get all sessions.
-
#by_name(pattern) ⇒ SessionAPI
Filter sessions by name pattern.
-
#by_status(status) ⇒ SessionAPI
Filter sessions by status.
-
#diagram_data(session_id, diagram_type = "database_tables") ⇒ Hash
Generate diagram data for a session.
-
#find(id) ⇒ Session?
Find a specific session by ID.
-
#most_active(limit: 10) ⇒ Array<Hash>
Get the most active sessions (by change count).
-
#recent(days: 7) ⇒ SessionAPI
Filter to recent sessions.
-
#summary(session_id) ⇒ Hash
Get comprehensive session analysis including tables and relationships.
-
#tables_summary(session_id) ⇒ Hash
Get tables summary for a session.
-
#with_changes ⇒ SessionAPI
Filter sessions that have changes.
-
#with_table_analysis ⇒ Array<Hash>
Get sessions with table analysis.
Methods included from Concerns::TableAnalyzer
#build_tables_summary, #extract_table_name, #process_session_changes
Methods inherited from BaseAPI
#create, #initialize, #limit, #where
Methods included from Concerns::DataNormalizer
#extract_value, #normalize_change, #normalize_hash_keys, #normalize_operation, #normalize_record_id, #normalize_session_data, #normalize_table_name, #normalize_timestamp
Constructor Details
This class inherits a constructor from Dbwatcher::Storage::Api::BaseAPI
Instance Method Details
#all ⇒ Array<Hash>
Get all sessions
25 26 27 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 25 def all apply_filters(storage.all) end |
#by_name(pattern) ⇒ SessionAPI
Filter sessions by name pattern
59 60 61 62 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 59 def by_name(pattern) filters[:name_pattern] = pattern self end |
#by_status(status) ⇒ SessionAPI
Filter sessions by status
50 51 52 53 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 50 def by_status(status) filters[:status] = status.to_s self end |
#diagram_data(session_id, diagram_type = "database_tables") ⇒ Hash
Generate diagram data for a session
126 127 128 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 126 def diagram_data(session_id, diagram_type = "database_tables") Dbwatcher::Services::DiagramSystem.generate(session_id, diagram_type) end |
#find(id) ⇒ Session?
Find a specific session by ID
18 19 20 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 18 def find(id) storage.load(id) end |
#most_active(limit: 10) ⇒ Array<Hash>
Get the most active sessions (by change count)
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 82 def most_active(limit: 10) sessions_with_counts = all.map do |session_info| session = find(safe_extract(session_info, :id)) change_count = session ? session.changes.length : 0 session_info.merge(change_count: change_count) end sessions_with_counts .sort_by { |s| -s[:change_count] } .first(limit) end |
#recent(days: 7) ⇒ SessionAPI
Filter to recent sessions
33 34 35 36 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 33 def recent(days: 7) cutoff = Time.now - (days * 24 * 60 * 60) where(started_after: cutoff) end |
#summary(session_id) ⇒ Hash
Get comprehensive session analysis including tables and relationships
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 98 def summary(session_id) session = find(session_id) return { error: "Session not found" } unless session { tables_summary: tables_summary(session_id), total_changes: session.changes&.count || 0, session_metadata: (session) } end |
#tables_summary(session_id) ⇒ Hash
Get tables summary for a session
113 114 115 116 117 118 119 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 113 def tables_summary(session_id) session = find(session_id) return { error: "Session not found" } unless session analyzer = Dbwatcher::Services::Analyzers::TableSummaryBuilder.new(session) analyzer.call end |
#with_changes ⇒ SessionAPI
Filter sessions that have changes
41 42 43 44 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 41 def with_changes filters[:has_changes] = true self end |
#with_table_analysis ⇒ Array<Hash>
Get sessions with table analysis
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dbwatcher/storage/api/session_api.rb', line 67 def with_table_analysis all.map do |session_info| session = find(safe_extract(session_info, :id)) next session_info unless session session_info.merge( tables_summary: build_tables_summary(session) ) end.compact end |