dbviewer 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/dbviewer/api/tables_controller.rb +55 -0
- data/app/views/dbviewer/tables/index.html.erb +1 -7
- data/app/views/dbviewer/tables/show.html.erb +1070 -2
- data/app/views/layouts/dbviewer/application.html.erb +4 -0
- data/app/views/layouts/dbviewer/shared/_sidebar.html.erb +95 -113
- data/config/routes.rb +3 -0
- data/lib/dbviewer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d46526c59b9c355c9e717e76ebe81299bbdb051be58fb1b789fbe2fa1c50c0e4
|
4
|
+
data.tar.gz: 713277fda9b00b0fe4a48b2e8324632f2c7920b25cbaad369afe2d159c2bcf29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77444f6cf1b7d847d114bdef9f965d9c90e4e216666db1fccb7de5652f92950cae7793bab07da982e473517f4c350d0dc186e094291138258c9a589de983bf5c
|
7
|
+
data.tar.gz: fc6801c693d632bf8a4bfe26d0aa4b0614ba8570867cf14575f279813c2b8599e5f3288f1bc0175d2db108d62ec2362d484c47a2e0059d5eb28c1a4d4a091d52
|
@@ -16,6 +16,61 @@ module Dbviewer
|
|
16
16
|
render_success(total_relationships: total_relationships)
|
17
17
|
end
|
18
18
|
|
19
|
+
def relationship_counts
|
20
|
+
table_name = params[:id]
|
21
|
+
record_id = params[:record_id]
|
22
|
+
|
23
|
+
unless table_name.present? && record_id.present?
|
24
|
+
render_error("Table name and record ID are required", 400)
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
# Get table metadata to find relationships
|
30
|
+
metadata = fetch_table_metadata(table_name)
|
31
|
+
|
32
|
+
unless metadata
|
33
|
+
render_error("Table not found", 404)
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
# Get reverse foreign keys (has_many relationships)
|
38
|
+
reverse_foreign_keys = metadata.dig(:reverse_foreign_keys) || []
|
39
|
+
|
40
|
+
relationship_counts = reverse_foreign_keys.map do |rel|
|
41
|
+
begin
|
42
|
+
# Count records in the related table that reference this record
|
43
|
+
count_query = "SELECT COUNT(*) as count FROM #{rel[:from_table]} WHERE #{rel[:column]} = ?"
|
44
|
+
result = database_manager.connection.exec_query(count_query, "Count Query", [ record_id ])
|
45
|
+
count = result.rows.first&.first || 0
|
46
|
+
|
47
|
+
{
|
48
|
+
table: rel[:from_table],
|
49
|
+
foreign_key: rel[:column],
|
50
|
+
count: count.to_i
|
51
|
+
}
|
52
|
+
rescue => e
|
53
|
+
Rails.logger.error "Error counting relationships for #{rel[:from_table]}: #{e.message}"
|
54
|
+
{
|
55
|
+
table: rel[:from_table],
|
56
|
+
foreign_key: rel[:column],
|
57
|
+
count: 0,
|
58
|
+
error: e.message
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
render_success({
|
64
|
+
table_name: table_name,
|
65
|
+
record_id: record_id,
|
66
|
+
relationships: relationship_counts
|
67
|
+
})
|
68
|
+
rescue => e
|
69
|
+
Rails.logger.error "Error fetching relationship counts: #{e.message}"
|
70
|
+
render_error("Error fetching relationship counts: #{e.message}", 500)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
19
74
|
private
|
20
75
|
|
21
76
|
def fetch_tables_count
|
@@ -40,13 +40,7 @@
|
|
40
40
|
<% @tables.each do |table| %>
|
41
41
|
<tr>
|
42
42
|
<td class="fw-medium">
|
43
|
-
|
44
|
-
# Include creation filter params in table links
|
45
|
-
filter_params = {}
|
46
|
-
filter_params[:creation_filter_start] = session[:creation_filter_start] if session[:creation_filter_start].present?
|
47
|
-
filter_params[:creation_filter_end] = session[:creation_filter_end] if session[:creation_filter_end].present?
|
48
|
-
%>
|
49
|
-
<%= link_to table[:name], table_path(table[:name], filter_params), class: "text-decoration-none" %>
|
43
|
+
<%= link_to table[:name], table_path(table[:name]), class: "text-decoration-none" %>
|
50
44
|
</td>
|
51
45
|
<td class="text-end">
|
52
46
|
<span class="badge bg-secondary-subtle"><%= table[:record_count] %></span>
|