项目作者: sue445

项目描述 :
duplicate index checker :fire: :gun: :cop:
高级语言: Ruby
项目地址: git://github.com/sue445/index_shotgun.git
创建时间: 2015-09-06T15:22:01Z
项目社区:https://github.com/sue445/index_shotgun

开源协议:MIT License

下载


IndexShotgun :fire: :gun: :cop:

Gem Version
test
Code Climate

Duplicate index checker.

This like pt-duplicate-key-checker, but also supports database other than MySQL

Example

  1. $ index_shotgun postgresql --database=index_shotgun_test
  2. # =============================
  3. # user_stocks
  4. # =============================
  5. # index_user_stocks_on_user_id is a left-prefix of index_user_stocks_on_user_id_and_article_id
  6. # To remove this duplicate index, execute:
  7. ALTER TABLE `user_stocks` DROP INDEX `index_user_stocks_on_user_id`;
  8. # =============================
  9. # user_stocks
  10. # =============================
  11. # index_user_stocks_on_user_id_and_article_id_and_already_read has column(s) on the right side of unique index (index_user_stocks_on_user_id_and_article_id). You can drop if low cardinality
  12. # To remove this duplicate index, execute:
  13. ALTER TABLE `user_stocks` DROP INDEX `index_user_stocks_on_user_id_and_article_id_and_already_read`;
  14. # =============================
  15. # user_stocks
  16. # =============================
  17. # index_user_stocks_on_user_id is a left-prefix of index_user_stocks_on_user_id_and_article_id_and_already_read
  18. # To remove this duplicate index, execute:
  19. ALTER TABLE `user_stocks` DROP INDEX `index_user_stocks_on_user_id`;
  20. # ########################################################################
  21. # Summary of indexes
  22. # ########################################################################
  23. # Total Duplicate Indexes 3
  24. # Total Indexes 6
  25. # Total Tables 5

Requirements

  • Ruby 2.5+
  • Database you want to use (ex. MySQL, PostgreSQL or SQLite3)

Installation

Add this line to your application’s Gemfile:

  1. group :development do
  2. gem 'index_shotgun'
  3. end

And then execute:

  1. # MySQL
  2. $ bundle install --without oracle postgresql sqlite3
  3. # Oracle
  4. $ bundle install --without mysql postgresql sqlite3
  5. # PostgreSQL
  6. $ bundle install --without mysql oracle sqlite3
  7. # sqlite3
  8. $ bundle install --without mysql oracle postgresql

Or install it yourself as:

  1. $ gem install index_shotgun

If you want to use as commandline tool, you need to install these gems.

  1. # MySQL
  2. $ gem install mysql2
  3. # Oracle
  4. $ gem install activerecord-oracle_enhanced-adapter ruby-oci8
  5. # PostgreSQL
  6. $ gem install pg
  7. # sqlite3
  8. $ gem install sqlite3

Note: requirements activerecord gem v4.2.5+ when using mysql2 gem v0.4.0+

Usage

Ruby app

  1. $ bundle exec rake index_shotgun:fire

run fire :fire: task

If you don’t use Rails app, append this to Rakefile

  1. require "index_shotgun/tasks"

Command line

Support these commands

  1. $ index_shotgun
  2. Commands:
  3. index_shotgun help [COMMAND] # Describe available commands or one specific command
  4. index_shotgun mysql --database=DATABASE # Search duplicate indexes on MySQL
  5. index_shotgun oracle --database=DATABASE # Search duplicate indexes on Oracle
  6. index_shotgun postgresql --database=DATABASE # Search duplicate indexes on PostgreSQL
  7. index_shotgun sqlite3 --database=DATABASE # Search duplicate indexes on sqlite3
  8. index_shotgun version # Show index_shotgun version

Details: check index_shotgun help <database>

MySQL

  1. $ index_shotgun help mysql
  2. Usage:
  3. index_shotgun mysql d, --database=DATABASE
  4. Options:
  5. d, --database=DATABASE
  6. [--encoding=ENCODING]
  7. # Default: utf8
  8. [--pool=N]
  9. # Default: 5
  10. h, [--host=HOST]
  11. # Default: localhost
  12. P, [--port=N]
  13. # Default: 3306
  14. u, [--username=USERNAME]
  15. p, [--password=PASSWORD]
  16. [--ask-password], [--no-ask-password]
  17. Search duplicate indexes on MySQL

Oracle

  1. $ index_shotgun help oracle
  2. Usage:
  3. index_shotgun oracle d, --database=DATABASE
  4. Options:
  5. d, --database=DATABASE
  6. [--encoding=ENCODING]
  7. # Default: utf8
  8. [--pool=N]
  9. # Default: 5
  10. h, [--host=HOST]
  11. # Default: localhost
  12. P, [--port=N]
  13. # Default: 1521
  14. u, [--username=USERNAME]
  15. p, [--password=PASSWORD]
  16. [--ask-password], [--no-ask-password]
  17. Search duplicate indexes on Oracle

PostgreSQL

  1. $ index_shotgun help postgresql
  2. Usage:
  3. index_shotgun postgresql d, --database=DATABASE
  4. Options:
  5. d, --database=DATABASE
  6. [--encoding=ENCODING]
  7. # Default: utf8
  8. [--pool=N]
  9. # Default: 5
  10. h, [--host=HOST]
  11. # Default: localhost
  12. P, [--port=N]
  13. # Default: 5432
  14. u, [--username=USERNAME]
  15. p, [--password=PASSWORD]
  16. [--ask-password], [--no-ask-password]
  17. Search duplicate indexes on PostgreSQL

SQLite3

  1. $ index_shotgun help sqlite3
  2. Usage:
  3. index_shotgun sqlite3 d, --database=DATABASE
  4. Options:
  5. d, --database=DATABASE
  6. Search duplicate indexes on sqlite3

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment. Run bundle exec index_shotgun to use the gem in this directory, ignoring other installed copies of this gem.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/index_shotgun.

License

The gem is available as open source under the terms of the MIT License.

FAQ

Q. The origin of the name?

A. Index Shotgun is one of SQL Antipatterns.

https://pragprog.com/book/bksqla/sql-antipatterns