indexter 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +130 -0
- data/Rakefile +6 -0
- data/assets/inDexter_logo.jpg +0 -0
- data/assets/inDexter_logo.pxm +0 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/indexter.gemspec +40 -0
- data/lib/indexter/config.rb +60 -0
- data/lib/indexter/formatters/hash.rb +11 -0
- data/lib/indexter/formatters/json.rb +13 -0
- data/lib/indexter/formatters/pass_fail.rb +16 -0
- data/lib/indexter/formatters/table.rb +24 -0
- data/lib/indexter/null_config.rb +5 -0
- data/lib/indexter/railtie.rb +26 -0
- data/lib/indexter/validator.rb +85 -0
- data/lib/indexter/version.rb +3 -0
- data/lib/indexter.rb +21 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 911b90dad0000c96346c793a439a2fd6859e5163
|
4
|
+
data.tar.gz: 2b931a04a985f947c75e69abbfd8d68004314532
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3acabd76bfbd893a548cc5bb71da4fb7705bcc7093ad7856956c3c2b4fe6ea157e567ed0cfe5e76cc565f4906bd080404045adea9a9d2798f824364b7cb88ed
|
7
|
+
data.tar.gz: 5b755cdb57f2c4078c3e4e3d3ec006aa60d9dbc6ba6a6e1bb546f532d4fa8f6c9c30547f18c06962b64299f8007b29efeb3932269ca97f2e608fadb1a60c1228
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at chris@unbounce.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Chris Cummer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
<p align='center'>
|
2
|
+
<img src='assets/inDexter_logo.jpg' width="600" height="186" alt="inDexter logo" title="inDexter" />
|
3
|
+
</p>
|
4
|
+
|
5
|
+
A gem for discovering foreign key indexes that may be missing from your Rails project.
|
6
|
+
|
7
|
+
### Example
|
8
|
+
|
9
|
+
Given a Rails table like so:
|
10
|
+
|
11
|
+
```
|
12
|
+
ActiveRecord::Schema.define do
|
13
|
+
create_table :addresses, :force => true do |t|
|
14
|
+
t.string :street
|
15
|
+
...
|
16
|
+
t.integer :user_id
|
17
|
+
t.integer :property_id
|
18
|
+
end
|
19
|
+
|
20
|
+
add_index :addresses, :user_id
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
By default, **inDexter** will return a hash:
|
25
|
+
|
26
|
+
```
|
27
|
+
{:suffixes=>["_id", "_uuid"], :exclusions=>["schema_migrations"], :missing=>{"addresses" => ["property_id"]}}
|
28
|
+
```
|
29
|
+
|
30
|
+
which indicated that you that you might want to add an index on table `addresses` for the `property_id` column.
|
31
|
+
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
1. Add this line to your application's Gemfile:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
gem 'indexter'
|
39
|
+
```
|
40
|
+
|
41
|
+
2. And then execute:
|
42
|
+
|
43
|
+
$ bundle
|
44
|
+
|
45
|
+
Or install it yourself as:
|
46
|
+
|
47
|
+
$ gem install indexter
|
48
|
+
|
49
|
+
## Configuration
|
50
|
+
Indexter is configured by creating an `.indexter.yaml` file in the root directory of your project (at the same level as your `.gitignore` and `.ruby-version` file).
|
51
|
+
|
52
|
+
Into this file you define the output format, the tables to be excluded from analysis, and the extensions the denote the columns you want to analyze.
|
53
|
+
|
54
|
+
### format
|
55
|
+
The output format the results of the analysis should be displayed in. See **Formatters**, below, for more details.
|
56
|
+
|
57
|
+
### exclusions
|
58
|
+
A list of the tables you *do not* want to analyze.
|
59
|
+
|
60
|
+
### suffixes
|
61
|
+
A list of the column extensions that define which columns should probably be indexed.
|
62
|
+
|
63
|
+
### Example
|
64
|
+
|
65
|
+
```
|
66
|
+
format: table
|
67
|
+
exclusions:
|
68
|
+
- table: default_companies
|
69
|
+
- table: schema_migrations
|
70
|
+
- table: taggings
|
71
|
+
suffixes:
|
72
|
+
- _id
|
73
|
+
- _uuid
|
74
|
+
```
|
75
|
+
|
76
|
+
Indexter provides a convenience rake task for viewing your `.indexter.yaml` config file:
|
77
|
+
|
78
|
+
```
|
79
|
+
rake indexter:config
|
80
|
+
```
|
81
|
+
|
82
|
+
## Usage
|
83
|
+
|
84
|
+
### Rails Console
|
85
|
+
|
86
|
+
```
|
87
|
+
$ rails c
|
88
|
+
irb(main):001:0> Indexter.validate
|
89
|
+
=> {:suffixes=>["_id", "_uuid"], :exclusions=>["schema_migrations"], :missing=>{}}
|
90
|
+
```
|
91
|
+
In that example the project has no missing indexes.
|
92
|
+
|
93
|
+
```
|
94
|
+
$ rails c
|
95
|
+
irb(main):001:0> Indexter.validate
|
96
|
+
=> {:suffixes=>["_id", "_uuid"], :exclusions=>["schema_migrations"], :missing=>{"users"=>["active_company_id"]}}
|
97
|
+
```
|
98
|
+
In that example the `users` table is missing an index on `active_company_id`.
|
99
|
+
|
100
|
+
### Rake Task
|
101
|
+
|
102
|
+
```
|
103
|
+
$ bundle exec rake indexter:validate
|
104
|
+
{:suffixes=>["_id", "_uuid"], :exclusions=>["schema_migrations"], :missing=>{}}
|
105
|
+
```
|
106
|
+
In that example the project has no missing indexes.
|
107
|
+
|
108
|
+
```
|
109
|
+
$ bundle exec rake indexter:validate
|
110
|
+
{:suffixes=>["_id", "_uuid"], :exclusions=>["schema_migrations"], :missing=>{"users"=>["active_company_id"]}}
|
111
|
+
```
|
112
|
+
In that example the `users` table is missing an index on `active_company_id`.
|
113
|
+
|
114
|
+
## Formatters
|
115
|
+
|
116
|
+
Out of the box, inDexter returns a Ruby hash of the results. But maybe that's not what you want? Fortunately inDexter also provides a number of additional formatting options:
|
117
|
+
|
118
|
+
* `hash`: the default option, returns a Ruby hash
|
119
|
+
* `json`: renders the output as a JSON string
|
120
|
+
* `pass_fail`: like a Unix process, returns 0 if no missing index, `n` if missing indexes, where `n` is the number of missing indexes
|
121
|
+
* `table`: renders the output as an ASCII-art table
|
122
|
+
|
123
|
+
## Contributing
|
124
|
+
|
125
|
+
Bug reports and pull requests are welcome on GitHub at [Github: inDexter](https://github.com/senorprogrammer/indexter). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
126
|
+
|
127
|
+
## License
|
128
|
+
|
129
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
130
|
+
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "indexter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require "irb"
|
10
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/indexter.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'indexter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "indexter"
|
8
|
+
spec.version = Indexter::VERSION
|
9
|
+
spec.authors = ["Chris Cummer"]
|
10
|
+
spec.email = ["chriscummer@me.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Checks databases tables for indexes on foreign keys.}
|
13
|
+
spec.homepage = "https://github.com/senorprogrammer/indexter"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Production dependencies
|
32
|
+
spec.add_dependency "activerecord"
|
33
|
+
spec.add_dependency "sqlite3"
|
34
|
+
spec.add_dependency "rainbow"
|
35
|
+
spec.add_dependency "terminal-table"
|
36
|
+
|
37
|
+
# Development dependencies
|
38
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
39
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
40
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Indexter::Config
|
2
|
+
#
|
3
|
+
# Two ways to provide configuration information:
|
4
|
+
#
|
5
|
+
# 1. Pass a path to a YAML file in the constructor
|
6
|
+
# 2. Create a .indexter.yaml file in the root of the project directory,
|
7
|
+
# and Indexter::Config will find it automatically
|
8
|
+
#
|
9
|
+
# Note that if you have a .indexter.yaml file _and_ you pass in a file
|
10
|
+
# path, the file path will trump the default file and over-ride it.
|
11
|
+
#
|
12
|
+
require 'yaml'
|
13
|
+
|
14
|
+
module Indexter
|
15
|
+
class Config
|
16
|
+
attr_reader :config_file_path, :format, :exclusions, :suffixes
|
17
|
+
|
18
|
+
DEFAULT_CONFIG_FILE = './.indexter.yaml'.freeze
|
19
|
+
|
20
|
+
def initialize(config_file_path: DEFAULT_CONFIG_FILE)
|
21
|
+
@config_file_path = config_file_path
|
22
|
+
configure if exists?
|
23
|
+
end
|
24
|
+
|
25
|
+
def exists?
|
26
|
+
File.exists?(config_file_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_yaml
|
30
|
+
@data.to_yaml
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def configure
|
36
|
+
@data = YAML.load_stream(File.read(config_file_path))
|
37
|
+
return unless @data.any?
|
38
|
+
|
39
|
+
load_format(@data)
|
40
|
+
load_exclusions(@data)
|
41
|
+
load_suffixes(@data)
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_format(data)
|
45
|
+
@format = data.first.fetch('format', nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_exclusions(data)
|
49
|
+
@exclusions = data.first.fetch('exclusions', []).inject({}) do |acc, hash|
|
50
|
+
acc[hash['table']] = hash.fetch('columns', [])
|
51
|
+
acc
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_suffixes(data)
|
56
|
+
@suffixes = data.first.fetch('suffixes', [])
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Indexter
|
2
|
+
module Formatters
|
3
|
+
class PassFail
|
4
|
+
|
5
|
+
# Returns like a Unix process:
|
6
|
+
#
|
7
|
+
# - 0 : successful, no missing indexes
|
8
|
+
# - n : failure, returns the number of missing indexes
|
9
|
+
#
|
10
|
+
def format(payload)
|
11
|
+
payload.fetch(:missing, {}).flatten.count
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rainbow/ext/string'
|
2
|
+
require 'terminal-table'
|
3
|
+
|
4
|
+
module Indexter
|
5
|
+
module Formatters
|
6
|
+
class Table
|
7
|
+
|
8
|
+
def format(payload)
|
9
|
+
missing = payload.fetch(:missing, {})
|
10
|
+
|
11
|
+
rows = missing.inject([]) do |acc, (db_table, columns)|
|
12
|
+
acc << [db_table, columns.join("\n")]
|
13
|
+
acc << :separator
|
14
|
+
acc
|
15
|
+
end
|
16
|
+
|
17
|
+
headings = ['Table', 'Column'].map { |col| col.color(:blue).bright }
|
18
|
+
|
19
|
+
Terminal::Table.new(headings: headings, rows: rows).to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'indexter'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Indexter
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
railtie_name :indexter
|
7
|
+
|
8
|
+
rake_tasks do
|
9
|
+
namespace :indexter do
|
10
|
+
desc "Checks the database for missing foreign key indexes"
|
11
|
+
task :validate => :environment do |t, args|
|
12
|
+
config = Indexter::Config.new
|
13
|
+
puts Indexter::Validator.new(config: config).validate
|
14
|
+
end
|
15
|
+
|
16
|
+
task :config do |t, args|
|
17
|
+
config = Indexter::Config.new
|
18
|
+
puts config.to_yaml
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
task indexter: ['indexter:validate', 'indexter:config']
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Indexter
|
4
|
+
class Validator
|
5
|
+
attr_reader :exclusions, :formatter, :results, :suffixes
|
6
|
+
|
7
|
+
DEFAULT_FORMATTER = 'hash'
|
8
|
+
DEFAULT_EXCLUSIONS = { 'schema_migrations' => [] }.freeze
|
9
|
+
DEFAULT_SUFFIXES = ['_id', '_uuid'].freeze
|
10
|
+
|
11
|
+
# -------------------- Instance Methods --------------------
|
12
|
+
|
13
|
+
def initialize(config: nil)
|
14
|
+
configure(config)
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate
|
18
|
+
missing = missing_indexes(tables)
|
19
|
+
output = build_results(missing)
|
20
|
+
|
21
|
+
results = formatter.new.format(output)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def configure(config)
|
27
|
+
config = config || NullConfig.new
|
28
|
+
|
29
|
+
format = config.format || DEFAULT_FORMATTER
|
30
|
+
@formatter = find_formatter(format: format)
|
31
|
+
|
32
|
+
@exclusions = config.exclusions || DEFAULT_EXCLUSIONS
|
33
|
+
@suffixes = config.suffixes || DEFAULT_SUFFIXES
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_formatter(format: nil)
|
37
|
+
format = format || DEFAULT_FORMATTER
|
38
|
+
klass_name = "Indexter::Formatters::#{format.to_s.camelize}"
|
39
|
+
klass = klass_name.constantize
|
40
|
+
rescue NameError
|
41
|
+
# If an un-known formatter is passed here, fall back to the hash
|
42
|
+
Indexter::Formatters::Hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def missing_indexes(tbls)
|
46
|
+
# Check the intersection between what we expect to have indexes on and what we actually have
|
47
|
+
# indexes on. If the set is not empty, we might be missing an index
|
48
|
+
result = tbls.inject({}) do |acc, table|
|
49
|
+
acc[table] = (id_columns(table) - indexes(table))
|
50
|
+
acc
|
51
|
+
end
|
52
|
+
|
53
|
+
# Reject any tables that have empty results
|
54
|
+
result.delete_if { |_, missing| missing.empty? }
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns a list of all the tables in the database that are analysable
|
58
|
+
def tables
|
59
|
+
func = ActiveRecord::Base.connection.respond_to?(:data_sources) ? :data_sources : :tables
|
60
|
+
ActiveRecord::Base.connection.send(func) - @exclusions.keys
|
61
|
+
end
|
62
|
+
|
63
|
+
# These are the columns we expect to have an index on that end in COL_SUFFIX
|
64
|
+
def id_columns(table)
|
65
|
+
ActiveRecord::Base.connection.columns(table).select do |column|
|
66
|
+
column.name.end_with? *@suffixes
|
67
|
+
end.map(&:name)
|
68
|
+
end
|
69
|
+
|
70
|
+
# These are the columns we have indexes on that also end in COL_SUFFIX
|
71
|
+
def indexes(table)
|
72
|
+
ActiveRecord::Base.connection.indexes(table).map do |idx_def|
|
73
|
+
idx_def.columns.select { |col| col.end_with? *@suffixes }
|
74
|
+
end.flatten
|
75
|
+
end
|
76
|
+
|
77
|
+
def build_results(missing)
|
78
|
+
{
|
79
|
+
suffixes: @suffixes,
|
80
|
+
exclusions: @exclusions,
|
81
|
+
missing: missing
|
82
|
+
}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/indexter.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'indexter/config'
|
2
|
+
require 'indexter/null_config'
|
3
|
+
require 'indexter/railtie' if defined?(Rails)
|
4
|
+
require 'indexter/validator'
|
5
|
+
require 'indexter/version'
|
6
|
+
|
7
|
+
require 'indexter/formatters/hash'
|
8
|
+
require 'indexter/formatters/json'
|
9
|
+
require 'indexter/formatters/pass_fail'
|
10
|
+
require 'indexter/formatters/table'
|
11
|
+
|
12
|
+
module Indexter
|
13
|
+
extend self
|
14
|
+
|
15
|
+
def validate(config_file_path: Indexter::Config::DEFAULT_CONFIG_FILE)
|
16
|
+
config = Indexter::Config.new(config_file_path: config_file_path)
|
17
|
+
val = Indexter::Validator.new(config: config)
|
18
|
+
|
19
|
+
val.validate
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: indexter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Cummer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rainbow
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: terminal-table
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '12.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '12.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.5'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- chriscummer@me.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- assets/inDexter_logo.jpg
|
113
|
+
- assets/inDexter_logo.pxm
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- indexter.gemspec
|
117
|
+
- lib/indexter.rb
|
118
|
+
- lib/indexter/config.rb
|
119
|
+
- lib/indexter/formatters/hash.rb
|
120
|
+
- lib/indexter/formatters/json.rb
|
121
|
+
- lib/indexter/formatters/pass_fail.rb
|
122
|
+
- lib/indexter/formatters/table.rb
|
123
|
+
- lib/indexter/null_config.rb
|
124
|
+
- lib/indexter/railtie.rb
|
125
|
+
- lib/indexter/validator.rb
|
126
|
+
- lib/indexter/version.rb
|
127
|
+
homepage: https://github.com/senorprogrammer/indexter
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.6.10
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Checks databases tables for indexes on foreign keys.
|
151
|
+
test_files: []
|