ruby-pg-extras 5.6.1 → 5.6.2
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/README.md +22 -4
- data/lib/ruby_pg_extras/missing_fk_indexes.rb +3 -3
- data/lib/ruby_pg_extras/version.rb +1 -1
- data/spec/spec_helper.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: 57c2a84fde86ad8d8f2edba0c3bb0036b525df7471013341338291b1e8c1f8e9
|
4
|
+
data.tar.gz: bc5624774204781bd1e970f118957aea5107e555c6f5698f3d32f7dfe5f3dc8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbe16634243b05f414ca9eee58b30b939a3a7bed2bbadead9782aa39951bb2b4dc13e71cd5b3e38a0698b03fb330b43427a807f1b221e4beb62128e3dc2e6a62
|
7
|
+
data.tar.gz: 6ea5ef05e992a7f8f9dcb986b3ff983a888584bea0468711ce7e40a4c43c4485d205fbd1bb71dd50591f37e5036406829f7ae24f3ec5b5390da2e75bca7eccb7
|
data/README.md
CHANGED
@@ -118,27 +118,45 @@ Keep reading to learn about methods that `diagnose` uses under the hood.
|
|
118
118
|
|
119
119
|
### `missing_fk_indexes`
|
120
120
|
|
121
|
-
This method lists columns likely to be foreign keys (i.e. name ending in `_id`)
|
121
|
+
This method lists columns likely to be foreign keys (i.e. column name ending in `_id` and related table exists) which don't have an index. It's recommended to always index foreign key columns because they are used for searching relation objects.
|
122
122
|
|
123
|
-
You can add indexes on the columns returned by this query and later check if they are receiving scans using the [unused_indexes method](#unused_indexes). Please
|
123
|
+
You can add indexes on the columns returned by this query and later check if they are receiving scans using the [unused_indexes method](#unused_indexes). Please remember that each index decreases write performance and autovacuuming overhead, so be careful when adding multiple indexes to often updated tables.
|
124
124
|
|
125
125
|
```ruby
|
126
126
|
RubyPgExtras.missing_fk_indexes(args: { table_name: "users" })
|
127
127
|
|
128
|
+
+---------------------------------+
|
129
|
+
| Missing foreign key indexes |
|
130
|
+
+-------------------+-------------+
|
131
|
+
| table | column_name |
|
132
|
+
+-------------------+-------------+
|
133
|
+
| feedbacks | team_id |
|
134
|
+
| votes | user_id |
|
135
|
+
+-------------------+-------------+
|
136
|
+
|
128
137
|
```
|
129
138
|
|
130
139
|
`table_name` argument is optional, if omitted, the method will display missing fk indexes for all the tables.
|
131
140
|
|
132
141
|
## `missing_fk_constraints`
|
133
142
|
|
134
|
-
Similarly to the previous method, this one shows columns likely to be foreign keys
|
143
|
+
Similarly to the previous method, this one shows columns likely to be foreign keys that don't have a corresponding foreign key constraint. Foreign key constraints improve data integrity in the database by preventing relations with nonexisting objects. You can read more about the benefits of using foreign keys [in this blog post](https://pawelurbanek.com/rails-postgresql-data-integrity).
|
135
144
|
|
136
145
|
```ruby
|
137
146
|
RubyPgExtras.missing_fk_constraints(args: { table_name: "users" })
|
138
147
|
|
148
|
+
+---------------------------------+
|
149
|
+
| Missing foreign key constraints |
|
150
|
+
+-------------------+-------------+
|
151
|
+
| table | column_name |
|
152
|
+
+-------------------+-------------+
|
153
|
+
| feedbacks | team_id |
|
154
|
+
| votes | user_id |
|
155
|
+
+-------------------+-------------+
|
156
|
+
|
139
157
|
```
|
140
158
|
|
141
|
-
`table_name` argument is optional, if omitted, method will display missing
|
159
|
+
`table_name` argument is optional, if omitted, method will display missing fk constraints for all the tables.
|
142
160
|
|
143
161
|
### `table_info`
|
144
162
|
|
@@ -13,10 +13,10 @@ module RubyPgExtras
|
|
13
13
|
all_tables
|
14
14
|
end
|
15
15
|
|
16
|
-
indexes_info = query_module.
|
16
|
+
indexes_info = query_module.indexes(in_format: :hash)
|
17
17
|
|
18
18
|
tables.reduce([]) do |agg, table|
|
19
|
-
index_info = indexes_info.select { |row| row.fetch(
|
19
|
+
index_info = indexes_info.select { |row| row.fetch("tablename") == table }
|
20
20
|
schema = query_module.table_schema(args: { table_name: table }, in_format: :hash)
|
21
21
|
|
22
22
|
fk_columns = schema.filter_map do |row|
|
@@ -26,7 +26,7 @@ module RubyPgExtras
|
|
26
26
|
end
|
27
27
|
|
28
28
|
fk_columns.each do |column_name|
|
29
|
-
if index_info.none? { |row| row.fetch(
|
29
|
+
if index_info.none? { |row| row.fetch("columns").split(",").first == column_name }
|
30
30
|
agg.push(
|
31
31
|
{
|
32
32
|
table: table,
|
data/spec/spec_helper.rb
CHANGED
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|