lol_dba 1.6.7 → 2.0.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: 4d22c2c708f37f6cc0d362a4f14a5cc793f7500a
4
- data.tar.gz: 40ef7243e0925d1cf8f6578ba17cf828954303ce
3
+ metadata.gz: 0ba7fdc2c7953969c50ccd82353b9e9162b6e21c
4
+ data.tar.gz: 4e15e8ce2c0c07dd96a8cbd29a6eac62b06fe117
5
5
  SHA512:
6
- metadata.gz: 53602c33e18f3660ec3ec01741edf97dd5a328cb524e5651cad67eae4483e8402178bf745aa5e40e158451971bd416c19098381b80855355d467d3d9c7af4b72
7
- data.tar.gz: d3de40d77b479e81d8523389a1b4e668b11706997113bfd4a67f0421c898ed25cfc410aa652b254bc8c072ab2f528cbed9e4485dd82222155d0853d8699fcf17
6
+ metadata.gz: e05dbb7d70f02e178a53a28014b3bd0ca56be77bde892512e8b6f4e124e4c25853548f44bbb4a531a7c1545d69c7925c9986b67ef3b881d547a056bbfa020afc
7
+ data.tar.gz: 0b005f850e1dc737e699c9052591c0a4e54454a3cda1deac9680e79f94384f332c2ff4ad271726e6721001e0ad4bfc1eeaff0908507b54f0946b78c891a2c840
data/Gemfile CHANGED
@@ -3,5 +3,6 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem "rails"
6
- gem "rspec-rails", "~> 3.0.0"
6
+ gem "rspec-rails"
7
+ gem "test-unit"
7
8
  gem "sqlite3"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lol_dba (1.6.6)
4
+ lol_dba (1.6.7)
5
5
  actionpack (>= 3.0, < 5.0)
6
6
  activerecord (>= 3.0, < 5.0)
7
7
  railties (>= 3.0, < 5.0)
@@ -96,22 +96,23 @@ GEM
96
96
  rake (>= 0.8.7)
97
97
  thor (>= 0.18.1, < 2.0)
98
98
  rake (10.4.2)
99
- rspec-core (3.0.4)
100
- rspec-support (~> 3.0.0)
101
- rspec-expectations (3.0.4)
99
+ rspec-core (3.2.2)
100
+ rspec-support (~> 3.2.0)
101
+ rspec-expectations (3.2.0)
102
102
  diff-lcs (>= 1.2.0, < 2.0)
103
- rspec-support (~> 3.0.0)
104
- rspec-mocks (3.0.4)
105
- rspec-support (~> 3.0.0)
106
- rspec-rails (3.0.2)
107
- actionpack (>= 3.0)
108
- activesupport (>= 3.0)
109
- railties (>= 3.0)
110
- rspec-core (~> 3.0.0)
111
- rspec-expectations (~> 3.0.0)
112
- rspec-mocks (~> 3.0.0)
113
- rspec-support (~> 3.0.0)
114
- rspec-support (3.0.4)
103
+ rspec-support (~> 3.2.0)
104
+ rspec-mocks (3.2.1)
105
+ diff-lcs (>= 1.2.0, < 2.0)
106
+ rspec-support (~> 3.2.0)
107
+ rspec-rails (3.2.1)
108
+ actionpack (>= 3.0, < 4.3)
109
+ activesupport (>= 3.0, < 4.3)
110
+ railties (>= 3.0, < 4.3)
111
+ rspec-core (~> 3.2.0)
112
+ rspec-expectations (~> 3.2.0)
113
+ rspec-mocks (~> 3.2.0)
114
+ rspec-support (~> 3.2.0)
115
+ rspec-support (3.2.2)
115
116
  sprockets (2.12.3)
116
117
  hike (~> 1.2)
117
118
  multi_json (~> 1.0)
@@ -137,6 +138,6 @@ DEPENDENCIES
137
138
  appraisal (~> 1.0)
138
139
  lol_dba!
139
140
  rails
140
- rspec-rails (~> 3.0.0)
141
+ rspec-rails
141
142
  sqlite3
142
- test-unit (~> 3.0)
143
+ test-unit
data/README.md CHANGED
@@ -41,7 +41,7 @@ Use it the same way you use other rake commands
41
41
 
42
42
  ### Compatibility
43
43
 
44
- Compatible with Ruby 2.x and Rails 4.x (for now, we still support Ruby 1.9 and Rails 3.x).
44
+ Compatible with Ruby 2.x and Rails 3.x, 4.x.
45
45
 
46
46
  ### About primary_key
47
47
 
@@ -3,7 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails"
6
- gem "rspec-rails", "~> 3.0.0"
6
+ gem "rspec-rails"
7
+ gem "test-unit"
7
8
  gem "sqlite3"
8
9
  gem "activerecord", "~> 3.2.21"
9
10
  gem "actionpack", "~> 3.2.21"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- lol_dba (1.6.6)
4
+ lol_dba (1.6.7)
5
5
  actionpack (>= 3.0, < 5.0)
6
6
  activerecord (>= 3.0, < 5.0)
7
7
  railties (>= 3.0, < 5.0)
@@ -121,6 +121,6 @@ DEPENDENCIES
121
121
  lol_dba!
122
122
  rails
123
123
  railties (~> 3.2.21)
124
- rspec-rails (~> 3.0.0)
124
+ rspec-rails
125
125
  sqlite3
126
- test-unit (~> 3.0)
126
+ test-unit
@@ -3,7 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails"
6
- gem "rspec-rails", "~> 3.0.0"
6
+ gem "rspec-rails"
7
+ gem "test-unit"
7
8
  gem "sqlite3"
8
9
  gem "activerecord", "~> 4.0.13"
9
10
  gem "actionpack", "~> 4.0.13"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- lol_dba (1.6.6)
4
+ lol_dba (1.6.7)
5
5
  actionpack (>= 3.0, < 5.0)
6
6
  activerecord (>= 3.0, < 5.0)
7
7
  railties (>= 3.0, < 5.0)
@@ -109,6 +109,6 @@ DEPENDENCIES
109
109
  lol_dba!
110
110
  rails
111
111
  railties (~> 4.0.13)
112
- rspec-rails (~> 3.0.0)
112
+ rspec-rails
113
113
  sqlite3
114
- test-unit (~> 3.0)
114
+ test-unit
@@ -3,7 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails"
6
- gem "rspec-rails", "~> 3.0.0"
6
+ gem "rspec-rails"
7
+ gem "test-unit"
7
8
  gem "sqlite3"
8
9
  gem "activerecord", "~> 4.1.9"
9
10
  gem "actionpack", "~> 4.1.9"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- lol_dba (1.6.6)
4
+ lol_dba (1.6.7)
5
5
  actionpack (>= 3.0, < 5.0)
6
6
  activerecord (>= 3.0, < 5.0)
7
7
  railties (>= 3.0, < 5.0)
@@ -115,6 +115,6 @@ DEPENDENCIES
115
115
  lol_dba!
116
116
  rails
117
117
  railties (~> 4.1.9)
118
- rspec-rails (~> 3.0.0)
118
+ rspec-rails
119
119
  sqlite3
120
- test-unit (~> 3.0)
120
+ test-unit
@@ -3,7 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails"
6
- gem "rspec-rails", "~> 3.0.0"
6
+ gem "rspec-rails"
7
+ gem "test-unit"
7
8
  gem "sqlite3"
8
9
  gem "activerecord", "~> 4.2.0"
9
10
  gem "actionpack", "~> 4.2.0"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- lol_dba (1.6.6)
4
+ lol_dba (1.6.7)
5
5
  actionpack (>= 3.0, < 5.0)
6
6
  activerecord (>= 3.0, < 5.0)
7
7
  railties (>= 3.0, < 5.0)
@@ -140,6 +140,6 @@ DEPENDENCIES
140
140
  lol_dba!
141
141
  rails
142
142
  railties (~> 4.2.0)
143
- rspec-rails (~> 3.0.0)
143
+ rspec-rails
144
144
  sqlite3
145
- test-unit (~> 3.0)
145
+ test-unit
@@ -18,10 +18,10 @@ EOM
18
18
  end
19
19
 
20
20
  def self.get_through_foreign_key(target_class, reflection_options)
21
- if target_class.reflections[reflection_options.options[:through].to_s]
22
- # has_many :through
23
- reflection = target_class.reflections[reflection_options.options[:through].to_s]
24
- else
21
+ # has_many :through
22
+ reflection = target_class.reflections[reflection_options.options[:through].to_s]
23
+
24
+ unless reflection
25
25
  # has_and_belongs_to_many
26
26
  reflection = reflection_options
27
27
  end
@@ -85,22 +85,25 @@ EOM
85
85
 
86
86
  model_classes.each do |class_name|
87
87
  unless class_name.descends_from_active_record?
88
- @index_migrations[class_name.base_class.table_name] += [[class_name.inheritance_column, class_name.base_class.primary_key].sort] unless @index_migrations[class_name.base_class.table_name].include?([class_name.inheritance_column, class_name.base_class.primary_key].sort)
88
+ index_name = [class_name.inheritance_column, class_name.base_class.primary_key].sort
89
+ @index_migrations[class_name.base_class.table_name] += [index_name]
89
90
  end
90
- class_name.reflections.each_pair do |reflection_name, reflection_options|
91
+ reflections = class_name.reflections.stringify_keys
92
+ reflections.each_pair do |reflection_name, reflection_options|
91
93
  begin
94
+ index_name = ""
92
95
  case reflection_options.macro
93
96
  when :belongs_to
94
97
  # polymorphic?
95
- @table_name = class_name.table_name.to_s
96
- if reflection_options.options.has_key?(:polymorphic) && (reflection_options.options[:polymorphic] == true)
98
+ table_name = class_name.table_name
99
+ if reflection_options.options[:polymorphic]
97
100
  poly_type = "#{reflection_options.name.to_s}_type"
98
101
  poly_id = "#{reflection_options.name.to_s}_id"
99
102
 
100
- @index_migrations[@table_name] += [[poly_type, poly_id].sort] unless @index_migrations[@table_name].include?([poly_type, poly_id].sort)
103
+ index_name = [[poly_type, poly_id].sort]
101
104
  else
102
105
  foreign_key = reflection_options.options[:foreign_key] ||= reflection_options.respond_to?(:primary_key_name) ? reflection_options.primary_key_name : reflection_options.foreign_key
103
- @index_migrations[@table_name] += [foreign_key.to_s] unless @index_migrations[@table_name].include?(foreign_key) || reflection_options.options.include?(:class)
106
+ index_name = foreign_key.to_s
104
107
  end
105
108
  when :has_and_belongs_to_many
106
109
  table_name = reflection_options.options[:join_table] ||= [class_name.table_name, reflection_name.to_s].sort.join('_')
@@ -109,12 +112,11 @@ EOM
109
112
 
110
113
  foreign_key = get_through_foreign_key(class_name, reflection_options)
111
114
 
112
- composite_keys = [association_foreign_key, foreign_key].sort
113
- @index_migrations[table_name.to_s] += [composite_keys] unless @index_migrations[table_name].include?(composite_keys)
115
+ index_name = [association_foreign_key, foreign_key].sort
114
116
  when :has_many
115
117
  # has_many tables are threaten by the other side of the relation
116
118
  next unless reflection_options.options[:through]
117
- through_class = class_name.reflections.stringify_keys[reflection_options.options[:through].to_s].klass
119
+ through_class = reflections[reflection_options.options[:through].to_s].klass
118
120
  table_name = through_class.table_name
119
121
 
120
122
  foreign_key = get_through_foreign_key(class_name, reflection_options)
@@ -124,18 +126,18 @@ EOM
124
126
  association_foreign_key = get_through_foreign_key(association_class, reflection_options)
125
127
  else
126
128
  # go to joining model through has_many and find belongs_to
127
- blg_to_reflection = class_name.reflections.stringify_keys[reflection_options.options[:through].to_s]
128
- blg_to_class = blg_to_reflection.class_name.constantize
129
-
130
- # get foreign_key from belongs_to
131
- association_foreign_key = blg_to_class.reflections.stringify_keys[reflection_name.to_s.singularize.to_s].options[:foreign_key]
129
+ association_foreign_key = through_class.reflections.stringify_keys[reflection_name.singularize].options[:foreign_key]
132
130
  end
133
131
 
134
132
  #FIXME currently we don't support :through => :another_regular_has_many_and_non_through_relation
135
133
  next if association_foreign_key.nil?
136
- composite_keys = [association_foreign_key.to_s, foreign_key.to_s].sort
137
- @index_migrations[table_name] += [composite_keys] unless @index_migrations[table_name].include?(composite_keys)
134
+ index_name = [association_foreign_key.to_s, foreign_key.to_s].sort
138
135
  end
136
+
137
+ unless index_name == "" || reflection_options.options.include?(:class)
138
+ @index_migrations[table_name] += [index_name]
139
+ end
140
+
139
141
  rescue Exception => e
140
142
  puts "Some errors here:"
141
143
  puts "Please, create an issue with the following information here https://github.com/plentz/lol_dba/issues:"
@@ -1,3 +1,3 @@
1
1
  module LolDba
2
- VERSION = "1.6.7" unless defined? LolDba::VERSION
2
+ VERSION = "2.0.0" unless defined? LolDba::VERSION
3
3
  end
@@ -24,5 +24,4 @@ Gem::Specification.new do |s|
24
24
  s.add_dependency "railties", ">= 3.0", "< 5.0"
25
25
 
26
26
  s.add_development_dependency "appraisal", "~> 1.0"
27
- s.add_development_dependency "test-unit", "~> 3.0"
28
27
  end
@@ -15,6 +15,8 @@ module Rails
15
15
  end
16
16
  end
17
17
  Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require_dependency file }
18
+
19
+ ActiveRecord::Schema.verbose = false
18
20
  load 'fixtures/schema.rb'
19
21
 
20
22
  root_dir = File.dirname(__FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lol_dba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.7
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Plentz
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-03-21 00:00:00.000000000 Z
15
+ date: 2015-04-19 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord
@@ -88,20 +88,6 @@ dependencies:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
90
  version: '1.0'
91
- - !ruby/object:Gem::Dependency
92
- name: test-unit
93
- requirement: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '3.0'
98
- type: :development
99
- prerelease: false
100
- version_requirements: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: '3.0'
105
91
  description: lol_dba is a small package of rake tasks that scan your application models
106
92
  and displays a list of columns that probably should be indexed. Also, it can generate
107
93
  .sql migration scripts.