index_shotgun 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,14 +7,3 @@ module IndexShotgun
7
7
  end
8
8
 
9
9
  require "index_shotgun/railtie" if defined?(Rails)
10
-
11
- begin
12
- require "mysql2/version"
13
-
14
- if Gem::Version.create(Mysql2::VERSION) >= Gem::Version.create("0.4.0") &&
15
- ActiveRecord.version < Gem::Version.create("4.2.5")
16
- raise "Requirements activerecord gem v4.2.5+ when using mysql2 gem v0.4.0+"
17
- end
18
-
19
- rescue LoadError
20
- end
@@ -1,5 +1,5 @@
1
1
  module IndexShotgun
2
- module Analyzer
2
+ module Analyzer # rubocop:disable Metrics/ModuleLength
3
3
  require "index_shotgun/array_start_with"
4
4
 
5
5
  class Response
@@ -24,7 +24,7 @@ module IndexShotgun
24
24
  ActiveSupport::Deprecation.silence do
25
25
  ActiveRecord::Base.connection.tables
26
26
  end
27
- tables.reject! { |table| exclude_tables.include?(table.downcase) }
27
+ tables.reject! {|table| exclude_tables.include?(table.downcase) }
28
28
 
29
29
  duplicate_indexes =
30
30
  tables.each_with_object([]) do |table, array|
@@ -33,8 +33,8 @@ module IndexShotgun
33
33
  end
34
34
 
35
35
  message =
36
- duplicate_indexes.each_with_object("") do |info, message|
37
- message << <<-EOS.strip_heredoc
36
+ duplicate_indexes.each_with_object("") do |info, str|
37
+ str << <<~MSG
38
38
  # =============================
39
39
  # #{info[:index].table}
40
40
  # =============================
@@ -43,11 +43,11 @@ module IndexShotgun
43
43
  # To remove this duplicate index, execute:
44
44
  ALTER TABLE `#{info[:index].table}` DROP INDEX `#{info[:index].name}`;
45
45
 
46
- EOS
46
+ MSG
47
47
  end
48
48
 
49
- total_index_count = tables.map { |table| table_indexes(table).count }.sum
50
- message << <<-EOS.strip_heredoc
49
+ total_index_count = tables.map {|table| table_indexes(table).count }.sum
50
+ message << <<~MSG
51
51
  # ########################################################################
52
52
  # Summary of indexes
53
53
  # ########################################################################
@@ -56,7 +56,7 @@ module IndexShotgun
56
56
  # Total Indexes #{total_index_count}
57
57
  # Total Tables #{tables.count}
58
58
 
59
- EOS
59
+ MSG
60
60
 
61
61
  response = Response.new
62
62
  response.duplicate_index_count = duplicate_indexes.count
@@ -99,189 +99,191 @@ module IndexShotgun
99
99
  ActiveRecord::Base.connection.indexes(table)
100
100
  end
101
101
 
102
+ ORACLE_SYSTEM_TABLES = %w[
103
+ AQ$DEF$_AQCALL
104
+ AQ$DEF$_AQERROR
105
+ AQ$_DEF$_AQCALL_F
106
+ AQ$_DEF$_AQERROR_F
107
+ AQ$_INTERNET_AGENTS
108
+ AQ$_INTERNET_AGENT_PRIVS
109
+ AQ$_QUEUES
110
+ AQ$_QUEUE_TABLES
111
+ AQ$_SCHEDULES
112
+ CATALOG
113
+ COL
114
+ DEF$_AQCALL
115
+ DEF$_AQERROR
116
+ DEF$_CALLDEST
117
+ DEF$_DEFAULTDEST
118
+ DEF$_DESTINATION
119
+ DEF$_ERROR
120
+ DEF$_LOB
121
+ DEF$_ORIGIN
122
+ DEF$_PROPAGATOR
123
+ DEF$_PUSHED_TRANSACTIONS
124
+ HELP
125
+ LOGMNRC_DBNAME_UID_MAP
126
+ LOGMNRC_GSBA
127
+ LOGMNRC_GSII
128
+ LOGMNRC_GTCS
129
+ LOGMNRC_GTLO
130
+ LOGMNRP_CTAS_PART_MAP
131
+ LOGMNRT_MDDL$
132
+ LOGMNR_AGE_SPILL$
133
+ LOGMNR_ATTRCOL$
134
+ LOGMNR_ATTRIBUTE$
135
+ LOGMNR_CCOL$
136
+ LOGMNR_CDEF$
137
+ LOGMNR_COL$
138
+ LOGMNR_COLTYPE$
139
+ LOGMNR_DICTIONARY$
140
+ LOGMNR_DICTSTATE$
141
+ LOGMNR_ENC$
142
+ LOGMNR_ERROR$
143
+ LOGMNR_FILTER$
144
+ LOGMNR_GLOBAL$
145
+ LOGMNR_GT_TAB_INCLUDE$
146
+ LOGMNR_GT_USER_INCLUDE$
147
+ LOGMNR_GT_XID_INCLUDE$
148
+ LOGMNR_ICOL$
149
+ LOGMNR_IND$
150
+ LOGMNR_INDCOMPART$
151
+ LOGMNR_INDPART$
152
+ LOGMNR_INDSUBPART$
153
+ LOGMNR_INTEGRATED_SPILL$
154
+ LOGMNR_KOPM$
155
+ LOGMNR_LOB$
156
+ LOGMNR_LOBFRAG$
157
+ LOGMNR_LOG$
158
+ LOGMNR_LOGMNR_BUILDLOG
159
+ LOGMNR_NTAB$
160
+ LOGMNR_OBJ$
161
+ LOGMNR_OPQTYPE$
162
+ LOGMNR_PARAMETER$
163
+ LOGMNR_PARTOBJ$
164
+ LOGMNR_PROCESSED_LOG$
165
+ LOGMNR_PROPS$
166
+ LOGMNR_REFCON$
167
+ LOGMNR_RESTART_CKPT$
168
+ LOGMNR_RESTART_CKPT_TXINFO$
169
+ LOGMNR_SEED$
170
+ LOGMNR_SESSION$
171
+ LOGMNR_SESSION_ACTIONS$
172
+ LOGMNR_SESSION_EVOLVE$
173
+ LOGMNR_SPILL$
174
+ LOGMNR_SUBCOLTYPE$
175
+ LOGMNR_TAB$
176
+ LOGMNR_TABCOMPART$
177
+ LOGMNR_TABPART$
178
+ LOGMNR_TABSUBPART$
179
+ LOGMNR_TS$
180
+ LOGMNR_TYPE$
181
+ LOGMNR_UID$
182
+ LOGMNR_USER$
183
+ LOGSTDBY$APPLY_MILESTONE
184
+ LOGSTDBY$APPLY_PROGRESS
185
+ LOGSTDBY$EDS_TABLES
186
+ LOGSTDBY$EVENTS
187
+ LOGSTDBY$FLASHBACK_SCN
188
+ LOGSTDBY$HISTORY
189
+ LOGSTDBY$PARAMETERS
190
+ LOGSTDBY$PLSQL
191
+ LOGSTDBY$SCN
192
+ LOGSTDBY$SKIP
193
+ LOGSTDBY$SKIP_SUPPORT
194
+ LOGSTDBY$SKIP_TRANSACTION
195
+ MVIEW$_ADV_AJG
196
+ MVIEW$_ADV_BASETABLE
197
+ MVIEW$_ADV_CLIQUE
198
+ MVIEW$_ADV_ELIGIBLE
199
+ MVIEW$_ADV_EXCEPTIONS
200
+ MVIEW$_ADV_FILTER
201
+ MVIEW$_ADV_FILTERINSTANCE
202
+ MVIEW$_ADV_FJG
203
+ MVIEW$_ADV_GC
204
+ MVIEW$_ADV_INFO
205
+ MVIEW$_ADV_JOURNAL
206
+ MVIEW$_ADV_LEVEL
207
+ MVIEW$_ADV_LOG
208
+ MVIEW$_ADV_OUTPUT
209
+ MVIEW$_ADV_PARAMETERS
210
+ MVIEW$_ADV_PLAN
211
+ MVIEW$_ADV_PRETTY
212
+ MVIEW$_ADV_ROLLUP
213
+ MVIEW$_ADV_SQLDEPEND
214
+ MVIEW$_ADV_TEMP
215
+ MVIEW$_ADV_WORKLOAD
216
+ MVIEW_EVALUATIONS
217
+ MVIEW_EXCEPTIONS
218
+ MVIEW_FILTER
219
+ MVIEW_FILTERINSTANCE
220
+ MVIEW_LOG
221
+ MVIEW_RECOMMENDATIONS
222
+ MVIEW_WORKLOAD
223
+ OL$
224
+ OL$HINTS
225
+ OL$NODES
226
+ PRODUCT_PRIVS
227
+ PRODUCT_USER_PROFILE
228
+ PUBLICSYN
229
+ REPCAT$_AUDIT_ATTRIBUTE
230
+ REPCAT$_AUDIT_COLUMN
231
+ REPCAT$_COLUMN_GROUP
232
+ REPCAT$_CONFLICT
233
+ REPCAT$_DDL
234
+ REPCAT$_EXCEPTIONS
235
+ REPCAT$_EXTENSION
236
+ REPCAT$_FLAVORS
237
+ REPCAT$_FLAVOR_OBJECTS
238
+ REPCAT$_GENERATED
239
+ REPCAT$_GROUPED_COLUMN
240
+ REPCAT$_INSTANTIATION_DDL
241
+ REPCAT$_KEY_COLUMNS
242
+ REPCAT$_OBJECT_PARMS
243
+ REPCAT$_OBJECT_TYPES
244
+ REPCAT$_PARAMETER_COLUMN
245
+ REPCAT$_PRIORITY
246
+ REPCAT$_PRIORITY_GROUP
247
+ REPCAT$_REFRESH_TEMPLATES
248
+ REPCAT$_REPCAT
249
+ REPCAT$_REPCATLOG
250
+ REPCAT$_REPCOLUMN
251
+ REPCAT$_REPGROUP_PRIVS
252
+ REPCAT$_REPOBJECT
253
+ REPCAT$_REPPROP
254
+ REPCAT$_REPSCHEMA
255
+ REPCAT$_RESOLUTION
256
+ REPCAT$_RESOLUTION_METHOD
257
+ REPCAT$_RESOLUTION_STATISTICS
258
+ REPCAT$_RESOL_STATS_CONTROL
259
+ REPCAT$_RUNTIME_PARMS
260
+ REPCAT$_SITES_NEW
261
+ REPCAT$_SITE_OBJECTS
262
+ REPCAT$_SNAPGROUP
263
+ REPCAT$_TEMPLATE_OBJECTS
264
+ REPCAT$_TEMPLATE_PARMS
265
+ REPCAT$_TEMPLATE_REFGROUPS
266
+ REPCAT$_TEMPLATE_SITES
267
+ REPCAT$_TEMPLATE_STATUS
268
+ REPCAT$_TEMPLATE_TARGETS
269
+ REPCAT$_TEMPLATE_TYPES
270
+ REPCAT$_USER_AUTHORIZATIONS
271
+ REPCAT$_USER_PARM_VALUES
272
+ SQLPLUS_PRODUCT_PROFILE
273
+ SYSCATALOG
274
+ SYSFILES
275
+ TAB
276
+ TABQUOTAS
277
+ ].freeze
278
+
102
279
  def exclude_tables
103
280
  return @exclude_tables if @exclude_tables
104
281
 
105
282
  # Rails default tables
106
- tables = %w(ar_internal_metadata schema_migrations)
283
+ tables = %w[ar_internal_metadata schema_migrations]
107
284
 
108
285
  # Oracle system tables
109
- tables += %w(
110
- AQ$DEF$_AQCALL
111
- AQ$DEF$_AQERROR
112
- AQ$_DEF$_AQCALL_F
113
- AQ$_DEF$_AQERROR_F
114
- AQ$_INTERNET_AGENTS
115
- AQ$_INTERNET_AGENT_PRIVS
116
- AQ$_QUEUES
117
- AQ$_QUEUE_TABLES
118
- AQ$_SCHEDULES
119
- CATALOG
120
- COL
121
- DEF$_AQCALL
122
- DEF$_AQERROR
123
- DEF$_CALLDEST
124
- DEF$_DEFAULTDEST
125
- DEF$_DESTINATION
126
- DEF$_ERROR
127
- DEF$_LOB
128
- DEF$_ORIGIN
129
- DEF$_PROPAGATOR
130
- DEF$_PUSHED_TRANSACTIONS
131
- HELP
132
- LOGMNRC_DBNAME_UID_MAP
133
- LOGMNRC_GSBA
134
- LOGMNRC_GSII
135
- LOGMNRC_GTCS
136
- LOGMNRC_GTLO
137
- LOGMNRP_CTAS_PART_MAP
138
- LOGMNRT_MDDL$
139
- LOGMNR_AGE_SPILL$
140
- LOGMNR_ATTRCOL$
141
- LOGMNR_ATTRIBUTE$
142
- LOGMNR_CCOL$
143
- LOGMNR_CDEF$
144
- LOGMNR_COL$
145
- LOGMNR_COLTYPE$
146
- LOGMNR_DICTIONARY$
147
- LOGMNR_DICTSTATE$
148
- LOGMNR_ENC$
149
- LOGMNR_ERROR$
150
- LOGMNR_FILTER$
151
- LOGMNR_GLOBAL$
152
- LOGMNR_GT_TAB_INCLUDE$
153
- LOGMNR_GT_USER_INCLUDE$
154
- LOGMNR_GT_XID_INCLUDE$
155
- LOGMNR_ICOL$
156
- LOGMNR_IND$
157
- LOGMNR_INDCOMPART$
158
- LOGMNR_INDPART$
159
- LOGMNR_INDSUBPART$
160
- LOGMNR_INTEGRATED_SPILL$
161
- LOGMNR_KOPM$
162
- LOGMNR_LOB$
163
- LOGMNR_LOBFRAG$
164
- LOGMNR_LOG$
165
- LOGMNR_LOGMNR_BUILDLOG
166
- LOGMNR_NTAB$
167
- LOGMNR_OBJ$
168
- LOGMNR_OPQTYPE$
169
- LOGMNR_PARAMETER$
170
- LOGMNR_PARTOBJ$
171
- LOGMNR_PROCESSED_LOG$
172
- LOGMNR_PROPS$
173
- LOGMNR_REFCON$
174
- LOGMNR_RESTART_CKPT$
175
- LOGMNR_RESTART_CKPT_TXINFO$
176
- LOGMNR_SEED$
177
- LOGMNR_SESSION$
178
- LOGMNR_SESSION_ACTIONS$
179
- LOGMNR_SESSION_EVOLVE$
180
- LOGMNR_SPILL$
181
- LOGMNR_SUBCOLTYPE$
182
- LOGMNR_TAB$
183
- LOGMNR_TABCOMPART$
184
- LOGMNR_TABPART$
185
- LOGMNR_TABSUBPART$
186
- LOGMNR_TS$
187
- LOGMNR_TYPE$
188
- LOGMNR_UID$
189
- LOGMNR_USER$
190
- LOGSTDBY$APPLY_MILESTONE
191
- LOGSTDBY$APPLY_PROGRESS
192
- LOGSTDBY$EDS_TABLES
193
- LOGSTDBY$EVENTS
194
- LOGSTDBY$FLASHBACK_SCN
195
- LOGSTDBY$HISTORY
196
- LOGSTDBY$PARAMETERS
197
- LOGSTDBY$PLSQL
198
- LOGSTDBY$SCN
199
- LOGSTDBY$SKIP
200
- LOGSTDBY$SKIP_SUPPORT
201
- LOGSTDBY$SKIP_TRANSACTION
202
- MVIEW$_ADV_AJG
203
- MVIEW$_ADV_BASETABLE
204
- MVIEW$_ADV_CLIQUE
205
- MVIEW$_ADV_ELIGIBLE
206
- MVIEW$_ADV_EXCEPTIONS
207
- MVIEW$_ADV_FILTER
208
- MVIEW$_ADV_FILTERINSTANCE
209
- MVIEW$_ADV_FJG
210
- MVIEW$_ADV_GC
211
- MVIEW$_ADV_INFO
212
- MVIEW$_ADV_JOURNAL
213
- MVIEW$_ADV_LEVEL
214
- MVIEW$_ADV_LOG
215
- MVIEW$_ADV_OUTPUT
216
- MVIEW$_ADV_PARAMETERS
217
- MVIEW$_ADV_PLAN
218
- MVIEW$_ADV_PRETTY
219
- MVIEW$_ADV_ROLLUP
220
- MVIEW$_ADV_SQLDEPEND
221
- MVIEW$_ADV_TEMP
222
- MVIEW$_ADV_WORKLOAD
223
- MVIEW_EVALUATIONS
224
- MVIEW_EXCEPTIONS
225
- MVIEW_FILTER
226
- MVIEW_FILTERINSTANCE
227
- MVIEW_LOG
228
- MVIEW_RECOMMENDATIONS
229
- MVIEW_WORKLOAD
230
- OL$
231
- OL$HINTS
232
- OL$NODES
233
- PRODUCT_PRIVS
234
- PRODUCT_USER_PROFILE
235
- PUBLICSYN
236
- REPCAT$_AUDIT_ATTRIBUTE
237
- REPCAT$_AUDIT_COLUMN
238
- REPCAT$_COLUMN_GROUP
239
- REPCAT$_CONFLICT
240
- REPCAT$_DDL
241
- REPCAT$_EXCEPTIONS
242
- REPCAT$_EXTENSION
243
- REPCAT$_FLAVORS
244
- REPCAT$_FLAVOR_OBJECTS
245
- REPCAT$_GENERATED
246
- REPCAT$_GROUPED_COLUMN
247
- REPCAT$_INSTANTIATION_DDL
248
- REPCAT$_KEY_COLUMNS
249
- REPCAT$_OBJECT_PARMS
250
- REPCAT$_OBJECT_TYPES
251
- REPCAT$_PARAMETER_COLUMN
252
- REPCAT$_PRIORITY
253
- REPCAT$_PRIORITY_GROUP
254
- REPCAT$_REFRESH_TEMPLATES
255
- REPCAT$_REPCAT
256
- REPCAT$_REPCATLOG
257
- REPCAT$_REPCOLUMN
258
- REPCAT$_REPGROUP_PRIVS
259
- REPCAT$_REPOBJECT
260
- REPCAT$_REPPROP
261
- REPCAT$_REPSCHEMA
262
- REPCAT$_RESOLUTION
263
- REPCAT$_RESOLUTION_METHOD
264
- REPCAT$_RESOLUTION_STATISTICS
265
- REPCAT$_RESOL_STATS_CONTROL
266
- REPCAT$_RUNTIME_PARMS
267
- REPCAT$_SITES_NEW
268
- REPCAT$_SITE_OBJECTS
269
- REPCAT$_SNAPGROUP
270
- REPCAT$_TEMPLATE_OBJECTS
271
- REPCAT$_TEMPLATE_PARMS
272
- REPCAT$_TEMPLATE_REFGROUPS
273
- REPCAT$_TEMPLATE_SITES
274
- REPCAT$_TEMPLATE_STATUS
275
- REPCAT$_TEMPLATE_TARGETS
276
- REPCAT$_TEMPLATE_TYPES
277
- REPCAT$_USER_AUTHORIZATIONS
278
- REPCAT$_USER_PARM_VALUES
279
- SQLPLUS_PRODUCT_PROFILE
280
- SYSCATALOG
281
- SYSFILES
282
- TAB
283
- TABQUOTAS
284
- )
286
+ tables += ORACLE_SYSTEM_TABLES
285
287
 
286
288
  @exclude_tables = tables.map(&:downcase)
287
289
  @exclude_tables
@@ -56,24 +56,24 @@ module IndexShotgun
56
56
 
57
57
  private
58
58
 
59
- def analyze(adapter_name, gem_name = nil)
60
- gem_name ||= adapter_name
61
- begin
62
- require gem_name
63
- rescue LoadError
64
- puts "[ERROR] #{adapter_name} is not installed. Please run `gem install #{gem_name}` and install gem"
65
- exit!
66
- end
59
+ def analyze(adapter_name, gem_name = nil)
60
+ gem_name ||= adapter_name
61
+ begin
62
+ require gem_name
63
+ rescue LoadError
64
+ puts "[ERROR] #{adapter_name} is not installed. Please run `gem install #{gem_name}` and install gem"
65
+ exit!
66
+ end
67
67
 
68
- config = options.reverse_merge(adapter: adapter_name)
68
+ config = options.reverse_merge(adapter: adapter_name)
69
69
 
70
- ask_password = config.delete("ask_password")
71
- config[:password] = ask("Input password (hidden):", echo: false) if ask_password
70
+ ask_password = config.delete("ask_password")
71
+ config[:password] = ask("Input password (hidden):", echo: false) if ask_password
72
72
 
73
- ActiveRecord::Base.establish_connection(config)
74
- response = IndexShotgun::Analyzer.perform
75
- puts response.message
76
- response.exit_if_failure!
77
- end
73
+ ActiveRecord::Base.establish_connection(config)
74
+ response = IndexShotgun::Analyzer.perform
75
+ puts response.message
76
+ response.exit_if_failure!
77
+ end
78
78
  end
79
79
  end