ruby-pg-extras 5.6.1 → 5.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d63b815252ba55f7501178013917e4cb7c48cf64f34ff1501dab8a6d84b3d7c4
4
- data.tar.gz: 8465dbaee0cd16da98fcaaeb9a20b92185060ded5371220ae04194610e9c2a58
3
+ metadata.gz: 57c2a84fde86ad8d8f2edba0c3bb0036b525df7471013341338291b1e8c1f8e9
4
+ data.tar.gz: bc5624774204781bd1e970f118957aea5107e555c6f5698f3d32f7dfe5f3dc8e
5
5
  SHA512:
6
- metadata.gz: cbac3bdc3566aaf3ac39702e8485661b3460ddf25506a52aa46c2f386345d47d868cce197f1b5dec3f1adff7e14081d772d2650cd65c889a48291ab1aabf8125
7
- data.tar.gz: 155101c5bc0bf1d791ccbad29b95d8f10556a32caa16c4ded2c6cfef51b3b834c2759e15d273830dc5f99221bd7b969022b66879886afe29cb7b8c7d8ace094b
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`) but don't have a corresponding index. It's a generally recommended to always index foreign key columns because they are used for searching relation objects.
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 also remember that each index decreases write performance and autovacuuming overhead, so be careful when adding multiple indexes to often updated tables.
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 (i.e. name ending in `_id`) 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).
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 foreign keys for all the tables.
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.index_info(in_format: :hash)
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(:table_name) == table }
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(:columns)[0] == column_name }
29
+ if index_info.none? { |row| row.fetch("columns").split(",").first == column_name }
30
30
  agg.push(
31
31
  {
32
32
  table: table,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyPgExtras
4
- VERSION = "5.6.1"
4
+ VERSION = "5.6.2"
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -52,7 +52,7 @@ CREATE TABLE companies (
52
52
  name VARCHAR(255)
53
53
  );
54
54
 
55
- CREATE INDEX index_posts_on_user_id ON posts(user_id);
55
+ CREATE INDEX index_posts_on_user_id ON posts(user_id, topic_id);
56
56
  SQL
57
57
 
58
58
  RubyPgExtras.connection.exec(DB_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.1
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-02 00:00:00.000000000 Z
11
+ date: 2025-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg