rails_lens 0.2.8 → 0.2.9
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/CHANGELOG.md +7 -0
- data/lib/rails_lens/schema/adapters/base.rb +11 -5
- data/lib/rails_lens/schema/adapters/postgresql.rb +63 -13
- data/lib/rails_lens/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7267c551ada38ab296fd1c45e75973f55d77d6aa6a3c7e8e36f672008780202
|
4
|
+
data.tar.gz: da563824b522ce15a6980630211b2a32b55e3ecacb3595695af3fc7661e4e158
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53de6ccec73c0364e3e44d4cfed19dce8f9e18a2ad4a2410e9130a6a0bf49c1289b45e7feec982ff37fd64b4a34d9a496dd781c6838769c9e9a17fb69a1b1ae0
|
7
|
+
data.tar.gz: 60a69e449ad623029f4114e412e6dd12394fd29e00650a910db106620bb414d92a3d3273faa74e7008e2c541d3fb759344aa4ee9b1fa5149c71f4c5ccd710566
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.2.9](https://github.com/seuros/rails_lens/compare/rails_lens/v0.2.8...rails_lens/v0.2.9) (2025-10-05)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* support PostgreSQL schema-qualified table names ([#22](https://github.com/seuros/rails_lens/issues/22)) ([478c6cc](https://github.com/seuros/rails_lens/commit/478c6ccb3f0271dd5bbe182e30057528a1639f4f))
|
9
|
+
|
3
10
|
## [0.2.8](https://github.com/seuros/rails_lens/compare/rails_lens/v0.2.7...rails_lens/v0.2.8) (2025-08-14)
|
4
11
|
|
5
12
|
|
@@ -11,6 +11,12 @@ module RailsLens
|
|
11
11
|
@table_name = table_name
|
12
12
|
end
|
13
13
|
|
14
|
+
# Extract table name without schema prefix for ActiveRecord connection methods
|
15
|
+
# PostgreSQL tables can be schema-qualified (e.g., "cms.posts")
|
16
|
+
def unqualified_table_name
|
17
|
+
@unqualified_table_name ||= table_name.to_s.split('.').last
|
18
|
+
end
|
19
|
+
|
14
20
|
def generate_annotation(_model_class)
|
15
21
|
lines = []
|
16
22
|
lines << "table = \"#{table_name}\""
|
@@ -74,16 +80,16 @@ module RailsLens
|
|
74
80
|
end
|
75
81
|
|
76
82
|
def columns
|
77
|
-
@columns ||= connection.columns(
|
83
|
+
@columns ||= connection.columns(unqualified_table_name)
|
78
84
|
end
|
79
85
|
|
80
86
|
def fetch_indexes
|
81
|
-
connection.indexes(
|
87
|
+
connection.indexes(unqualified_table_name)
|
82
88
|
end
|
83
89
|
|
84
90
|
def fetch_foreign_keys
|
85
91
|
if connection.supports_foreign_keys?
|
86
|
-
connection.foreign_keys(
|
92
|
+
connection.foreign_keys(unqualified_table_name)
|
87
93
|
else
|
88
94
|
[]
|
89
95
|
end
|
@@ -139,7 +145,7 @@ module RailsLens
|
|
139
145
|
end
|
140
146
|
|
141
147
|
def primary_key_name
|
142
|
-
@primary_key_name ||= connection.primary_key(
|
148
|
+
@primary_key_name ||= connection.primary_key(unqualified_table_name)
|
143
149
|
end
|
144
150
|
|
145
151
|
def column_name_width
|
@@ -267,7 +273,7 @@ module RailsLens
|
|
267
273
|
line = ' { '
|
268
274
|
attrs = []
|
269
275
|
attrs << "name = \"#{index.name}\""
|
270
|
-
attrs << "columns = [#{index.columns.map { |c| "\"#{c}\"" }.join(', ')}]"
|
276
|
+
attrs << "columns = [#{Array(index.columns).map { |c| "\"#{c}\"" }.join(', ')}]"
|
271
277
|
attrs << 'unique = true' if index.unique
|
272
278
|
attrs << "type = \"#{index.type}\"" if index.respond_to?(:type) && index.type
|
273
279
|
line += attrs.join(', ')
|
@@ -73,6 +73,50 @@ module RailsLens
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
# Execute block with schema in search_path for ActiveRecord methods
|
77
|
+
def with_schema_in_search_path
|
78
|
+
if schema_name && schema_name != 'public'
|
79
|
+
original_search_path = connection.schema_search_path
|
80
|
+
begin
|
81
|
+
connection.schema_search_path = "#{schema_name}, #{original_search_path}"
|
82
|
+
yield
|
83
|
+
ensure
|
84
|
+
connection.schema_search_path = original_search_path
|
85
|
+
end
|
86
|
+
else
|
87
|
+
yield
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Override to handle schema-qualified table names
|
92
|
+
def columns
|
93
|
+
@columns ||= with_schema_in_search_path do
|
94
|
+
connection.columns(unqualified_table_name)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def fetch_indexes
|
99
|
+
with_schema_in_search_path do
|
100
|
+
connection.indexes(unqualified_table_name)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def fetch_foreign_keys
|
105
|
+
with_schema_in_search_path do
|
106
|
+
if connection.supports_foreign_keys?
|
107
|
+
connection.foreign_keys(unqualified_table_name)
|
108
|
+
else
|
109
|
+
[]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def primary_key_name
|
115
|
+
@primary_key_name ||= with_schema_in_search_path do
|
116
|
+
connection.primary_key(unqualified_table_name)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
76
120
|
def format_column(column)
|
77
121
|
parts = []
|
78
122
|
parts << column.name.ljust(column_name_width)
|
@@ -142,11 +186,13 @@ module RailsLens
|
|
142
186
|
def fetch_check_constraints
|
143
187
|
return [] unless connection.supports_check_constraints?
|
144
188
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
189
|
+
with_schema_in_search_path do
|
190
|
+
connection.check_constraints(unqualified_table_name).map do |constraint|
|
191
|
+
{
|
192
|
+
name: constraint.name,
|
193
|
+
expression: constraint.expression
|
194
|
+
}
|
195
|
+
end
|
150
196
|
end
|
151
197
|
rescue ActiveRecord::StatementInvalid => e
|
152
198
|
# Table doesn't exist or other database error
|
@@ -161,7 +207,9 @@ module RailsLens
|
|
161
207
|
def column_comment(column_name)
|
162
208
|
return nil unless connection.respond_to?(:column_comment)
|
163
209
|
|
164
|
-
|
210
|
+
with_schema_in_search_path do
|
211
|
+
connection.column_comment(unqualified_table_name, column_name)
|
212
|
+
end
|
165
213
|
rescue ActiveRecord::StatementInvalid => e
|
166
214
|
# Table or column doesn't exist
|
167
215
|
RailsLens.logger.debug { "Failed to fetch column comment for #{table_name}.#{column_name}: #{e.message}" }
|
@@ -175,7 +223,9 @@ module RailsLens
|
|
175
223
|
def table_comment
|
176
224
|
return nil unless connection.respond_to?(:table_comment)
|
177
225
|
|
178
|
-
|
226
|
+
with_schema_in_search_path do
|
227
|
+
connection.table_comment(unqualified_table_name)
|
228
|
+
end
|
179
229
|
rescue ActiveRecord::StatementInvalid => e
|
180
230
|
# Table doesn't exist
|
181
231
|
RailsLens.logger.debug { "Failed to fetch table comment for #{table_name}: #{e.message}" }
|
@@ -252,7 +302,7 @@ module RailsLens
|
|
252
302
|
false as is_updatable,
|
253
303
|
mv.matviewname as view_name
|
254
304
|
FROM pg_matviews mv
|
255
|
-
WHERE mv.matviewname = '#{connection.quote_string(
|
305
|
+
WHERE mv.matviewname = '#{connection.quote_string(unqualified_table_name)}'
|
256
306
|
UNION ALL
|
257
307
|
-- Check for regular view
|
258
308
|
SELECT
|
@@ -260,14 +310,14 @@ module RailsLens
|
|
260
310
|
CASE WHEN v.is_updatable = 'YES' THEN true ELSE false END as is_updatable,
|
261
311
|
v.table_name as view_name
|
262
312
|
FROM information_schema.views v
|
263
|
-
WHERE v.table_name = '#{connection.quote_string(
|
313
|
+
WHERE v.table_name = '#{connection.quote_string(unqualified_table_name)}'
|
264
314
|
),
|
265
315
|
dependencies AS (
|
266
316
|
SELECT DISTINCT c2.relname as dependency_name
|
267
317
|
FROM pg_class c1
|
268
318
|
JOIN pg_depend d ON c1.oid = d.objid
|
269
319
|
JOIN pg_class c2 ON d.refobjid = c2.oid
|
270
|
-
WHERE c1.relname = '#{connection.quote_string(
|
320
|
+
WHERE c1.relname = '#{connection.quote_string(unqualified_table_name)}'
|
271
321
|
AND c1.relkind IN ('v', 'm')
|
272
322
|
AND c2.relkind IN ('r', 'v', 'm')
|
273
323
|
AND d.deptype = 'n'
|
@@ -316,13 +366,13 @@ module RailsLens
|
|
316
366
|
result = if view_type == 'materialized'
|
317
367
|
connection.exec_query(<<~SQL.squish, 'PostgreSQL Materialized View Definition')
|
318
368
|
SELECT definition FROM pg_matviews
|
319
|
-
WHERE matviewname = '#{connection.quote_string(
|
369
|
+
WHERE matviewname = '#{connection.quote_string(unqualified_table_name)}'
|
320
370
|
LIMIT 1
|
321
371
|
SQL
|
322
372
|
else
|
323
373
|
connection.exec_query(<<~SQL.squish, 'PostgreSQL View Definition')
|
324
374
|
SELECT view_definition FROM information_schema.views
|
325
|
-
WHERE table_name = '#{connection.quote_string(
|
375
|
+
WHERE table_name = '#{connection.quote_string(unqualified_table_name)}'
|
326
376
|
LIMIT 1
|
327
377
|
SQL
|
328
378
|
end
|
@@ -343,7 +393,7 @@ module RailsLens
|
|
343
393
|
result = connection.exec_query(<<~SQL.squish, 'PostgreSQL Materialized View Last Refresh')
|
344
394
|
SELECT COALESCE(last_vacuum, last_autovacuum) as last_refreshed
|
345
395
|
FROM pg_stat_user_tables
|
346
|
-
WHERE relname = '#{connection.quote_string(
|
396
|
+
WHERE relname = '#{connection.quote_string(unqualified_table_name)}'
|
347
397
|
LIMIT 1
|
348
398
|
SQL
|
349
399
|
|
data/lib/rails_lens/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_lens
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: '0'
|
265
265
|
requirements: []
|
266
|
-
rubygems_version: 3.
|
266
|
+
rubygems_version: 3.7.2
|
267
267
|
specification_version: 4
|
268
268
|
summary: Comprehensive Rails application visualization and annotation
|
269
269
|
test_files: []
|