Class: RailsBestPractices::Reviews::AlwaysAddDbIndexReview
- Inherits:
-
Review
- Object
- CodeAnalyzer::Checker
- Core::Check
- Review
- RailsBestPractices::Reviews::AlwaysAddDbIndexReview
- Defined in:
- lib/rails_best_practices/reviews/always_add_db_index_review.rb
Overview
Review db/schema.rb file to make sure every reference key has a database index.
See the best practice details here rails-bestpractices.com/posts/2010/07/24/always-add-db-index/
Implementation:
Review process:
only check the command and command_calls nodes and at the end of review process,
if the receiver of command node is "create_table", then remember the table names
if the receiver of command_call node is "integer" or "string" or "bigint" and suffix with _id, then remember it as foreign key
if the receiver of command_call node is "string", the name of it is _type suffixed and there is an integer or string column _id suffixed, then remember it as polymorphic foreign key
if the receiver of command_call node is remembered as foreign key and it have argument non-false "index", then remember the index columns
if the receiver of command node is "add_index", then remember the index columns
after all of these, at the end of review process
ActiveRecord::Schema.define(version: 20101201111111) do
......
end
if there are any foreign keys not existed in index columns,
then the foreign keys should add db index.
Constant Summary
Constants inherited from Core::Check
Core::Check::ALL_FILES, Core::Check::CAPFILE, Core::Check::CONFIG_FILES, Core::Check::CONTROLLER_FILES, Core::Check::DEPLOY_FILES, Core::Check::GEMFILE_LOCK, Core::Check::HELPER_FILES, Core::Check::INITIALIZER_FILES, Core::Check::MAILER_FILES, Core::Check::MIGRATION_FILES, Core::Check::MODEL_FILES, Core::Check::PARTIAL_VIEW_FILES, Core::Check::ROUTE_FILES, Core::Check::SCHEMA_FILE, Core::Check::SKIP_FILES, Core::Check::VIEW_FILES
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ AlwaysAddDbIndexReview
constructor
A new instance of AlwaysAddDbIndexReview.
Methods inherited from Review
#model_associations, #model_attributes, #models, #remember_variable_use_count, #reset_variable_use_count, #variable, #variable_use_count
Methods inherited from Core::Check
#add_error, debug, debug?, #errors, #is_ignored?, #is_interesting_file?, #method_missing, #parse_file?, #regex_ignored_files, #url, url
Constructor Details
#initialize(options = {}) ⇒ AlwaysAddDbIndexReview
Returns a new instance of AlwaysAddDbIndexReview.
31 32 33 34 35 36 |
# File 'lib/rails_best_practices/reviews/always_add_db_index_review.rb', line 31 def initialize( = {}) super() @index_columns = {} @foreign_keys = {} @table_nodes = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RailsBestPractices::Core::Check