ruby-pg-extras 5.6.13 → 5.6.14
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/lib/ruby-pg-extras.rb +4 -1
- data/lib/ruby_pg_extras/missing_fk_constraints.rb +6 -3
- data/lib/ruby_pg_extras/missing_fk_indexes.rb +2 -1
- data/lib/ruby_pg_extras/queries/foreign_keys.sql +19 -0
- data/lib/ruby_pg_extras/queries/table_schemas.sql +5 -0
- data/lib/ruby_pg_extras/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76983587160dcdfb1e9cc45f5e42b1329d08f74977f5c7691c7fafeeefc61fe4
|
|
4
|
+
data.tar.gz: 4ed633c71a3b2f4c12be8911b73ea59b750f2e7c569c6ae9913d62cab68b45e3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34423951a2e88e0c2e333e3cf2acc81aa8fd3b85eb76a410d2b6a5f195c22f584b475a9ee23585f012579c203496eee037d79889325f65b3b7d224a607fe98ac
|
|
7
|
+
data.tar.gz: cb3ff5a3d3ef075bd1cfe5c4604bf7dfcd821b9c11985868fa98d910213e1e767b765fe92c6acc6b1bb910d35cc12435402e97364cc26b1dacc2cd5d0212b55f
|
data/lib/ruby-pg-extras.rb
CHANGED
|
@@ -29,7 +29,8 @@ module RubyPgExtras
|
|
|
29
29
|
unused_indexes duplicate_indexes vacuum_stats kill_all kill_pid
|
|
30
30
|
pg_stat_statements_reset buffercache_stats
|
|
31
31
|
buffercache_usage ssl_used connections
|
|
32
|
-
table_schema
|
|
32
|
+
table_schema table_schemas
|
|
33
|
+
table_foreign_keys foreign_keys
|
|
33
34
|
)
|
|
34
35
|
|
|
35
36
|
DEFAULT_SCHEMA = ENV["PG_EXTRAS_SCHEMA"] || "public"
|
|
@@ -57,12 +58,14 @@ module RubyPgExtras
|
|
|
57
58
|
index_cache_hit: { schema: DEFAULT_SCHEMA },
|
|
58
59
|
table_cache_hit: { schema: DEFAULT_SCHEMA },
|
|
59
60
|
table_size: { schema: DEFAULT_SCHEMA },
|
|
61
|
+
table_schemas: { schema: DEFAULT_SCHEMA },
|
|
60
62
|
index_scans: { schema: DEFAULT_SCHEMA },
|
|
61
63
|
cache_hit: { schema: DEFAULT_SCHEMA },
|
|
62
64
|
seq_scans: { schema: DEFAULT_SCHEMA },
|
|
63
65
|
table_index_scans: { schema: DEFAULT_SCHEMA },
|
|
64
66
|
records_rank: { schema: DEFAULT_SCHEMA },
|
|
65
67
|
tables: { schema: DEFAULT_SCHEMA },
|
|
68
|
+
foreign_keys: { schema: DEFAULT_SCHEMA },
|
|
66
69
|
kill_pid: { pid: 0 },
|
|
67
70
|
})
|
|
68
71
|
|
|
@@ -13,9 +13,12 @@ module RubyPgExtras
|
|
|
13
13
|
all_tables
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
schemas = query_module.table_schemas(in_format: :hash)
|
|
17
|
+
foreign_keys = query_module.foreign_keys(in_format: :hash)
|
|
18
|
+
|
|
16
19
|
tables.reduce([]) do |agg, table|
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
schema = schemas.select { |row| row.fetch("table_name") == table }
|
|
21
|
+
fk_columns = foreign_keys.select { |row| row.fetch("table_name") == table }
|
|
19
22
|
|
|
20
23
|
fk_columns = schema.filter_map do |row|
|
|
21
24
|
if DetectFkColumn.call(row.fetch("column_name"), all_tables)
|
|
@@ -24,7 +27,7 @@ module RubyPgExtras
|
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
fk_columns.each do |column_name|
|
|
27
|
-
if
|
|
30
|
+
if foreign_keys.none? { |row| row.fetch("column_name") == column_name }
|
|
28
31
|
agg.push(
|
|
29
32
|
{
|
|
30
33
|
table: table,
|
|
@@ -14,10 +14,11 @@ module RubyPgExtras
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
indexes_info = query_module.indexes(in_format: :hash)
|
|
17
|
+
schemas = query_module.table_schemas(in_format: :hash)
|
|
17
18
|
|
|
18
19
|
tables.reduce([]) do |agg, table|
|
|
19
20
|
index_info = indexes_info.select { |row| row.fetch("tablename") == table }
|
|
20
|
-
schema =
|
|
21
|
+
schema = schemas.select { |row| row.fetch("table_name") == table }
|
|
21
22
|
|
|
22
23
|
fk_columns = schema.filter_map do |row|
|
|
23
24
|
if DetectFkColumn.call(row.fetch("column_name"), all_tables)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* Foreign keys info for all tables */
|
|
2
|
+
|
|
3
|
+
SELECT
|
|
4
|
+
conrelid::regclass AS table_name,
|
|
5
|
+
conname AS constraint_name,
|
|
6
|
+
a.attname AS column_name,
|
|
7
|
+
confrelid::regclass AS foreign_table_name,
|
|
8
|
+
af.attname AS foreign_column_name
|
|
9
|
+
FROM
|
|
10
|
+
pg_constraint AS c
|
|
11
|
+
JOIN
|
|
12
|
+
pg_attribute AS a ON a.attnum = ANY(c.conkey) AND a.attrelid = c.conrelid
|
|
13
|
+
JOIN
|
|
14
|
+
pg_attribute AS af ON af.attnum = ANY(c.confkey) AND af.attrelid = c.confrelid
|
|
15
|
+
JOIN
|
|
16
|
+
pg_namespace AS n ON n.oid = c.connamespace
|
|
17
|
+
WHERE
|
|
18
|
+
c.contype = 'f'
|
|
19
|
+
AND n.nspname = '%{schema}';
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-pg-extras
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.6.
|
|
4
|
+
version: 5.6.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- pawurb
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pg
|
|
@@ -132,6 +132,7 @@ files:
|
|
|
132
132
|
- lib/ruby_pg_extras/queries/db_settings.sql
|
|
133
133
|
- lib/ruby_pg_extras/queries/duplicate_indexes.sql
|
|
134
134
|
- lib/ruby_pg_extras/queries/extensions.sql
|
|
135
|
+
- lib/ruby_pg_extras/queries/foreign_keys.sql
|
|
135
136
|
- lib/ruby_pg_extras/queries/index_cache_hit.sql
|
|
136
137
|
- lib/ruby_pg_extras/queries/index_scans.sql
|
|
137
138
|
- lib/ruby_pg_extras/queries/index_size.sql
|
|
@@ -155,6 +156,7 @@ files:
|
|
|
155
156
|
- lib/ruby_pg_extras/queries/table_index_scans.sql
|
|
156
157
|
- lib/ruby_pg_extras/queries/table_indexes_size.sql
|
|
157
158
|
- lib/ruby_pg_extras/queries/table_schema.sql
|
|
159
|
+
- lib/ruby_pg_extras/queries/table_schemas.sql
|
|
158
160
|
- lib/ruby_pg_extras/queries/table_size.sql
|
|
159
161
|
- lib/ruby_pg_extras/queries/tables.sql
|
|
160
162
|
- lib/ruby_pg_extras/queries/total_index_size.sql
|