datastax_rails 1.1.0.3 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +13 -13
- data/Rakefile +1 -0
- data/config/schema.xml.erb +0 -1
- data/config/{solrconfig.xml → solrconfig.xml.erb} +1 -1
- data/lib/blankslate.rb +1 -1
- data/lib/datastax_rails/associations/collection_proxy.rb +6 -2
- data/lib/datastax_rails/attribute_assignment.rb +114 -0
- data/lib/datastax_rails/attribute_methods/definition.rb +8 -2
- data/lib/datastax_rails/attribute_methods/typecasting.rb +2 -5
- data/lib/datastax_rails/attribute_methods.rb +9 -7
- data/lib/datastax_rails/base.rb +127 -109
- data/lib/datastax_rails/callbacks.rb +11 -7
- data/lib/datastax_rails/cassandra_only_model.rb +27 -0
- data/lib/datastax_rails/collection.rb +3 -1
- data/lib/datastax_rails/cql/base.rb +4 -0
- data/lib/datastax_rails/cql/select.rb +12 -2
- data/lib/datastax_rails/identity/abstract_key_factory.rb +1 -0
- data/lib/datastax_rails/identity/custom_key_factory.rb +1 -0
- data/lib/datastax_rails/identity/natural_key_factory.rb +1 -0
- data/lib/datastax_rails/identity/uuid_key_factory.rb +4 -0
- data/lib/datastax_rails/identity.rb +2 -1
- data/lib/datastax_rails/inheritance.rb +61 -0
- data/lib/datastax_rails/payload_model.rb +2 -5
- data/lib/datastax_rails/persistence.rb +63 -20
- data/lib/datastax_rails/railtie.rb +5 -1
- data/lib/datastax_rails/relation/batches.rb +2 -2
- data/lib/datastax_rails/relation/facet_methods.rb +56 -5
- data/lib/datastax_rails/relation/finder_methods.rb +55 -1
- data/lib/datastax_rails/relation/search_methods.rb +103 -32
- data/lib/datastax_rails/relation/spawn_methods.rb +3 -1
- data/lib/datastax_rails/relation/stats_methods.rb +1 -1
- data/lib/datastax_rails/relation.rb +166 -30
- data/lib/datastax_rails/schema/cassandra.rb +165 -0
- data/lib/datastax_rails/schema/migrator.rb +85 -193
- data/lib/datastax_rails/schema/solr.rb +158 -0
- data/lib/datastax_rails/schema.rb +2 -30
- data/lib/datastax_rails/scoping/default.rb +142 -0
- data/lib/datastax_rails/scoping/named.rb +200 -0
- data/lib/datastax_rails/scoping.rb +106 -349
- data/lib/datastax_rails/tasks/ds.rake +41 -42
- data/lib/datastax_rails/types/array_type.rb +1 -1
- data/lib/datastax_rails/types/base_type.rb +2 -2
- data/lib/datastax_rails/types/binary_type.rb +1 -1
- data/lib/datastax_rails/types/boolean_type.rb +1 -1
- data/lib/datastax_rails/types/date_type.rb +1 -1
- data/lib/datastax_rails/types/float_type.rb +4 -4
- data/lib/datastax_rails/types/integer_type.rb +3 -3
- data/lib/datastax_rails/types/string_type.rb +1 -1
- data/lib/datastax_rails/types/text_type.rb +1 -1
- data/lib/datastax_rails/types/time_type.rb +3 -3
- data/lib/datastax_rails/validations/uniqueness.rb +1 -1
- data/lib/datastax_rails/version.rb +1 -1
- data/lib/datastax_rails/wide_storage_model.rb +44 -0
- data/lib/datastax_rails.rb +16 -18
- data/spec/datastax_rails/associations_spec.rb +7 -3
- data/spec/datastax_rails/attribute_methods_spec.rb +23 -0
- data/spec/datastax_rails/base_spec.rb +1 -6
- data/spec/datastax_rails/inheritance_spec.rb +41 -0
- data/spec/datastax_rails/persistence_spec.rb +13 -3
- data/spec/datastax_rails/relation/batches_spec.rb +1 -1
- data/spec/datastax_rails/relation/facet_methods_spec.rb +52 -0
- data/spec/datastax_rails/relation/finder_methods_spec.rb +22 -1
- data/spec/datastax_rails/relation/search_methods_spec.rb +51 -1
- data/spec/datastax_rails/relation_spec.rb +14 -3
- data/spec/datastax_rails/schema/migrator_spec.rb +92 -0
- data/spec/datastax_rails/schema/solr_spec.rb +34 -0
- data/spec/datastax_rails/scoping/default_spec.rb +17 -0
- data/spec/datastax_rails/types/float_type_spec.rb +5 -9
- data/spec/datastax_rails/types/integer_type_spec.rb +5 -9
- data/spec/datastax_rails/types/time_type_spec.rb +28 -0
- data/spec/datastax_rails/validations/uniqueness_spec.rb +3 -1
- data/spec/dummy/config/application.rb +1 -4
- data/spec/dummy/config/datastax.yml +1 -1
- data/spec/dummy/config/environments/test.rb +2 -0
- data/spec/dummy/config/solr/articles-schema.xml.erb +1 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +2 -0
- data/spec/dummy/log/production.log +2 -0
- data/spec/dummy/log/test.log +523 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/models.rb +14 -0
- metadata +66 -22
- data/lib/datastax_rails/log_subscriber.rb +0 -37
- data/lib/datastax_rails/migrations/migration.rb +0 -15
- data/lib/datastax_rails/migrations.rb +0 -36
- data/lib/datastax_rails/mocking.rb +0 -15
- data/lib/datastax_rails/schema/migration.rb +0 -106
- data/lib/datastax_rails/schema/migration_proxy.rb +0 -25
- data/lib/datastax_rails/tasks/column_family.rb +0 -329
- data/lib/datastax_rails/tasks/keyspace.rb +0 -57
- data/spec/support/connection_double.rb +0 -6
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,17 @@ Dir[File.expand_path(File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb"))].each
|
|
12
12
|
|
13
13
|
RSpec.configure do |config|
|
14
14
|
config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
|
15
|
+
|
16
|
+
# Use a focus tag to filter specific specs. This helps if you need to
|
17
|
+
# focus on one spec instead of the whole suite.
|
18
|
+
config.filter_run focus: true
|
19
|
+
config.run_all_when_everything_filtered = true
|
20
|
+
|
21
|
+
# Filter slow specs. Add a :slow tag to the spec to keep it from
|
22
|
+
# running unless the SLOW_SPECS environment variable is set.
|
23
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
24
|
+
config.filter_run_excluding :slow unless ENV['SLOW_SPECS']
|
25
|
+
|
15
26
|
config.before(:each) do
|
16
27
|
DatastaxRails::Base.recorded_classes = {}
|
17
28
|
end
|
data/spec/support/models.rb
CHANGED
@@ -47,6 +47,18 @@ class CarPayload < DatastaxRails::PayloadModel
|
|
47
47
|
self.column_family = "car_payloads"
|
48
48
|
end
|
49
49
|
|
50
|
+
class AuditLog < DatastaxRails::WideStorageModel
|
51
|
+
self.column_family = "audit_logs"
|
52
|
+
|
53
|
+
key :natural, :attributes => [:uuid]
|
54
|
+
cluster_by :created_at
|
55
|
+
|
56
|
+
string :uuid
|
57
|
+
string :message
|
58
|
+
string :user, :indexed => :cassandra
|
59
|
+
timestamps
|
60
|
+
end
|
61
|
+
|
50
62
|
class Job < DatastaxRails::Base
|
51
63
|
self.column_family = "jobs"
|
52
64
|
|
@@ -66,9 +78,11 @@ class Boat < DatastaxRails::Base
|
|
66
78
|
|
67
79
|
key :uuid
|
68
80
|
string :name
|
81
|
+
integer :registration
|
69
82
|
timestamps
|
70
83
|
|
71
84
|
validates :name, :uniqueness => true
|
85
|
+
default_scope order(:name)
|
72
86
|
end
|
73
87
|
|
74
88
|
class Hobby < DatastaxRails::Base
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datastax_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason M. Kusar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.2.
|
19
|
+
version: 3.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.2.
|
26
|
+
version: 3.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: cassandra-cql
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.2.
|
33
|
+
version: 1.2.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.2.
|
40
|
+
version: 1.2.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rsolr
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.0.
|
47
|
+
version: 1.0.9
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.0.
|
54
|
+
version: 1.0.9
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rsolr-client-cert
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: appraisal
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.0.beta2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.0.beta2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: A Ruby-on-Rails interface to Datastax Enterprise. Intended for use with
|
84
112
|
the DSE search nodes.
|
85
113
|
email:
|
@@ -90,10 +118,10 @@ extra_rdoc_files: []
|
|
90
118
|
files:
|
91
119
|
- config/stopwords.txt
|
92
120
|
- config/schema.xml.erb
|
93
|
-
- config/solrconfig.xml
|
94
|
-
- lib/datastax_rails/schema/migration_proxy.rb
|
95
|
-
- lib/datastax_rails/schema/migration.rb
|
121
|
+
- config/solrconfig.xml.erb
|
96
122
|
- lib/datastax_rails/schema/migrator.rb
|
123
|
+
- lib/datastax_rails/schema/solr.rb
|
124
|
+
- lib/datastax_rails/schema/cassandra.rb
|
97
125
|
- lib/datastax_rails/serializers/xml_serializer.rb
|
98
126
|
- lib/datastax_rails/scoping.rb
|
99
127
|
- lib/datastax_rails/callbacks.rb
|
@@ -101,8 +129,6 @@ files:
|
|
101
129
|
- lib/datastax_rails/schema.rb
|
102
130
|
- lib/datastax_rails/rsolr_client_wrapper.rb
|
103
131
|
- lib/datastax_rails/associations.rb
|
104
|
-
- lib/datastax_rails/log_subscriber.rb
|
105
|
-
- lib/datastax_rails/mocking.rb
|
106
132
|
- lib/datastax_rails/identity.rb
|
107
133
|
- lib/datastax_rails/cql/use_keyspace.rb
|
108
134
|
- lib/datastax_rails/cql/alter_column_family.rb
|
@@ -122,12 +148,15 @@ files:
|
|
122
148
|
- lib/datastax_rails/cql/drop_index.rb
|
123
149
|
- lib/datastax_rails/attribute_methods.rb
|
124
150
|
- lib/datastax_rails/connection.rb
|
151
|
+
- lib/datastax_rails/scoping/default.rb
|
152
|
+
- lib/datastax_rails/scoping/named.rb
|
125
153
|
- lib/datastax_rails/reflection.rb
|
126
154
|
- lib/datastax_rails/identity/custom_key_factory.rb
|
127
155
|
- lib/datastax_rails/identity/uuid_key_factory.rb
|
128
156
|
- lib/datastax_rails/identity/hashed_natural_key_factory.rb
|
129
157
|
- lib/datastax_rails/identity/abstract_key_factory.rb
|
130
158
|
- lib/datastax_rails/identity/natural_key_factory.rb
|
159
|
+
- lib/datastax_rails/cassandra_only_model.rb
|
131
160
|
- lib/datastax_rails/collection.rb
|
132
161
|
- lib/datastax_rails/relation.rb
|
133
162
|
- lib/datastax_rails/type.rb
|
@@ -143,7 +172,6 @@ files:
|
|
143
172
|
- lib/datastax_rails/types/text_type.rb
|
144
173
|
- lib/datastax_rails/types/float_type.rb
|
145
174
|
- lib/datastax_rails/validations.rb
|
146
|
-
- lib/datastax_rails/migrations.rb
|
147
175
|
- lib/datastax_rails/associations/builder/association.rb
|
148
176
|
- lib/datastax_rails/associations/builder/singular_association.rb
|
149
177
|
- lib/datastax_rails/associations/builder/has_many.rb
|
@@ -162,6 +190,7 @@ files:
|
|
162
190
|
- lib/datastax_rails/associations/collection_proxy.rb
|
163
191
|
- lib/datastax_rails/errors.rb
|
164
192
|
- lib/datastax_rails/base.rb
|
193
|
+
- lib/datastax_rails/attribute_assignment.rb
|
165
194
|
- lib/datastax_rails/grouped_collection.rb
|
166
195
|
- lib/datastax_rails/payload_model.rb
|
167
196
|
- lib/datastax_rails/relation/batches.rb
|
@@ -173,12 +202,11 @@ files:
|
|
173
202
|
- lib/datastax_rails/relation/modification_methods.rb
|
174
203
|
- lib/datastax_rails/util/solr_repair.rb
|
175
204
|
- lib/datastax_rails/serialization.rb
|
205
|
+
- lib/datastax_rails/wide_storage_model.rb
|
206
|
+
- lib/datastax_rails/inheritance.rb
|
176
207
|
- lib/datastax_rails/validations/uniqueness.rb
|
177
208
|
- lib/datastax_rails/validations/associated.rb
|
178
209
|
- lib/datastax_rails/timestamps.rb
|
179
|
-
- lib/datastax_rails/migrations/migration.rb
|
180
|
-
- lib/datastax_rails/tasks/column_family.rb
|
181
|
-
- lib/datastax_rails/tasks/keyspace.rb
|
182
210
|
- lib/datastax_rails/tasks/ds.rake
|
183
211
|
- lib/datastax_rails/attribute_methods/definition.rb
|
184
212
|
- lib/datastax_rails/attribute_methods/dirty.rb
|
@@ -192,13 +220,16 @@ files:
|
|
192
220
|
- MIT-LICENSE
|
193
221
|
- Rakefile
|
194
222
|
- README.rdoc
|
195
|
-
- spec/support/connection_double.rb
|
196
223
|
- spec/support/default_consistency_shared_examples.rb
|
197
224
|
- spec/support/models.rb
|
198
225
|
- spec/support/datastax_test_hook.rb
|
226
|
+
- spec/datastax_rails/schema/solr_spec.rb
|
227
|
+
- spec/datastax_rails/schema/migrator_spec.rb
|
199
228
|
- spec/datastax_rails/attribute_methods_spec.rb
|
200
229
|
- spec/datastax_rails/cql/update_spec.rb
|
201
230
|
- spec/datastax_rails/cql/select_spec.rb
|
231
|
+
- spec/datastax_rails/scoping/default_spec.rb
|
232
|
+
- spec/datastax_rails/types/time_type_spec.rb
|
202
233
|
- spec/datastax_rails/types/integer_type_spec.rb
|
203
234
|
- spec/datastax_rails/types/float_type_spec.rb
|
204
235
|
- spec/datastax_rails/persistence_spec.rb
|
@@ -206,7 +237,9 @@ files:
|
|
206
237
|
- spec/datastax_rails/associations/has_many_association_spec.rb
|
207
238
|
- spec/datastax_rails/relation_spec.rb
|
208
239
|
- spec/datastax_rails/associations_spec.rb
|
240
|
+
- spec/datastax_rails/inheritance_spec.rb
|
209
241
|
- spec/datastax_rails/relation/batches_spec.rb
|
242
|
+
- spec/datastax_rails/relation/facet_methods_spec.rb
|
210
243
|
- spec/datastax_rails/relation/search_methods_spec.rb
|
211
244
|
- spec/datastax_rails/relation/spawn_methods_spec.rb
|
212
245
|
- spec/datastax_rails/relation/modification_methods_spec.rb
|
@@ -236,7 +269,9 @@ files:
|
|
236
269
|
- spec/dummy/config/locales/en.yml
|
237
270
|
- spec/dummy/config/sunspot.yml
|
238
271
|
- spec/dummy/config/boot.rb
|
272
|
+
- spec/dummy/config/solr/articles-schema.xml.erb
|
239
273
|
- spec/dummy/Rakefile
|
274
|
+
- spec/dummy/db/test.sqlite3
|
240
275
|
- spec/dummy/ks/migrate/20111117224534_models.rb
|
241
276
|
- spec/dummy/ks/schema.json
|
242
277
|
- spec/dummy/public/favicon.ico
|
@@ -253,7 +288,8 @@ files:
|
|
253
288
|
- spec/dummy/log/test.log
|
254
289
|
- spec/dummy/log/production.log
|
255
290
|
homepage: https://github.com/jasonmk/datastax_rails
|
256
|
-
licenses:
|
291
|
+
licenses:
|
292
|
+
- MIT
|
257
293
|
metadata: {}
|
258
294
|
post_install_message:
|
259
295
|
rdoc_options: []
|
@@ -276,13 +312,16 @@ signing_key:
|
|
276
312
|
specification_version: 4
|
277
313
|
summary: A Ruby-on-Rails interface to Datastax Enterprise
|
278
314
|
test_files:
|
279
|
-
- spec/support/connection_double.rb
|
280
315
|
- spec/support/default_consistency_shared_examples.rb
|
281
316
|
- spec/support/models.rb
|
282
317
|
- spec/support/datastax_test_hook.rb
|
318
|
+
- spec/datastax_rails/schema/solr_spec.rb
|
319
|
+
- spec/datastax_rails/schema/migrator_spec.rb
|
283
320
|
- spec/datastax_rails/attribute_methods_spec.rb
|
284
321
|
- spec/datastax_rails/cql/update_spec.rb
|
285
322
|
- spec/datastax_rails/cql/select_spec.rb
|
323
|
+
- spec/datastax_rails/scoping/default_spec.rb
|
324
|
+
- spec/datastax_rails/types/time_type_spec.rb
|
286
325
|
- spec/datastax_rails/types/integer_type_spec.rb
|
287
326
|
- spec/datastax_rails/types/float_type_spec.rb
|
288
327
|
- spec/datastax_rails/persistence_spec.rb
|
@@ -290,7 +329,9 @@ test_files:
|
|
290
329
|
- spec/datastax_rails/associations/has_many_association_spec.rb
|
291
330
|
- spec/datastax_rails/relation_spec.rb
|
292
331
|
- spec/datastax_rails/associations_spec.rb
|
332
|
+
- spec/datastax_rails/inheritance_spec.rb
|
293
333
|
- spec/datastax_rails/relation/batches_spec.rb
|
334
|
+
- spec/datastax_rails/relation/facet_methods_spec.rb
|
294
335
|
- spec/datastax_rails/relation/search_methods_spec.rb
|
295
336
|
- spec/datastax_rails/relation/spawn_methods_spec.rb
|
296
337
|
- spec/datastax_rails/relation/modification_methods_spec.rb
|
@@ -320,7 +361,9 @@ test_files:
|
|
320
361
|
- spec/dummy/config/locales/en.yml
|
321
362
|
- spec/dummy/config/sunspot.yml
|
322
363
|
- spec/dummy/config/boot.rb
|
364
|
+
- spec/dummy/config/solr/articles-schema.xml.erb
|
323
365
|
- spec/dummy/Rakefile
|
366
|
+
- spec/dummy/db/test.sqlite3
|
324
367
|
- spec/dummy/ks/migrate/20111117224534_models.rb
|
325
368
|
- spec/dummy/ks/schema.json
|
326
369
|
- spec/dummy/public/favicon.ico
|
@@ -336,3 +379,4 @@ test_files:
|
|
336
379
|
- spec/dummy/log/development.log
|
337
380
|
- spec/dummy/log/test.log
|
338
381
|
- spec/dummy/log/production.log
|
382
|
+
has_rdoc:
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module DatastaxRails
|
2
|
-
class LogSubscriber < ActiveSupport::LogSubscriber
|
3
|
-
def multi_get(event)
|
4
|
-
name = '%s multi_get (%.1fms)' % [event.payload[:column_family], event.duration]
|
5
|
-
|
6
|
-
debug " #{name} (#{event.payload[:keys].size}) #{event.payload[:keys].join(" ")}"
|
7
|
-
end
|
8
|
-
|
9
|
-
def remove(event)
|
10
|
-
name = '%s remove (%.1fms)' % [event.payload[:column_family], event.duration]
|
11
|
-
|
12
|
-
message = " #{name} #{event.payload[:key]}"
|
13
|
-
message << " #{Array(event.payload[:attributes]).inspect}" if event.payload[:attributes]
|
14
|
-
|
15
|
-
debug message
|
16
|
-
end
|
17
|
-
|
18
|
-
def truncate(event)
|
19
|
-
name = '%s truncate (%.1fms)' % [event.payload[:column_family], event.duration]
|
20
|
-
|
21
|
-
debug " #{name} #{event.payload[:column_family]}"
|
22
|
-
end
|
23
|
-
|
24
|
-
def insert(event)
|
25
|
-
name = '%s insert (%.1fms)' % [event.payload[:column_family], event.duration]
|
26
|
-
|
27
|
-
debug " #{name} #{event.payload[:key]} #{event.payload[:attributes].inspect}"
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_range(event)
|
31
|
-
name = '%s get_range (%.1fms)' % [event.payload[:column_family], event.duration]
|
32
|
-
|
33
|
-
debug " #{name} (#{event.payload[:count]}) '#{event.payload[:start]}' => '#{event.payload[:finish]}'"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
DatastaxRails::LogSubscriber.attach_to :datastax_rails
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module DatastaxRails
|
2
|
-
module Migrations
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
extend ActiveSupport::Autoload
|
5
|
-
|
6
|
-
included do
|
7
|
-
class_attribute :migrations
|
8
|
-
self.migrations = []
|
9
|
-
|
10
|
-
class_attribute :current_schema_version
|
11
|
-
self.current_schema_version = 0
|
12
|
-
end
|
13
|
-
|
14
|
-
autoload :Migration
|
15
|
-
|
16
|
-
class MigrationNotFoundError < StandardError
|
17
|
-
def initialize(record_version, migrations)
|
18
|
-
super("Cannot migrate a record from #{record_version.inspect}. Migrations exist for #{migrations.map(&:version)}")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def schema_version
|
23
|
-
Integer(@schema_version || self.class.current_schema_version)
|
24
|
-
end
|
25
|
-
|
26
|
-
module ClassMethods
|
27
|
-
def migrate(version, &blk)
|
28
|
-
migrations << Migration.new(version, blk)
|
29
|
-
|
30
|
-
if version > self.current_schema_version
|
31
|
-
self.current_schema_version = version
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'cassandra/mock'
|
2
|
-
module DatastaxRails
|
3
|
-
module Mocking
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
module ClassMethods
|
6
|
-
def use_mock!(really=true)
|
7
|
-
if really
|
8
|
-
self.connection_class = Cassandra::Mock
|
9
|
-
else
|
10
|
-
self.connection_class = Cassandra
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
module DatastaxRails
|
2
|
-
module Schema
|
3
|
-
|
4
|
-
class Migration
|
5
|
-
|
6
|
-
@@verbose = true
|
7
|
-
cattr_accessor :verbose
|
8
|
-
|
9
|
-
# Returns the raw connection to Cassandra
|
10
|
-
def self.connection
|
11
|
-
DatastaxRails::Base.connection
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.migrate(direction)
|
15
|
-
return unless respond_to?(direction)
|
16
|
-
|
17
|
-
case direction
|
18
|
-
when :up then announce "migrating"
|
19
|
-
when :down then announce "reverting"
|
20
|
-
end
|
21
|
-
|
22
|
-
result = nil
|
23
|
-
time = Benchmark.measure { result = send("#{direction}") }
|
24
|
-
|
25
|
-
case direction
|
26
|
-
when :up then announce "migrated (%.4fs)" % time.real; write
|
27
|
-
when :down then announce "reverted (%.4fs)" % time.real; write
|
28
|
-
end
|
29
|
-
|
30
|
-
result
|
31
|
-
end
|
32
|
-
|
33
|
-
# Creates a new column family with the given name. Column family configurations can be set within
|
34
|
-
# a block like this:
|
35
|
-
#
|
36
|
-
# create_column_family(:users) do |cf|
|
37
|
-
# cf.comment = 'Users column family'
|
38
|
-
# cf.comparator_type = 'TimeUUIDType'
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# A complete list of available configuration settings is here:
|
42
|
-
#
|
43
|
-
# http://github.com/fauna/cassandra/blob/master/vendor/0.7/gen-rb/cassandra_types.rb
|
44
|
-
#
|
45
|
-
# Scroll down to the CfDef definition.
|
46
|
-
def self.create_column_family(name, &block)
|
47
|
-
say_with_time("create_column_family #{name}") do
|
48
|
-
column_family_tasks.create(name, &block)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Drops the given column family
|
53
|
-
def self.drop_column_family(name)
|
54
|
-
say_with_time("drop_column_family #{name}") do
|
55
|
-
column_family_tasks.drop(name)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Renames the column family from the old name to the new name
|
60
|
-
def self.rename_column_family(old_name, new_name)
|
61
|
-
say_with_time("rename_column_family #{name}") do
|
62
|
-
column_family_tasks.rename(old_name, new_name)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.write(text="")
|
67
|
-
puts(text) if verbose
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.announce(message)
|
71
|
-
version = defined?(@version) ? @version : nil
|
72
|
-
|
73
|
-
text = "#{version} #{name}: #{message}"
|
74
|
-
length = [0, 75 - text.length].max
|
75
|
-
write "== %s %s" % [text, "=" * length]
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.say(message, subitem=false)
|
79
|
-
write "#{subitem ? " ->" : "--"} #{message}"
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.say_with_time(message)
|
83
|
-
say(message)
|
84
|
-
result = nil
|
85
|
-
time = Benchmark.measure { result = yield }
|
86
|
-
say "%.4fs" % time.real, :subitem
|
87
|
-
say("#{result} rows", :subitem) if result.is_a?(Integer)
|
88
|
-
result
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.suppress_messages
|
92
|
-
save, self.verbose = verbose, false
|
93
|
-
yield
|
94
|
-
ensure
|
95
|
-
self.verbose = save
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
|
100
|
-
def self.column_family_tasks
|
101
|
-
Tasks::ColumnFamily.new(DatastaxRails::Base.connection.keyspace)
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module DatastaxRails
|
2
|
-
module Schema
|
3
|
-
|
4
|
-
# MigrationProxy is used to defer loading of the actual migration classes
|
5
|
-
# until they are needed
|
6
|
-
class MigrationProxy
|
7
|
-
|
8
|
-
attr_accessor :name, :version, :filename
|
9
|
-
|
10
|
-
delegate :migrate, :announce, :write, :to=>:migration
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def migration
|
15
|
-
@migration ||= load_migration
|
16
|
-
end
|
17
|
-
|
18
|
-
def load_migration
|
19
|
-
require(File.expand_path(filename))
|
20
|
-
name.constantize
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|