datastax_rails 1.0.15 → 1.0.16.3
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.
- data/lib/datastax_rails/collection.rb +4 -0
- data/lib/datastax_rails/connection.rb +43 -7
- data/lib/datastax_rails/cql/base.rb +0 -1
- data/lib/datastax_rails/cql/update.rb +28 -26
- data/lib/datastax_rails/grouped_collection.rb +8 -0
- data/lib/datastax_rails/persistence.rb +4 -0
- data/lib/datastax_rails/railtie.rb +2 -1
- data/lib/datastax_rails/relation/search_methods.rb +120 -32
- data/lib/datastax_rails/relation/spawn_methods.rb +31 -6
- data/lib/datastax_rails/relation.rb +30 -9
- data/lib/datastax_rails/rsolr_client_wrapper.rb +1 -1
- data/lib/datastax_rails/tasks/column_family.rb +38 -11
- data/lib/datastax_rails/tasks/keyspace.rb +1 -1
- data/lib/datastax_rails/types/binary_type.rb +2 -0
- data/lib/datastax_rails/types/date_type.rb +1 -0
- data/lib/datastax_rails/types/string_type.rb +1 -2
- data/lib/datastax_rails/types/time_type.rb +1 -0
- data/lib/datastax_rails/version.rb +1 -1
- data/lib/datastax_rails.rb +1 -1
- data/spec/datastax_rails/relation/search_methods_spec.rb +44 -1
- data/spec/datastax_rails/validations/uniqueness_spec.rb +2 -2
- data/spec/dummy/config/datastax.yml +29 -22
- data/spec/dummy/config/datastax_rails.crt +18 -0
- data/spec/dummy/config/datastax_rails.key +15 -0
- data/spec/dummy/log/development.log +3 -0
- data/spec/dummy/log/test.log +2637 -0
- metadata +17 -24
@@ -108,26 +108,53 @@ module DatastaxRails
|
|
108
108
|
|
109
109
|
solr_url = "#{DatastaxRails::Base.solr_base_url}/resource/#{DatastaxRails::Base.config[:keyspace]}.#{model.column_family}"
|
110
110
|
uri = URI.parse(solr_url)
|
111
|
-
Net::HTTP.
|
112
|
-
|
113
|
-
|
111
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
112
|
+
if uri.scheme == 'https'
|
113
|
+
http.use_ssl = true
|
114
|
+
http.cert = OpenSSL::X509::Certificate.new(Rails.root.join("config","pow.crt").read)
|
115
|
+
http.key = OpenSSL::PKey::RSA.new(Rails.root.join("config","pow.key").read)
|
116
|
+
http.ca_path = Rails.root.join("config","sade_ca.crt").to_s
|
117
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
118
|
+
end
|
119
|
+
http.read_timeout = 300
|
120
|
+
if force || solrconfig_digest != sm_digests['solrconfig']
|
121
|
+
loop do
|
114
122
|
puts "Posting Solr Config file to '#{solr_url}/solrconfig.xml'"
|
115
123
|
http.post(uri.path+"/solrconfig.xml", solrconfig)
|
116
|
-
|
117
|
-
|
124
|
+
if Rails.env.production?
|
125
|
+
sleep(5)
|
126
|
+
resp = http.get(uri.path+"/solrconfig.xml")
|
127
|
+
continue unless resp.message == 'OK'
|
128
|
+
end
|
129
|
+
break
|
118
130
|
end
|
119
|
-
|
131
|
+
DatastaxRails::Cql::Update.new(SchemaMigration, model.column_family).columns(:solrconfig => solrconfig_digest).execute
|
132
|
+
end
|
133
|
+
if force || stopwords_digest != sm_digests['stopwords']
|
134
|
+
loop do
|
120
135
|
puts "Posting Solr Stopwords file to '#{solr_url}/stopwords.txt'"
|
121
136
|
http.post(uri.path+"/stopwords.txt", stopwords)
|
122
|
-
|
123
|
-
|
137
|
+
if Rails.env.production?
|
138
|
+
sleep(5)
|
139
|
+
resp = http.get(uri.path+"/stopwords.txt")
|
140
|
+
continue unless resp.message == 'OK'
|
141
|
+
end
|
142
|
+
break
|
124
143
|
end
|
125
|
-
|
144
|
+
DatastaxRails::Cql::Update.new(SchemaMigration, model.column_family).columns(:stopwords => stopwords_digest).execute
|
145
|
+
end
|
146
|
+
if force || schema_digest != sm_digests['digest']
|
147
|
+
loop do
|
126
148
|
puts "Posting Solr Schema file to '#{solr_url}/schema.xml'"
|
127
149
|
http.post(uri.path+"/schema.xml", schema)
|
128
|
-
|
129
|
-
|
150
|
+
if Rails.env.production?
|
151
|
+
sleep(5)
|
152
|
+
resp = http.get(uri.path+"/schema.xml")
|
153
|
+
continue unless resp.message == 'OK'
|
154
|
+
end
|
155
|
+
break
|
130
156
|
end
|
157
|
+
DatastaxRails::Cql::Update.new(SchemaMigration, model.column_family).columns(:digest => schema_digest).execute
|
131
158
|
end
|
132
159
|
end
|
133
160
|
end
|
@@ -8,7 +8,7 @@ module DatastaxRails
|
|
8
8
|
|
9
9
|
def create(name, options = {})
|
10
10
|
opts = { :name => name.to_s,
|
11
|
-
:strategy_class => 'org.apache.cassandra.locator.NetworkTopologyStrategy'}.merge(options)
|
11
|
+
:strategy_class => 'org.apache.cassandra.locator.NetworkTopologyStrategy'}.with_indifferent_access.merge(options)
|
12
12
|
|
13
13
|
if(exists?(name.to_s))
|
14
14
|
puts "Keyspace #{name.to_s} already exists"
|
@@ -5,6 +5,7 @@ module DatastaxRails
|
|
5
5
|
def encode(str)
|
6
6
|
raise ArgumentError.new("#{self} requires a String") unless str.kind_of?(String)
|
7
7
|
io = StringIO.new(Base64.encode64(str))
|
8
|
+
#io = StringIO.new(str)
|
8
9
|
chunks = []
|
9
10
|
while chunk = io.read(1.megabyte)
|
10
11
|
chunks << chunk
|
@@ -20,6 +21,7 @@ module DatastaxRails
|
|
20
21
|
end
|
21
22
|
io.rewind
|
22
23
|
Base64.decode64(io.read)
|
24
|
+
#io.read
|
23
25
|
else
|
24
26
|
arr
|
25
27
|
end
|
@@ -4,8 +4,7 @@ module DatastaxRails
|
|
4
4
|
DEFAULTS = {:solr_type => 'string', :indexed => true, :stored => true, :multi_valued => false, :sortable => true, :tokenized => false, :fulltext => true}
|
5
5
|
def encode(str)
|
6
6
|
str = "" unless str
|
7
|
-
|
8
|
-
str.dup
|
7
|
+
str.to_s
|
9
8
|
end
|
10
9
|
|
11
10
|
def wrap(record, name, value)
|
data/lib/datastax_rails.rb
CHANGED
@@ -79,12 +79,24 @@ describe DatastaxRails::Relation do
|
|
79
79
|
@relation.where(:complexity).greater_than(1.0).should_not be_empty
|
80
80
|
end
|
81
81
|
|
82
|
+
it "should allow :greater_than to be specified in a single call" do
|
83
|
+
Hobby.create(:name => 'Swimming', :complexity => 1.1)
|
84
|
+
@relation.commit_solr
|
85
|
+
@relation.where(:complexity => {:greater_than => 1.0}).should_not be_empty
|
86
|
+
end
|
87
|
+
|
82
88
|
it "should return documents where a value is less than the given value" do
|
83
89
|
Hobby.create(:name => 'Swimming', :complexity => 1.1)
|
84
90
|
@relation.commit_solr
|
85
91
|
@relation.where(:complexity).less_than(2.0).should_not be_empty
|
86
92
|
end
|
87
93
|
|
94
|
+
it "should allow :less_than to be specified in a single call" do
|
95
|
+
Hobby.create(:name => 'Swimming', :complexity => 1.1)
|
96
|
+
@relation.commit_solr
|
97
|
+
@relation.where(:complexity => {:less_than => 2.0}).should_not be_empty
|
98
|
+
end
|
99
|
+
|
88
100
|
it "should allow arrays to be passed as OR queries" do
|
89
101
|
%w[fishing hiking boating jogging swimming chess].each do |word|
|
90
102
|
Hobby.create(:name => word)
|
@@ -114,7 +126,7 @@ describe DatastaxRails::Relation do
|
|
114
126
|
end
|
115
127
|
|
116
128
|
it "should search for values within a range" do
|
117
|
-
Hobby.create(:name => '
|
129
|
+
Hobby.create(:name => 'jogging', :complexity => 1.2)
|
118
130
|
@relation.commit_solr
|
119
131
|
@relation.where(:complexity => 1..2).should_not be_empty
|
120
132
|
@relation.where(:complexity => 2..3).should be_empty
|
@@ -134,6 +146,37 @@ describe DatastaxRails::Relation do
|
|
134
146
|
@relation.commit_solr
|
135
147
|
@relation.where_not(:name => ['Swimming','Biking']).should be_empty
|
136
148
|
end
|
149
|
+
|
150
|
+
it "should return documents where a value is not greater than the given value" do
|
151
|
+
Hobby.create(:name => 'Swimming', :complexity => 1.1)
|
152
|
+
@relation.commit_solr
|
153
|
+
@relation.where_not(:complexity).greater_than(2.0).should_not be_empty
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should allow :greater_than to be specified in a single call" do
|
157
|
+
Hobby.create(:name => 'Swimming', :complexity => 1.1)
|
158
|
+
@relation.commit_solr
|
159
|
+
@relation.where_not(:complexity => {:greater_than => 2.0}).should_not be_empty
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return documents where a value is not less than the given value" do
|
163
|
+
Hobby.create(:name => 'Swimming', :complexity => 1.1)
|
164
|
+
@relation.commit_solr
|
165
|
+
@relation.where_not(:complexity).less_than(1.0).should_not be_empty
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should allow :less_than to be specified in a single call" do
|
169
|
+
Hobby.create(:name => 'Swimming', :complexity => 1.1)
|
170
|
+
@relation.commit_solr
|
171
|
+
@relation.where_not(:complexity => {:less_than => 1.0}).should_not be_empty
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should search for values outside a range" do
|
175
|
+
Hobby.create(:name => 'jogging', :complexity => 1.2)
|
176
|
+
@relation.commit_solr
|
177
|
+
@relation.where_not(:complexity => 1..2).should be_empty
|
178
|
+
@relation.where_not(:complexity => 2..3).should_not be_empty
|
179
|
+
end
|
137
180
|
end
|
138
181
|
|
139
182
|
describe "#fulltext" do
|
@@ -13,9 +13,9 @@ describe DatastaxRails::Base do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should allow an update to a model without triggering a uniqueness error" do
|
16
|
-
p=Person.create!(:name => "Jason", :birthdate => Date.
|
16
|
+
p=Person.create!(:name => "Jason", :birthdate => Date.strptime("10/19/1985", '%m/%d/%Y'))
|
17
17
|
Person.commit_solr
|
18
|
-
p.birthdate = Date.
|
18
|
+
p.birthdate = Date.strptime("10/19/1980", '%m/%d/%Y')
|
19
19
|
p.save!
|
20
20
|
end
|
21
21
|
|
@@ -1,22 +1,29 @@
|
|
1
|
-
development:
|
2
|
-
servers: ["
|
3
|
-
keyspace: "datastax_rails_development"
|
4
|
-
strategy_class: "org.apache.cassandra.locator.SimpleStrategy"
|
5
|
-
strategy_options: {"
|
6
|
-
connection_options:
|
7
|
-
timeout: 10
|
8
|
-
solr:
|
9
|
-
port:
|
10
|
-
path: /solr
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
development:
|
2
|
+
servers: ["127.0.0.1:9160"]
|
3
|
+
keyspace: "datastax_rails_development"
|
4
|
+
strategy_class: "org.apache.cassandra.locator.SimpleStrategy"
|
5
|
+
strategy_options: {"replication_factor": "1"}
|
6
|
+
connection_options:
|
7
|
+
timeout: 10
|
8
|
+
solr:
|
9
|
+
port: 8984
|
10
|
+
path: /solr
|
11
|
+
ssl:
|
12
|
+
use_ssl: true
|
13
|
+
cert: config/datastax_rails.crt
|
14
|
+
key: config/datastax_rails.key
|
15
|
+
|
16
|
+
test:
|
17
|
+
servers: ["127.0.0.1:9160"]
|
18
|
+
keyspace: "datastax_rails_test"
|
19
|
+
strategy_class: "org.apache.cassandra.locator.SimpleStrategy"
|
20
|
+
strategy_options: {"replication_factor": "1"}
|
21
|
+
connection_options:
|
22
|
+
timeout: 10
|
23
|
+
solr:
|
24
|
+
port: 8984
|
25
|
+
path: /solr
|
26
|
+
ssl:
|
27
|
+
use_ssl: true
|
28
|
+
cert: config/datastax_rails.crt
|
29
|
+
key: config/datastax_rails.key
|
@@ -0,0 +1,18 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIC6DCCAlGgAwIBAgIBKTANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQGEwJVUzER
|
3
|
+
MA8GA1UECBMIVmlyZ2luaWExDzANBgNVBAcTBlJlc3RvbjEbMBkGA1UEChMST3Bl
|
4
|
+
biBTb3VyY2UgQ2VudGVyMQ0wCwYDVQQLEwRTQURFMQ0wCwYDVQQDEwRTQURFMB4X
|
5
|
+
DTEyMTAxMjA5MjQ1OVoXDTIyMTAxMjA5MjQ1OVowdjELMAkGA1UEBhMCVVMxETAP
|
6
|
+
BgNVBAgMCFZpcmdpbmlhMQ8wDQYDVQQHDAZSZXN0b24xGzAZBgNVBAoME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Z+pUmok2eP0dhj3QQIDAQAB
|
5
|
+
AoGAM7KiAG72pXKS7LfjdbMZVJYHEUNexql+xC8i44L+q+mLK5P7ax1XnUaL1Q+A
|
6
|
+
TjGatnW+KpIhGEKLzkeiqFq8JxiBgp1l25lri4V1aTF8YuloekzroebUmz5sOVXO
|
7
|
+
GZxBkLl73t7m3xMWrMlR6o5tXgzeap5a2gMFLVBgJR/nIAECQQDXuINWtZKStza6
|
8
|
+
ZoPy0ofF3BVzXwP9ybt8rCA9NTTmH/06cOhIHibj8cDnEq29y8m9nJY122HKkdPP
|
9
|
+
77J/yxBhAkEAyFDsh8O2EkPH40ajWvFTpaI9aforaXEcgGNEyGg5f1ghrGOGjpkf
|
10
|
+
GDWdrOHyRzcoFxpi/fZfbvWYfjOm3zDS4QJBAJd45jBCetMudu1YAprEnbWfHijO
|
11
|
+
tPzFZDLcoh6Yd7aHC8a3dUL+eQxhurQGd5zntZbAlvDmRLp6vyIpC0uUiMECQQC8
|
12
|
+
d0bTRVOcQ6FhOCihe8RTZh2aBAGsJvvF35/rXgQax/SGmO0UZQRYZrl+2uZ0EnTp
|
13
|
+
p63Te2W2o+NheX9bJjiBAkEAhlnGxWHEPZfW6R+rFfbVKLW2NZe9wPVJb35XLRxf
|
14
|
+
G1W41KMP267frVpEXC8Kd/HOFLD9cM3tvFaN6B8GqRMj4g==
|
15
|
+
-----END RSA PRIVATE KEY-----
|
@@ -64,3 +64,6 @@ update hobbies using consistency QUORUM SET name = 'j', schema_version = '0' WHE
|
|
64
64
|
hobbies insert (8.7ms) 7332d7f8-0758-11e2-93a6-c8fd85e4fc7d {"name"=>"j", "schema_version"=>"0"}
|
65
65
|
update hobbies using consistency QUORUM SET created_at = '2012-09-25T21:35:31Z', updated_at = '2012-09-25T21:35:31Z', schema_version = '0' WHERE KEY IN ('ee85bbfa-0758-11e2-9b96-52afb52cd9cd')
|
66
66
|
hobbies insert (8.2ms) ee85bbfa-0758-11e2-9b96-52afb52cd9cd {"created_at"=>"2012-09-25T21:35:31Z", "updated_at"=>"2012-09-25T21:35:31Z", "schema_version"=>"0"}
|
67
|
+
update people using consistency QUORUM SET name = 'Jason', created_at = '2012-10-05T18:57:18Z', updated_at = '2012-10-05T18:57:18Z', nickname = 'Jason', schema_version = '0' WHERE KEY IN ('7c3fa8f8-0f1e-11e2-88cb-3b5bb170a231')
|
68
|
+
people insert (37.1ms) 7c3fa8f8-0f1e-11e2-88cb-3b5bb170a231 {"name"=>"Jason", "created_at"=>"2012-10-05T18:57:18Z", "updated_at"=>"2012-10-05T18:57:18Z", "nickname"=>"Jason", "schema_version"=>"0"}
|
69
|
+
SELECT updated_at,birthdate,nickname,created_at,name FROM people USING CONSISTENCY QUORUM WHERE key = '12345'
|