gotime-cassandra_object 3.0.2 → 3.0.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/.travis.yml +2 -1
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/tasks/column_family.rb +0 -11
- data/lib/cassandra_object/tasks/keyspace.rb +7 -45
- data/lib/cassandra_object/tasks/ks.rake +4 -16
- data/lib/cassandra_object/types/array_type.rb +1 -1
- data/test/support/connect.rb +11 -2
- data/test/unit/types/array_type_test.rb +2 -2
- metadata +2 -2
data/.travis.yml
CHANGED
@@ -52,14 +52,3 @@ module CassandraObject
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
class Cassandra
|
56
|
-
class ColumnFamily
|
57
|
-
def with_fields(options)
|
58
|
-
struct_fields.collect { |f| f[1][:name] }.each do |f|
|
59
|
-
send("#{f}=", options[f.to_sym] || options[f.to_s])
|
60
|
-
end
|
61
|
-
self
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
@@ -1,29 +1,18 @@
|
|
1
1
|
module CassandraObject
|
2
2
|
module Tasks
|
3
3
|
class Keyspace
|
4
|
-
def self.parse(hash)
|
5
|
-
ks = Cassandra::Keyspace.new.with_fields hash
|
6
|
-
ks.cf_defs = []
|
7
|
-
hash['cf_defs'].each do |cf|
|
8
|
-
ks.cf_defs << Cassandra::ColumnFamily.new.with_fields(cf)
|
9
|
-
end
|
10
|
-
ks
|
11
|
-
end
|
12
|
-
|
13
4
|
def exists?(name)
|
14
5
|
connection.keyspaces.include? name.to_s
|
15
6
|
end
|
16
7
|
|
17
8
|
def create(name, options = {})
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
ks = Cassandra::Keyspace.new.with_fields(opts)
|
26
|
-
connection.add_keyspace ks
|
9
|
+
keyspace = Cassandra::Keyspace.new
|
10
|
+
keyspace.name = name.to_s
|
11
|
+
keyspace.replication_factor = options[:replication_factor] || 1
|
12
|
+
keyspace.strategy_class = options[:strategy_class] || 'org.apache.cassandra.locator.SimpleStrategy'
|
13
|
+
keyspace.cf_defs = options[:cf_defs] || []
|
14
|
+
|
15
|
+
connection.add_keyspace keyspace
|
27
16
|
end
|
28
17
|
|
29
18
|
def drop(name)
|
@@ -44,22 +33,6 @@ module CassandraObject
|
|
44
33
|
connection.clear_keyspace!
|
45
34
|
end
|
46
35
|
|
47
|
-
def schema_dump
|
48
|
-
connection.schema
|
49
|
-
end
|
50
|
-
|
51
|
-
def schema_load(schema)
|
52
|
-
connection.schema.cf_defs.each do |cf|
|
53
|
-
connection.drop_column_family cf.name
|
54
|
-
end
|
55
|
-
|
56
|
-
keyspace = get
|
57
|
-
schema.cf_defs.each do |cf|
|
58
|
-
cf.keyspace = keyspace
|
59
|
-
connection.add_column_family cf
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
36
|
private
|
64
37
|
def connection
|
65
38
|
@connection ||= begin
|
@@ -69,14 +42,3 @@ module CassandraObject
|
|
69
42
|
end
|
70
43
|
end
|
71
44
|
end
|
72
|
-
|
73
|
-
class Cassandra
|
74
|
-
class Keyspace
|
75
|
-
def with_fields(options)
|
76
|
-
struct_fields.collect { |f| f[1][:name] }.each do |f|
|
77
|
-
send("#{f}=", options[f.to_sym] || options[f.to_s])
|
78
|
-
end
|
79
|
-
self
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -23,7 +23,7 @@ namespace :ks do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n)'
|
26
|
-
task :
|
26
|
+
task rollback: :environment do
|
27
27
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
28
28
|
CassandraObject::Schema::Migrator.rollback CassandraObject::Schema::Migrator.migrations_path, step
|
29
29
|
schema_dump
|
@@ -38,14 +38,10 @@ namespace :ks do
|
|
38
38
|
|
39
39
|
namespace :schema do
|
40
40
|
desc 'Create ks/schema.json file that can be portably used against any Cassandra instance supported by CassandraObject'
|
41
|
-
task :
|
41
|
+
task dump: :environment do
|
42
42
|
schema_dump
|
43
43
|
end
|
44
44
|
|
45
|
-
desc 'Load ks/schema.json file into Cassandra'
|
46
|
-
task :load => :environment do
|
47
|
-
schema_load
|
48
|
-
end
|
49
45
|
end
|
50
46
|
|
51
47
|
namespace :test do
|
@@ -58,19 +54,11 @@ namespace :ks do
|
|
58
54
|
|
59
55
|
private
|
60
56
|
def schema_dump(env = Rails.env)
|
61
|
-
File.open "#{Rails.root}/ks/schema.
|
62
|
-
|
63
|
-
JSON.pretty_generate(schema).split(/\n/).each do |line|
|
64
|
-
file.puts line
|
65
|
-
end
|
66
|
-
end
|
57
|
+
# File.open "#{Rails.root}/ks/schema.rb", 'w' do |file|
|
58
|
+
# end
|
67
59
|
end
|
68
60
|
|
69
61
|
def schema_load(env = Rails.env)
|
70
|
-
File.open "#{Rails.root}/ks/schema.json", 'r' do |file|
|
71
|
-
hash = JSON.parse(file.read(nil))
|
72
|
-
get_keyspace.schema_load CassandraObject::Tasks::Keyspace.parse(hash)
|
73
|
-
end
|
74
62
|
end
|
75
63
|
|
76
64
|
def cassandra_config
|
data/test/support/connect.rb
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
CassandraObject::Base.establish_connection(
|
2
|
-
keyspace: '
|
2
|
+
keyspace: 'cassandra_object_test',
|
3
3
|
servers: '127.0.0.1:9160'
|
4
|
-
)
|
4
|
+
)
|
5
|
+
|
6
|
+
CassandraObject::Tasks::Keyspace.new.tap do |keyspace_task|
|
7
|
+
keyspace_task.drop('cassandra_object_test') if keyspace_task.exists?('cassandra_object_test')
|
8
|
+
keyspace_task.create('cassandra_object_test')
|
9
|
+
end
|
10
|
+
|
11
|
+
CassandraObject::Tasks::ColumnFamily.new('cassandra_object_test').tap do |column_family_task|
|
12
|
+
column_family_task.create('Issues') unless column_family_task.exists?('Issues')
|
13
|
+
end
|
@@ -42,8 +42,8 @@ class CassandraObject::Types::ArrayTypeTest < CassandraObject::Types::TestCase
|
|
42
42
|
assert_equal({'favorite_colors' => [['red'], []]}, issue.changes)
|
43
43
|
end
|
44
44
|
|
45
|
-
test 'unique array removes
|
46
|
-
issue = TestIssue.create favorite_colors: ['blue', 'red', nil]
|
45
|
+
test 'unique array removes blank' do
|
46
|
+
issue = TestIssue.create favorite_colors: ['blue', 'red', '', nil]
|
47
47
|
assert_equal ['blue', 'red'], issue.favorite_colors
|
48
48
|
end
|
49
49
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotime-cassandra_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-07-
|
13
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|