index_shotgun 0.1.0.beta3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efda005b97a48619e646d6ea190aba4d89722d8a
4
- data.tar.gz: 8ada78e2d7b1a7539136b19f86fddc04507cea9e
3
+ metadata.gz: dfe6dfc045c77c91c8be0ccbe3ed00c8e08bcdf1
4
+ data.tar.gz: 654edf6cec790e269a176382b33d52000dcff049
5
5
  SHA512:
6
- metadata.gz: 174c177214b9d24e301b99078a88f6d4400a6a59532cd99672e8721ca44221976f7b9662bff6967b693286e6011940ace8bf54469bb76f64d36513116a61c913
7
- data.tar.gz: b75f81cad3c703a90981c631540fc9248da42f561037284de5cc28af9f0f81c9aa87de33b7513de5a2459dd8c4ed2a1c2a593e9e53dbd6aae4dbe2f32bb29b22
6
+ metadata.gz: 3845b88c538a92785934ec8943ffc536bf674afdb003ae7e3994c1bdc3e9a32edc944a02c18acb3a42498c2655f49c33cd7bc1b0aaee356c4e9a9d6e4f3509d1
7
+ data.tar.gz: 8d35c3e9b0f9184980cab2bbb52f44acebafe6fabee04cdff9297290474fb4abbf02568f7b9170bfc461945a3da34018bc385b879a3eb00904e8aca377d1afa1
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Change Log
2
+
3
+ ## [v0.1.0.beta2](https://github.com/sue445/index_shotgun/tree/v0.1.0.beta2) (2015/09/16)
4
+ [Full Changelog](https://github.com/sue445/index_shotgun/compare/v0.1.0.beta1...v0.1.0.beta2)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - Impl client [\#7](https://github.com/sue445/index_shotgun/pull/7) ([sue445](https://github.com/sue445))
9
+ - Impl index\_shotgun:fire [\#6](https://github.com/sue445/index_shotgun/pull/6) ([sue445](https://github.com/sue445))
10
+ - Impl perform [\#5](https://github.com/sue445/index_shotgun/pull/5) ([sue445](https://github.com/sue445))
11
+ - Feature/rubocop [\#3](https://github.com/sue445/index_shotgun/pull/3) ([sue445](https://github.com/sue445))
12
+ - Setup codeclimate, coveralls [\#2](https://github.com/sue445/index_shotgun/pull/2) ([sue445](https://github.com/sue445))
13
+ - Setup travis [\#1](https://github.com/sue445/index_shotgun/pull/1) ([sue445](https://github.com/sue445))
14
+
15
+ ## [v0.1.0.beta1](https://github.com/sue445/index_shotgun/tree/v0.1.0.beta1) (2015/09/06)
16
+
17
+
18
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -1,34 +1,120 @@
1
- # IndexShotgun
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/index_shotgun`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
1
+ # IndexShotgun :fire: :gun: :cop:
7
2
  [![Gem Version](https://badge.fury.io/rb/index_shotgun.svg)](http://badge.fury.io/rb/index_shotgun)
8
3
  [![Build Status](https://travis-ci.org/sue445/index_shotgun.svg?branch=master)](https://travis-ci.org/sue445/index_shotgun)
9
4
  [![Code Climate](https://codeclimate.com/github/sue445/index_shotgun/badges/gpa.svg)](https://codeclimate.com/github/sue445/index_shotgun)
10
5
  [![Coverage Status](https://coveralls.io/repos/sue445/index_shotgun/badge.svg?branch=master&service=github)](https://coveralls.io/github/sue445/index_shotgun?branch=master)
11
6
  [![Dependency Status](https://gemnasium.com/sue445/index_shotgun.svg)](https://gemnasium.com/sue445/index_shotgun)
12
7
 
8
+ Duplicate index checker.
9
+
10
+ This like [pt-duplicate-key-checker](https://www.percona.com/doc/percona-toolkit/2.1/pt-duplicate-key-checker.html), but also supports database other than MySQL
11
+
12
+ ## Example
13
+ ```sh
14
+ $ index_shotgun postgresql --database=index_shotgun_test
15
+ # =============================
16
+ # user_stocks
17
+ # =============================
18
+
19
+ # index_user_stocks_on_user_id is a left-prefix of index_user_stocks_on_user_id_and_article_id
20
+ # To remove this duplicate index, execute:
21
+ ALTER TABLE `user_stocks` DROP INDEX `index_user_stocks_on_user_id`;
22
+
23
+ # =============================
24
+ # user_stocks
25
+ # =============================
26
+
27
+ # 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
28
+ # To remove this duplicate index, execute:
29
+ ALTER TABLE `user_stocks` DROP INDEX `index_user_stocks_on_user_id_and_article_id_and_already_read`;
30
+
31
+ # =============================
32
+ # user_stocks
33
+ # =============================
34
+
35
+ # index_user_stocks_on_user_id is a left-prefix of index_user_stocks_on_user_id_and_article_id_and_already_read
36
+ # To remove this duplicate index, execute:
37
+ ALTER TABLE `user_stocks` DROP INDEX `index_user_stocks_on_user_id`;
38
+
39
+ # ########################################################################
40
+ # Summary of indexes
41
+ # ########################################################################
42
+
43
+ # Total Duplicate Indexes 3
44
+ # Total Indexes 6
45
+ # Total Tables 5
46
+ ```
47
+
48
+ ## Requirements
49
+ * Ruby 2.1+
50
+ * Database you want to use (ex. MySQL, PostgreSQL or SQLite3)
51
+
13
52
  ## Installation
14
53
 
15
54
  Add this line to your application's Gemfile:
16
55
 
17
56
  ```ruby
18
- gem 'index_shotgun'
57
+ group :development do
58
+ gem 'index_shotgun'
59
+ end
19
60
  ```
20
61
 
21
62
  And then execute:
22
63
 
23
- $ bundle
64
+ ```sh
65
+ $ bundle
66
+ ```
24
67
 
25
68
  Or install it yourself as:
26
69
 
27
- $ gem install index_shotgun
70
+ ```sh
71
+ $ gem install index_shotgun
72
+ ```
73
+
74
+ If you want to use as commandline tool, you need to install these gems.
75
+
76
+ ```sh
77
+ # MySQL
78
+ $ gem install mysql2 -v 0.3.20
79
+
80
+ # PostgreSQL
81
+ $ gem install pg
82
+
83
+ # sqlite3
84
+ $ gem install sqlite3
85
+ ```
86
+
87
+ **Details:** `index_shotgun` does not yet support `mysql2` v0.4+
28
88
 
29
89
  ## Usage
90
+ ### Ruby app
91
+
92
+ ```sh
93
+ $ bundle exec rake index_shotgun:fire
94
+ ```
30
95
 
31
- TODO: Write usage instructions here
96
+ run `fire` :fire: task
97
+
98
+ If you don't use Rails app, append this to `Rakefile`
99
+
100
+ ```ruby
101
+ require "index_shotgun/tasks"
102
+ ```
103
+
104
+ ### Command line
105
+ Support these commands
106
+
107
+ ```sh
108
+ $ index_shotgun
109
+ Commands:
110
+ index_shotgun help [COMMAND] # Describe available commands or one specific command
111
+ index_shotgun mysql --database=DATABASE # Search duplicate indexes on MySQL
112
+ index_shotgun postgresql --database=DATABASE # Search duplicate indexes on PostgreSQL
113
+ index_shotgun sqlite3 --database=DATABASE # Search duplicate indexes on sqlite3
114
+ index_shotgun version # Show index_shotgun version
115
+ ```
116
+
117
+ **Details:** check `index_shotgun help <database>`
32
118
 
33
119
  ## Development
34
120
 
@@ -45,3 +131,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445
45
131
 
46
132
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
47
133
 
134
+ ## FAQ
135
+ ### Q. The origin of the name?
136
+ A. **Index Shotgun** is one of SQL Antipatterns.
137
+
138
+ https://pragprog.com/book/bksqla/sql-antipatterns
@@ -57,10 +57,9 @@ module IndexShotgun
57
57
  next unless source_index.columns.start_with?(target_index.columns)
58
58
 
59
59
  if target_index.unique
60
- last_column = source_index.columns.last
61
60
  response << {
62
61
  index: source_index,
63
- result: "#{source_index.name} has unnecessary column #{last_column} (#{target_index.name} is unique index!)",
62
+ result: "#{source_index.name} has column(s) on the right side of unique index (#{target_index.name}). You can drop if low cardinality",
64
63
  }
65
64
  else
66
65
  response << {
@@ -5,31 +5,33 @@ require "active_support/core_ext/hash"
5
5
  module IndexShotgun
6
6
  class CLI < Thor
7
7
  desc "mysql", "Search duplicate indexes on MySQL"
8
- option :database, required: true
8
+ option :database, aliases: "d", required: true
9
9
  option :encoding, default: "utf8"
10
10
  option :pool, default: 5, type: :numeric
11
- option :host, default: "localhost"
12
- option :port, default: 3306, type: :numeric
13
- option :username
14
- option :password
11
+ option :host, aliases: "h", default: "localhost"
12
+ option :port, aliases: "P", default: 3306, type: :numeric
13
+ option :username, aliases: "u"
14
+ option :password, aliases: "p"
15
+ option :ask_password, default: false, type: :boolean
15
16
  def mysql
16
17
  analyze("mysql2")
17
18
  end
18
19
 
19
20
  desc "postgresql", "Search duplicate indexes on PostgreSQL"
20
- option :database, required: true
21
+ option :database, aliases: "d", required: true
21
22
  option :encoding, default: "utf8"
22
23
  option :pool, default: 5, type: :numeric
23
- option :host, default: "localhost"
24
- option :port, default: 5432, type: :numeric
25
- option :username
26
- option :password
24
+ option :host, aliases: "h", default: "localhost"
25
+ option :port, aliases: "P", default: 5432, type: :numeric
26
+ option :username, aliases: "u"
27
+ option :password, aliases: "p"
28
+ option :ask_password, default: false, type: :boolean
27
29
  def postgresql
28
30
  analyze("postgresql", "pg")
29
31
  end
30
32
 
31
33
  desc "sqlite3", "Search duplicate indexes on sqlite3"
32
- option :database, required: true
34
+ option :database, aliases: "d", required: true
33
35
  def sqlite3
34
36
  analyze("sqlite3")
35
37
  end
@@ -51,6 +53,10 @@ module IndexShotgun
51
53
  end
52
54
 
53
55
  config = options.reverse_merge(adapter: adapter_name)
56
+
57
+ ask_password = config.delete("ask_password")
58
+ config[:password] = ask("Input password (hidden):", echo: false) if ask_password
59
+
54
60
  ActiveRecord::Base.establish_connection(config)
55
61
  puts IndexShotgun::Analyzer.perform
56
62
  end
@@ -1,3 +1,3 @@
1
1
  module IndexShotgun
2
- VERSION = "0.1.0.beta3"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: index_shotgun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-17 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -235,6 +235,7 @@ files:
235
235
  - ".rubocop.yml"
236
236
  - ".rubocop_standard.yml"
237
237
  - ".travis.yml"
238
+ - CHANGELOG.md
238
239
  - Gemfile
239
240
  - LICENSE.txt
240
241
  - README.md
@@ -271,9 +272,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
271
272
  version: 2.1.0
272
273
  required_rubygems_version: !ruby/object:Gem::Requirement
273
274
  requirements:
274
- - - ">"
275
+ - - ">="
275
276
  - !ruby/object:Gem::Version
276
- version: 1.3.1
277
+ version: '0'
277
278
  requirements: []
278
279
  rubyforge_project:
279
280
  rubygems_version: 2.4.5.1