active_record_doctor 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,10 @@
1
1
  class SpyPrinter
2
- attr_reader :unindexed_foreign_keys, :extraneous_indexes
2
+ attr_reader :unindexed_foreign_keys, :extraneous_indexes, :indexed_primary_key
3
3
 
4
4
  def initialize
5
5
  @unindexed_foreign_keys = nil
6
6
  @extraneous_indexes = nil
7
+ @indexed_primary_key = nil
7
8
  end
8
9
 
9
10
  def print_unindexed_foreign_keys(argument)
@@ -21,4 +22,12 @@ class SpyPrinter
21
22
  @extraneous_indexes = argument
22
23
  end
23
24
  end
25
+
26
+ def print_indexed_primary_keys(argument)
27
+ if @extraneous_indexes
28
+ fail("indexed_primary_key cannot be called twice")
29
+ else
30
+ @indexed_primary_key = argument
31
+ end
32
+ end
24
33
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_doctor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Navis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-04 00:00:00.000000000 Z
11
+ date: 2016-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '4.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '11.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '11.1'
69
69
  description:
@@ -73,70 +73,73 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - lib/generators/active_record_doctor/add_indexes/add_indexes_generator.rb
77
- - lib/generators/active_record_doctor/add_indexes/USAGE
78
- - lib/active_record_doctor/railtie.rb
76
+ - MIT-LICENSE.txt
77
+ - README.md
78
+ - Rakefile
79
+ - lib/active_record_doctor.rb
79
80
  - lib/active_record_doctor/printers.rb
80
81
  - lib/active_record_doctor/printers/io_printer.rb
82
+ - lib/active_record_doctor/railtie.rb
81
83
  - lib/active_record_doctor/tasks.rb
82
- - lib/active_record_doctor/version.rb
83
84
  - lib/active_record_doctor/tasks/extraneous_indexes.rb
84
85
  - lib/active_record_doctor/tasks/unindexed_foreign_keys.rb
85
- - lib/active_record_doctor.rb
86
+ - lib/active_record_doctor/version.rb
87
+ - lib/generators/active_record_doctor/add_indexes/USAGE
88
+ - lib/generators/active_record_doctor/add_indexes/add_indexes_generator.rb
86
89
  - lib/tasks/active_record_doctor_tasks.rake
87
- - Rakefile
88
- - README.rdoc
89
- - test/test_helper.rb
90
90
  - test/active_record_doctor/printers/io_printer_test.rb
91
91
  - test/active_record_doctor/tasks/extraneous_indexes_test.rb
92
92
  - test/active_record_doctor/tasks/unindexed_foreign_keys_test.rb
93
93
  - test/dummy/README.rdoc
94
- - test/dummy/log/development.log
95
- - test/dummy/log/test.log
96
- - test/dummy/bin/rake
97
- - test/dummy/bin/rails
98
- - test/dummy/bin/setup
99
- - test/dummy/bin/bundle
100
- - test/dummy/app/helpers/application_helper.rb
101
- - test/dummy/app/controllers/application_controller.rb
102
- - test/dummy/app/assets/stylesheets/application.css
94
+ - test/dummy/Rakefile
103
95
  - test/dummy/app/assets/javascripts/application.js
104
- - test/dummy/app/views/layouts/application.html.erb
105
- - test/dummy/app/models/profile.rb
96
+ - test/dummy/app/assets/stylesheets/application.css
97
+ - test/dummy/app/controllers/application_controller.rb
98
+ - test/dummy/app/helpers/application_helper.rb
99
+ - test/dummy/app/models/comment.rb
106
100
  - test/dummy/app/models/employer.rb
101
+ - test/dummy/app/models/profile.rb
107
102
  - test/dummy/app/models/user.rb
108
- - test/dummy/db/schema.rb
109
- - test/dummy/db/migrate/20160213102131_create_employers.rb
110
- - test/dummy/db/migrate/20160213101232_create_profiles.rb
111
- - test/dummy/db/migrate/20160213101213_create_users.rb
112
- - test/dummy/db/development.sqlite3
113
- - test/dummy/db/test.sqlite3
114
- - test/dummy/public/404.html
115
- - test/dummy/public/500.html
116
- - test/dummy/public/422.html
117
- - test/dummy/public/favicon.ico
118
- - test/dummy/config/secrets.yml
103
+ - test/dummy/app/views/layouts/application.html.erb
104
+ - test/dummy/bin/bundle
105
+ - test/dummy/bin/rails
106
+ - test/dummy/bin/rake
107
+ - test/dummy/bin/setup
108
+ - test/dummy/config.ru
119
109
  - test/dummy/config/application.rb
120
- - test/dummy/config/routes.rb
110
+ - test/dummy/config/boot.rb
111
+ - test/dummy/config/database.yml
112
+ - test/dummy/config/environment.rb
121
113
  - test/dummy/config/environments/development.rb
122
- - test/dummy/config/environments/test.rb
123
114
  - test/dummy/config/environments/production.rb
124
- - test/dummy/config/environment.rb
125
- - test/dummy/config/database.yml
126
- - test/dummy/config/locales/en.yml
127
- - test/dummy/config/initializers/wrap_parameters.rb
115
+ - test/dummy/config/environments/test.rb
116
+ - test/dummy/config/initializers/assets.rb
128
117
  - test/dummy/config/initializers/backtrace_silencers.rb
129
118
  - test/dummy/config/initializers/cookies_serializer.rb
130
- - test/dummy/config/initializers/session_store.rb
131
- - test/dummy/config/initializers/inflections.rb
132
119
  - test/dummy/config/initializers/filter_parameter_logging.rb
133
- - test/dummy/config/initializers/assets.rb
120
+ - test/dummy/config/initializers/inflections.rb
134
121
  - test/dummy/config/initializers/mime_types.rb
135
- - test/dummy/config/boot.rb
136
- - test/dummy/Rakefile
137
- - test/dummy/config.ru
122
+ - test/dummy/config/initializers/session_store.rb
123
+ - test/dummy/config/initializers/wrap_parameters.rb
124
+ - test/dummy/config/locales/en.yml
125
+ - test/dummy/config/routes.rb
126
+ - test/dummy/config/secrets.yml
127
+ - test/dummy/db/development.sqlite3
128
+ - test/dummy/db/migrate/20160213101213_create_users.rb
129
+ - test/dummy/db/migrate/20160213101232_create_profiles.rb
130
+ - test/dummy/db/migrate/20160213102131_create_employers.rb
131
+ - test/dummy/db/migrate/20160604081452_create_comments.rb
132
+ - test/dummy/db/schema.rb
133
+ - test/dummy/db/test.sqlite3
134
+ - test/dummy/log/development.log
135
+ - test/dummy/log/test.log
136
+ - test/dummy/public/404.html
137
+ - test/dummy/public/422.html
138
+ - test/dummy/public/500.html
139
+ - test/dummy/public/favicon.ico
138
140
  - test/support/spy_printer.rb
139
- homepage: http://www.gregnavis.com/active-record-doctor/
141
+ - test/test_helper.rb
142
+ homepage: https://github.com/gregnavis/active_record_doctor
140
143
  licenses:
141
144
  - MIT
142
145
  metadata: {}
@@ -146,17 +149,17 @@ require_paths:
146
149
  - lib
147
150
  required_ruby_version: !ruby/object:Gem::Requirement
148
151
  requirements:
149
- - - '>='
152
+ - - ">="
150
153
  - !ruby/object:Gem::Version
151
154
  version: '0'
152
155
  required_rubygems_version: !ruby/object:Gem::Requirement
153
156
  requirements:
154
- - - '>='
157
+ - - ">="
155
158
  - !ruby/object:Gem::Version
156
159
  version: '0'
157
160
  requirements: []
158
161
  rubyforge_project:
159
- rubygems_version: 2.0.14
162
+ rubygems_version: 2.5.1
160
163
  signing_key:
161
164
  specification_version: 4
162
165
  summary: A cure for your Active Record ailments.
@@ -178,9 +181,11 @@ test_files:
178
181
  - test/dummy/app/assets/javascripts/application.js
179
182
  - test/dummy/app/views/layouts/application.html.erb
180
183
  - test/dummy/app/models/profile.rb
184
+ - test/dummy/app/models/comment.rb
181
185
  - test/dummy/app/models/employer.rb
182
186
  - test/dummy/app/models/user.rb
183
187
  - test/dummy/db/schema.rb
188
+ - test/dummy/db/migrate/20160604081452_create_comments.rb
184
189
  - test/dummy/db/migrate/20160213102131_create_employers.rb
185
190
  - test/dummy/db/migrate/20160213101232_create_profiles.rb
186
191
  - test/dummy/db/migrate/20160213101213_create_users.rb
data/README.rdoc DELETED
@@ -1,84 +0,0 @@
1
- = Active Record Doctor
2
-
3
- Active Record Doctor helps to keep the database in a good shape. Currently, it
4
- can:
5
-
6
- * index unindexed foreign keys
7
- * detect extraneous indexes
8
-
9
- More features coming soon!
10
-
11
- Want to suggest a feature? Just shoot me {an email}[mailto:contact@gregnavis.com].
12
-
13
- {<img src="https://travis-ci.org/gregnavis/active_record_doctor.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/gregnavis/active_record_doctor]
14
-
15
- == Installation
16
-
17
- The preferred installation method is adding +active_record_doctor+ to your
18
- +Gemfile+:
19
-
20
- gem 'active_record_doctor', group: :development
21
-
22
- Then run:
23
-
24
- bundle install
25
-
26
- == Usage
27
-
28
- === Indexing Unindexed Foreign Keys
29
-
30
- Foreign keys should be indexed unless it's proven ineffective. However, Rails
31
- makes it easy to create an unindexed foreign key. Active Record Doctor can
32
- automatically generate database migrations that add the missing indexes. It's a
33
- three-step process:
34
-
35
- 1. Generate a list of unindexed foreign keys by running
36
-
37
- rake active_record_doctor:unindexed_foreign_keys > unindexed_foreign_keys.txt
38
-
39
- 2. Remove columns that should _not_ be indexed from +unindexed_foreign_keys.txt+
40
- as a column can look like a foreign key (i.e. end with +_id+) without being
41
- one.
42
-
43
- 3. Generate the migrations
44
-
45
- rails generate active_record_doctor:add_indexes unindexed_foreign_keys.txt
46
-
47
- 4. Run the migrations
48
-
49
- rake db:migrate
50
-
51
- === Removing Extraneous Indexes
52
-
53
- Let me illustrate with an example. Consider a +users+ table with columns
54
- +first_name+ and +last_name+. If there are two indexes:
55
-
56
- * A two-column index on +last_name, first_name+.
57
- * A single-column index on +last_name+.
58
-
59
- Then the latter index can be dropped as the former can play its role. In
60
- general, a multi-column index on +column_1, column_2, ..., column_n+ can replace
61
- indexes on:
62
-
63
- * +column_1+
64
- * +column_1+, +column_2+
65
- * ...
66
- * +column_1+, +column_2+, ..., +column_(n - 1)+
67
-
68
- To discover such indexes automatically just follow these steps:
69
-
70
- 1. List extraneous indexes by running:
71
-
72
- rake active_record_doctor:extraneous_indexes
73
-
74
- 2. Confirm that each of the indexes can be indeed dropped.
75
-
76
- 3. Create a migration to drop the indexes.
77
-
78
- The indexes aren't dropped automatically because there's usually just a few of
79
- them and it's a good idea to double-check that you won't drop something
80
- necessary.
81
-
82
- == Author
83
-
84
- This gem is developed and maintained by {Greg Navis}[http://www.gregnavis.com].