lol_dba 1.6.5 → 1.6.6
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 +4 -4
- data/README.md +1 -0
- data/lib/lol_dba.rb +3 -6
- data/lib/lol_dba/version.rb +1 -1
- data/spec/associations_index_spec.rb +12 -4
- data/spec/fixtures/app/models/gift.rb +1 -5
- data/spec/fixtures/app/models/user.rb +0 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac0b85b66b11cef7a5a9f061f9882e174ebd6873
|
4
|
+
data.tar.gz: dc82fa017c77d78ba1d29e2ab7eea95713f0d7a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4104dea3e0f47a9af87cebd86baa446088b2e4bbebceedadfa57f753fa2e55cccd2c47278ae1906d7d77eb7464c8fb70c75c65e4da3f868bbaddec1fc579af6c
|
7
|
+
data.tar.gz: 772690ccc91087cec77b7b2451fdf246638351f3d821b8c581b828bdff64777c9d94847d4d934d8ca9b155a3397b3213f8dd7dedfab6d3a5f4365b576c7a2c2a
|
data/README.md
CHANGED
@@ -74,6 +74,7 @@ All feedback, bug reports and thoughts on this gratefully received.
|
|
74
74
|
* [Adrian Hooper](https://twitter.com/PaReeOhNos)
|
75
75
|
* [Ray Zane](https://github.com/rzane)
|
76
76
|
* [Grant Gongaware](https://github.com/ggongaware)
|
77
|
+
* [Przemysław “Szeryf” Kowalczyk](https://szeryf.wordpress.com)
|
77
78
|
* [Philipp Weissensteiner](http://philippweissensteiner.com)
|
78
79
|
|
79
80
|
### License
|
data/lib/lol_dba.rb
CHANGED
@@ -28,8 +28,6 @@ EOM
|
|
28
28
|
# Guess foreign key?
|
29
29
|
if reflection.options[:foreign_key]
|
30
30
|
association_foreign_key = reflection.options[:foreign_key]
|
31
|
-
elsif reflection.options[:class_name]
|
32
|
-
association_foreign_key = reflection.options[:class_name].foreign_key
|
33
31
|
else
|
34
32
|
association_foreign_key = "#{target_class.name.tableize.singularize}_id"
|
35
33
|
end
|
@@ -99,10 +97,10 @@ EOM
|
|
99
97
|
poly_type = "#{reflection_options.name.to_s}_type"
|
100
98
|
poly_id = "#{reflection_options.name.to_s}_id"
|
101
99
|
|
102
|
-
@index_migrations[@table_name
|
100
|
+
@index_migrations[@table_name] += [[poly_type, poly_id].sort] unless @index_migrations[@table_name].include?([poly_type, poly_id].sort)
|
103
101
|
else
|
104
102
|
foreign_key = reflection_options.options[:foreign_key] ||= reflection_options.respond_to?(:primary_key_name) ? reflection_options.primary_key_name : reflection_options.foreign_key
|
105
|
-
@index_migrations[@table_name
|
103
|
+
@index_migrations[@table_name] += [foreign_key.to_s] unless @index_migrations[@table_name].include?(foreign_key) || reflection_options.options.include?(:class)
|
106
104
|
end
|
107
105
|
when :has_and_belongs_to_many
|
108
106
|
table_name = reflection_options.options[:join_table] ||= [class_name.table_name, reflection_name.to_s].sort.join('_')
|
@@ -111,8 +109,7 @@ EOM
|
|
111
109
|
|
112
110
|
foreign_key = get_through_foreign_key(class_name, reflection_options)
|
113
111
|
|
114
|
-
composite_keys = [association_foreign_key, foreign_key]
|
115
|
-
|
112
|
+
composite_keys = [association_foreign_key, foreign_key].sort
|
116
113
|
@index_migrations[table_name.to_s] += [composite_keys] unless @index_migrations[table_name].include?(composite_keys)
|
117
114
|
when :has_many
|
118
115
|
# has_many tables are threaten by the other side of the relation
|
data/lib/lol_dba/version.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Collect indexes based on associations:" do
|
4
4
|
|
5
|
-
let
|
5
|
+
let(:lol_dba){ LolDba.check_for_indexes }
|
6
6
|
let(:relationship_indexes){ lol_dba[0] }
|
7
7
|
let(:warning_messages){ lol_dba[1] }
|
8
8
|
|
@@ -24,11 +24,17 @@ describe "Collect indexes based on associations:" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "find indexes for has_and_belongs_to_many" do
|
27
|
-
expect(relationship_indexes["companies_freelancers"]).to include(["
|
27
|
+
expect(relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
|
28
|
+
expect(relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
|
28
29
|
end
|
29
30
|
|
30
31
|
it "find indexes for has_and_belongs_to_many with custom join_table, primary and foreign keys" do
|
31
|
-
expect(relationship_indexes["purchases"]).to include(["
|
32
|
+
expect(relationship_indexes["purchases"]).to include(["buyer_id", "present_id"])
|
33
|
+
expect(relationship_indexes["purchases"]).not_to include(["present_id", "buyer_id"])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "find indexes for has_and_belongs_to_many but don't create the left_side index" do
|
37
|
+
expect(relationship_indexes["purchases"]).not_to include("left_side_id")
|
32
38
|
end
|
33
39
|
|
34
40
|
it "do not add an already existing index" do
|
@@ -37,6 +43,7 @@ describe "Collect indexes based on associations:" do
|
|
37
43
|
|
38
44
|
it "find indexes for has_many :through" do
|
39
45
|
expect(relationship_indexes["billable_weeks"]).to include(["remote_worker_id", "timesheet_id"])
|
46
|
+
expect(relationship_indexes["billable_weeks"]).not_to include(["billable_week_id", "remote_worker_id"])
|
40
47
|
end
|
41
48
|
|
42
49
|
it "find indexes for has_many :through with source and foreign key" do
|
@@ -64,7 +71,8 @@ describe "Collect indexes based on associations:" do
|
|
64
71
|
|
65
72
|
it "find indexes, than use custom class name option in association" do
|
66
73
|
expect(relationship_indexes["employers_freelancers"]).to be_nil
|
67
|
-
expect(relationship_indexes["companies_freelancers"]).to include(["
|
74
|
+
expect(relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
|
75
|
+
expect(relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
|
68
76
|
end
|
69
77
|
|
70
78
|
end
|
@@ -3,8 +3,4 @@ class Gift < ActiveRecord::Base
|
|
3
3
|
self.primary_key = :custom_primary_key
|
4
4
|
has_and_belongs_to_many :users, :join_table => "purchases", :association_foreign_key => 'buyer_id', :foreign_key => 'present_id'
|
5
5
|
|
6
|
-
|
7
|
-
Gift.find_all_by_name_and_price(name, price)
|
8
|
-
end
|
9
|
-
|
10
|
-
end
|
6
|
+
end
|
@@ -7,11 +7,4 @@ class User < ActiveRecord::Base
|
|
7
7
|
|
8
8
|
validates_uniqueness_of :name
|
9
9
|
|
10
|
-
def search_via_email(email = "user@domain.com")
|
11
|
-
self.find_by_email(email)
|
12
|
-
end
|
13
|
-
|
14
|
-
def search_via_email_and_name(email, name)
|
15
|
-
self.find_by_email_and_name(email, name)
|
16
|
-
end
|
17
10
|
end
|