File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,6 +136,16 @@ RubyPgExtras.missing_fk_indexes(args: { table_name: "users" })
136136
137137```
138138
139+ You can also exclude known/intentional cases using ` ignore_list ` (array or comma-separated string), with entries like:
140+ - ` "posts.topic_id" ` (ignore a specific table+column)
141+ - ` "topic_id" ` (ignore this column name for all tables)
142+ - ` "posts.*" ` (ignore all columns on a table)
143+ - ` "*" ` (ignore everything)
144+
145+ ``` ruby
146+ RubyPgExtras .missing_fk_indexes(args: { ignore_list: [" users.company_id" , " posts.*" ] })
147+ ```
148+
139149` table_name ` argument is optional, if omitted, the method will display missing fk indexes for all the tables.
140150
141151## ` missing_fk_constraints `
Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ def self.table_info(args: {}, in_format: :display_table)
192192 end
193193
194194 def self . missing_fk_indexes ( args : { } , in_format : :display_table )
195- RubyPgExtras ::MissingFkIndexes . call ( args [ :table_name ] )
195+ RubyPgExtras ::MissingFkIndexes . call ( args [ :table_name ] , ignore_list : args [ :ignore_list ] )
196196 end
197197
198198 def self . missing_fk_constraints ( args : { } , in_format : :display_table )
Original file line number Diff line number Diff line change 22
33module RubyPgExtras
44 class MissingFkIndexes
5- def self . call ( table_name )
6- new . call ( table_name )
5+ # ignore_list: array (or comma-separated string) of entries like:
6+ # - "posts.topic_id" (ignore a specific table+column)
7+ # - "topic_id" (ignore this column name for all tables)
8+ # - "posts.*" (ignore all columns on a table)
9+ # - "*" (ignore everything)
10+ def self . call ( table_name , ignore_list : nil )
11+ new . call ( table_name , ignore_list : ignore_list )
712 end
813
9- def call ( table_name )
14+ def call ( table_name , ignore_list : nil )
15+ ignore_list_matcher = IgnoreList . new ( ignore_list )
16+
1017 indexes_info = query_module . indexes ( in_format : :hash )
1118 foreign_keys = query_module . foreign_keys ( in_format : :hash )
1219
@@ -23,6 +30,9 @@ def call(table_name)
2330 table_fks . each do |fk |
2431 column_name = fk . fetch ( "column_name" )
2532
33+ # Skip columns explicitly excluded via ignore list.
34+ next if ignore_list_matcher . ignored? ( table : table , column_name : column_name )
35+
2636 if index_info . none? { |row | row . fetch ( "columns" ) . split ( "," ) . first == column_name }
2737 agg . push (
2838 {
Original file line number Diff line number Diff line change 1818 { table : "posts" , column_name : "topic_id" } ,
1919 ] )
2020 end
21+
22+ it "supports ignoring a specific table+column via args" do
23+ result = RubyPgExtras . missing_fk_indexes (
24+ args : { ignore_list : [ "posts.topic_id" ] } ,
25+ in_format : :hash
26+ )
27+
28+ expect ( result ) . to eq ( [
29+ { table : "users" , column_name : "company_id" } ,
30+ ] )
31+ end
32+
33+ it "supports ignoring a column name globally via args" do
34+ result = RubyPgExtras . missing_fk_indexes (
35+ args : { ignore_list : [ "company_id" ] } ,
36+ in_format : :hash
37+ )
38+
39+ expect ( result ) . to eq ( [
40+ { table : "posts" , column_name : "topic_id" } ,
41+ ] )
42+ end
2143end
You can’t perform that action at this time.
0 commit comments