schemy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -4,21 +4,43 @@ Schemy analyzes schema.rb to suggest new database indexes, providing a migration
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Add this line to your
|
7
|
+
Add this line to your rails app's Gemfile in the development group:
|
8
8
|
|
9
|
-
|
9
|
+
group :development do
|
10
|
+
gem 'schemy'
|
11
|
+
end
|
10
12
|
|
11
13
|
And then execute:
|
12
14
|
|
13
15
|
$ bundle
|
14
16
|
|
15
|
-
|
17
|
+
## Usage
|
16
18
|
|
17
|
-
|
19
|
+
Within your rails app, run
|
18
20
|
|
19
|
-
|
21
|
+
bundle exec rake schemy:indexes
|
22
|
+
|
23
|
+
## Customization
|
24
|
+
|
25
|
+
By default, schemy will index:
|
26
|
+
|
27
|
+
- foo**_id** (foreign keys)
|
28
|
+
- foo**_id** and foo**_type** (polymorphic associations)
|
29
|
+
- **type** (for STI)
|
30
|
+
|
31
|
+
To create custom indexing rules, create a file in your rails app called config/schemy.yml.
|
32
|
+
|
33
|
+
###Example config/schemy.yml:
|
34
|
+
|
35
|
+
indexed_columns:
|
36
|
+
- identifier
|
37
|
+
- - association_id
|
38
|
+
- identifier
|
39
|
+
|
40
|
+
With the above configuration, schemy will create:
|
20
41
|
|
21
|
-
|
42
|
+
- an index for any column called identifier
|
43
|
+
- a compound index for any table that has **both** association_id and identifier
|
22
44
|
|
23
45
|
## Contributing
|
24
46
|
|
@@ -8,8 +8,7 @@ require_relative 'fake_column'
|
|
8
8
|
module ActiveRecord
|
9
9
|
class Schema
|
10
10
|
|
11
|
-
DEFAULT_VALIDATORS = [
|
12
|
-
IdentifierValidator, TypeValidator]
|
11
|
+
DEFAULT_VALIDATORS = [CustomValidator, ForeignKeyValidator, TypeValidator]
|
13
12
|
|
14
13
|
def self.define(options= {}, &block)
|
15
14
|
schema = new
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'base_validator'
|
2
|
+
|
3
|
+
class CustomValidator < BaseValidator
|
4
|
+
|
5
|
+
def validate_column column
|
6
|
+
self.class.configured_column_combinations.each do |config_columns|
|
7
|
+
|
8
|
+
config_columns = Array(config_columns)
|
9
|
+
|
10
|
+
# Only validate this column if it's first in the combination config.
|
11
|
+
# This way we don't create duplicate indices.
|
12
|
+
if column == config_columns.first
|
13
|
+
# Only require an index if this table has all of the columns in the column combination.
|
14
|
+
return unless config_columns[1..-1].all? { |col| @table.has_column? col }
|
15
|
+
require_index config_columns
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.config_file_path
|
22
|
+
Rails.root.join 'config', 'schemy.yml'
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.configured_column_combinations
|
26
|
+
@configured_column_combinations ||= load_configured_column_combinations
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.load_configured_column_combinations
|
30
|
+
if File.exists? config_file_path
|
31
|
+
config = YAML.load_file config_file_path
|
32
|
+
config['indexed_columns']
|
33
|
+
else
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/schemy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-16 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Analyzes schema.rb to suggest new database indexes, providing a migration
|
15
15
|
file that can be used directly.
|
@@ -31,10 +31,9 @@ files:
|
|
31
31
|
- lib/schemy/fake_table.rb
|
32
32
|
- lib/schemy/railtie.rb
|
33
33
|
- lib/schemy/schema_checker.rb
|
34
|
-
- lib/schemy/validators/association_id_identifier_validator.rb
|
35
34
|
- lib/schemy/validators/base_validator.rb
|
35
|
+
- lib/schemy/validators/custom_validator.rb
|
36
36
|
- lib/schemy/validators/foreign_key_validator.rb
|
37
|
-
- lib/schemy/validators/identifier_validator.rb
|
38
37
|
- lib/schemy/validators/type_validator.rb
|
39
38
|
- lib/schemy/version.rb
|
40
39
|
- lib/tasks/schemy.rake
|
@@ -59,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
58
|
version: '0'
|
60
59
|
requirements: []
|
61
60
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.10
|
63
62
|
signing_key:
|
64
63
|
specification_version: 3
|
65
64
|
summary: Analyzes schema.rb to suggest new database indexes.
|