active_column 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -7
- data/Gemfile.lock +60 -61
- data/README.md +7 -3
- data/active_column.gemspec +2 -3
- data/docs/Migrate.md +30 -7
- data/generators/ks_migration/USAGE +6 -0
- data/generators/ks_migration/ks_migration_generator.rb +17 -0
- data/generators/ks_migration/templates/migration.rb.erb +11 -0
- data/lib/active_column.rb +16 -9
- data/lib/active_column/configuration.rb +36 -0
- data/lib/active_column/helpers.rb +36 -0
- data/lib/active_column/migration.rb +76 -214
- data/lib/active_column/migrator.rb +231 -0
- data/lib/active_column/tasks/column_family.rb +28 -17
- data/lib/active_column/tasks/keyspace.rb +38 -3
- data/lib/active_column/tasks/ks.rake +142 -0
- data/lib/active_column/version.rb +1 -1
- data/spec/active_column/migration_spec.rb +58 -0
- data/spec/active_column/tasks/column_family_spec.rb +4 -2
- data/spec/active_column/tasks/keyspace_spec.rb +104 -4
- data/spec/spec_helper.rb +36 -11
- metadata +24 -44
- data/lib/active_column/connection.rb +0 -15
- data/lib/active_column/tasks/ks.rb +0 -76
data/.rvmrc
CHANGED
@@ -1,7 +1 @@
|
|
1
|
-
|
2
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
3
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/ruby-1.9.2-p0@active_column" ]] ; then
|
4
|
-
\. "${rvm_path:-$HOME/.rvm}/environments/ruby-1.9.2-p0@active_column"
|
5
|
-
else
|
6
|
-
rvm --create "ruby-1.9.2-p0@active_column"
|
7
|
-
fi
|
1
|
+
rvm --create 1.9.2@active_column
|
data/Gemfile.lock
CHANGED
@@ -1,51 +1,50 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_column (0.
|
5
|
-
activesupport
|
4
|
+
active_column (0.2)
|
6
5
|
cassandra (>= 0.9)
|
7
6
|
rake
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: http://rubygems.org/
|
11
10
|
specs:
|
12
|
-
ParseTree (3.0.
|
11
|
+
ParseTree (3.0.7)
|
13
12
|
RubyInline (>= 3.7.0)
|
14
13
|
sexp_processor (>= 3.0.0)
|
15
|
-
RubyInline (3.
|
14
|
+
RubyInline (3.9.0)
|
16
15
|
ZenTest (~> 4.3)
|
17
|
-
ZenTest (4.
|
16
|
+
ZenTest (4.5.0)
|
18
17
|
abstract (1.0.0)
|
19
|
-
actionmailer (3.0.
|
20
|
-
actionpack (= 3.0.
|
21
|
-
mail (~> 2.2.
|
22
|
-
actionpack (3.0.
|
23
|
-
activemodel (= 3.0.
|
24
|
-
activesupport (= 3.0.
|
18
|
+
actionmailer (3.0.7)
|
19
|
+
actionpack (= 3.0.7)
|
20
|
+
mail (~> 2.2.15)
|
21
|
+
actionpack (3.0.7)
|
22
|
+
activemodel (= 3.0.7)
|
23
|
+
activesupport (= 3.0.7)
|
25
24
|
builder (~> 2.1.2)
|
26
25
|
erubis (~> 2.6.6)
|
27
|
-
i18n (~> 0.
|
26
|
+
i18n (~> 0.5.0)
|
28
27
|
rack (~> 1.2.1)
|
29
|
-
rack-mount (~> 0.6.
|
30
|
-
rack-test (~> 0.5.
|
28
|
+
rack-mount (~> 0.6.14)
|
29
|
+
rack-test (~> 0.5.7)
|
31
30
|
tzinfo (~> 0.3.23)
|
32
|
-
activemodel (3.0.
|
33
|
-
activesupport (= 3.0.
|
31
|
+
activemodel (3.0.7)
|
32
|
+
activesupport (= 3.0.7)
|
34
33
|
builder (~> 2.1.2)
|
35
|
-
i18n (~> 0.
|
36
|
-
activerecord (3.0.
|
37
|
-
activemodel (= 3.0.
|
38
|
-
activesupport (= 3.0.
|
34
|
+
i18n (~> 0.5.0)
|
35
|
+
activerecord (3.0.7)
|
36
|
+
activemodel (= 3.0.7)
|
37
|
+
activesupport (= 3.0.7)
|
39
38
|
arel (~> 2.0.2)
|
40
39
|
tzinfo (~> 0.3.23)
|
41
|
-
activeresource (3.0.
|
42
|
-
activemodel (= 3.0.
|
43
|
-
activesupport (= 3.0.
|
44
|
-
activesupport (3.0.
|
45
|
-
arel (2.0.
|
46
|
-
bluecloth (2.0
|
40
|
+
activeresource (3.0.7)
|
41
|
+
activemodel (= 3.0.7)
|
42
|
+
activesupport (= 3.0.7)
|
43
|
+
activesupport (3.0.7)
|
44
|
+
arel (2.0.9)
|
45
|
+
bluecloth (2.1.0)
|
47
46
|
builder (2.1.2)
|
48
|
-
cassandra (0.9.
|
47
|
+
cassandra (0.9.1)
|
49
48
|
json
|
50
49
|
rake
|
51
50
|
simple_uuid (>= 0.1.0)
|
@@ -56,65 +55,67 @@ GEM
|
|
56
55
|
file-tail (1.0.5)
|
57
56
|
spruz (>= 0.1.0)
|
58
57
|
i18n (0.5.0)
|
59
|
-
json (1.
|
60
|
-
mail (2.2.
|
58
|
+
json (1.5.1)
|
59
|
+
mail (2.2.19)
|
61
60
|
activesupport (>= 2.3.6)
|
62
61
|
i18n (>= 0.4.0)
|
63
62
|
mime-types (~> 1.16)
|
64
63
|
treetop (~> 1.4.8)
|
65
64
|
mime-types (1.16)
|
65
|
+
mocha (0.9.12)
|
66
66
|
polyglot (0.3.1)
|
67
67
|
predicated (0.2.2)
|
68
|
-
rack (1.2.
|
69
|
-
rack-mount (0.6.
|
68
|
+
rack (1.2.2)
|
69
|
+
rack-mount (0.6.14)
|
70
70
|
rack (>= 1.0.0)
|
71
|
-
rack-test (0.5.
|
71
|
+
rack-test (0.5.7)
|
72
72
|
rack (>= 1.0)
|
73
|
-
rails (3.0.
|
74
|
-
actionmailer (= 3.0.
|
75
|
-
actionpack (= 3.0.
|
76
|
-
activerecord (= 3.0.
|
77
|
-
activeresource (= 3.0.
|
78
|
-
activesupport (= 3.0.
|
73
|
+
rails (3.0.7)
|
74
|
+
actionmailer (= 3.0.7)
|
75
|
+
actionpack (= 3.0.7)
|
76
|
+
activerecord (= 3.0.7)
|
77
|
+
activeresource (= 3.0.7)
|
78
|
+
activesupport (= 3.0.7)
|
79
79
|
bundler (~> 1.0)
|
80
|
-
railties (= 3.0.
|
81
|
-
railties (3.0.
|
82
|
-
actionpack (= 3.0.
|
83
|
-
activesupport (= 3.0.
|
80
|
+
railties (= 3.0.7)
|
81
|
+
railties (3.0.7)
|
82
|
+
actionpack (= 3.0.7)
|
83
|
+
activesupport (= 3.0.7)
|
84
84
|
rake (>= 0.8.7)
|
85
85
|
thor (~> 0.14.4)
|
86
86
|
rake (0.8.7)
|
87
|
-
rspec (2.
|
88
|
-
rspec-core (~> 2.
|
89
|
-
rspec-expectations (~> 2.
|
90
|
-
rspec-mocks (~> 2.
|
91
|
-
rspec-core (2.
|
92
|
-
rspec-expectations (2.
|
87
|
+
rspec (2.5.0)
|
88
|
+
rspec-core (~> 2.5.0)
|
89
|
+
rspec-expectations (~> 2.5.0)
|
90
|
+
rspec-mocks (~> 2.5.0)
|
91
|
+
rspec-core (2.5.1)
|
92
|
+
rspec-expectations (2.5.0)
|
93
93
|
diff-lcs (~> 1.1.2)
|
94
|
-
rspec-mocks (2.
|
95
|
-
rspec-rails (2.
|
94
|
+
rspec-mocks (2.5.0)
|
95
|
+
rspec-rails (2.5.0)
|
96
96
|
actionpack (~> 3.0)
|
97
97
|
activesupport (~> 3.0)
|
98
98
|
railties (~> 3.0)
|
99
|
-
rspec (~> 2.
|
99
|
+
rspec (~> 2.5.0)
|
100
100
|
ruby2ruby (1.2.5)
|
101
101
|
ruby_parser (~> 2.0)
|
102
102
|
sexp_processor (~> 3.0)
|
103
|
-
ruby_parser (2.0.
|
103
|
+
ruby_parser (2.0.6)
|
104
104
|
sexp_processor (~> 3.0)
|
105
105
|
sexp_processor (3.0.5)
|
106
|
-
simple_uuid (0.1.
|
107
|
-
sourcify (0.4.
|
106
|
+
simple_uuid (0.1.2)
|
107
|
+
sourcify (0.4.2)
|
108
|
+
file-tail (>= 1.0.5)
|
108
109
|
ruby2ruby (>= 1.2.5)
|
109
110
|
sexp_processor (>= 3.0.5)
|
110
|
-
spruz (0.2.
|
111
|
+
spruz (0.2.5)
|
111
112
|
thor (0.14.6)
|
112
113
|
thrift (0.5.0)
|
113
114
|
thrift_client (0.6.0)
|
114
115
|
thrift (~> 0.5.0)
|
115
116
|
treetop (1.4.9)
|
116
117
|
polyglot (>= 0.3.1)
|
117
|
-
tzinfo (0.3.
|
118
|
+
tzinfo (0.3.27)
|
118
119
|
wrong (0.5.0)
|
119
120
|
ParseTree (~> 3.0)
|
120
121
|
diff-lcs (~> 1.1.2)
|
@@ -124,18 +125,16 @@ GEM
|
|
124
125
|
ruby_parser (~> 2.0.4)
|
125
126
|
sexp_processor (~> 3.0)
|
126
127
|
sourcify (>= 0.3.0)
|
127
|
-
yard (0.6.
|
128
|
+
yard (0.6.8)
|
128
129
|
|
129
130
|
PLATFORMS
|
130
131
|
ruby
|
131
132
|
|
132
133
|
DEPENDENCIES
|
133
134
|
active_column!
|
134
|
-
activesupport
|
135
135
|
bluecloth
|
136
|
-
|
136
|
+
mocha
|
137
137
|
rails (>= 3.0)
|
138
|
-
|
139
|
-
rspec-rails
|
138
|
+
rspec-rails (>= 2.5.0)
|
140
139
|
wrong
|
141
140
|
yard
|
data/README.md
CHANGED
@@ -33,8 +33,12 @@ bundle install
|
|
33
33
|
|
34
34
|
### Configuration
|
35
35
|
|
36
|
-
ActiveColumn requires Cassandra 0.7 or above, as
|
37
|
-
version 0.9 or above.
|
36
|
+
ActiveColumn requires Cassandra 0.7 or above, as well as the [cassandra gem](https://github.com/fauna/cassandra),
|
37
|
+
version 0.9 or above. You must also be sure to use the Cassandra 0.7 support in the gem, which can be done by
|
38
|
+
adding Cassandra to your Gemfile like this:
|
39
|
+
<pre>
|
40
|
+
gem 'cassandra', '>= 0.9', :require => 'cassandra/0.7'
|
41
|
+
</pre>
|
38
42
|
|
39
43
|
Data migrations in ActiveColumn are used within a Rails project, and are driven off of a configuration file,
|
40
44
|
config/cassandra.yml. It should look something like this:
|
@@ -74,4 +78,4 @@ As you can see, I create a global $cassandra variable, which I use in my tests t
|
|
74
78
|
|
75
79
|
One other thing to note is that you obviously must have Cassandra installed and running! Please take a look at the
|
76
80
|
[mama_cass gem](https://github.com/carbonfive/mama_cass) for a quick way to get up and running with Cassandra for
|
77
|
-
development and testing.
|
81
|
+
development and testing.
|
data/active_column.gemspec
CHANGED
@@ -18,15 +18,14 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
-
s.has_rdoc = true
|
22
21
|
|
23
22
|
s.add_dependency 'cassandra', '>= 0.9'
|
24
|
-
s.add_dependency 'activesupport'
|
25
23
|
s.add_dependency 'rake'
|
26
24
|
|
27
25
|
s.add_development_dependency 'rails', '>= 3.0'
|
28
|
-
s.add_development_dependency 'rspec-rails'
|
26
|
+
s.add_development_dependency 'rspec-rails', '>= 2.5.0'
|
29
27
|
s.add_development_dependency 'wrong'
|
30
28
|
s.add_development_dependency 'yard'
|
31
29
|
s.add_development_dependency 'bluecloth'
|
30
|
+
s.add_development_dependency 'mocha'
|
32
31
|
end
|
data/docs/Migrate.md
CHANGED
@@ -23,7 +23,7 @@ the equivalent of a database in MySQL (or other relational dbs). To see the ava
|
|
23
23
|
rake -T ks
|
24
24
|
</pre>
|
25
25
|
|
26
|
-
3. Create your
|
26
|
+
3. Create your keyspaces with the **ks:create:all** rake task:
|
27
27
|
|
28
28
|
<pre>
|
29
29
|
rake ks:create:all
|
@@ -40,6 +40,11 @@ command:
|
|
40
40
|
rails g active_column:migration NameOfYourMigration
|
41
41
|
</pre>
|
42
42
|
|
43
|
+
If you are using Rails 2, run this command instead:
|
44
|
+
<pre>
|
45
|
+
./script/generate ks_migration NameOfYourMigration
|
46
|
+
</pre>
|
47
|
+
|
43
48
|
The name of the migration might be something like "CreateUsersColumnFamily". After you run this command, you should see
|
44
49
|
a new file that is located here:
|
45
50
|
|
@@ -71,7 +76,10 @@ this:
|
|
71
76
|
class CreateUsersColumnFamily < ActiveColumn::Migration
|
72
77
|
|
73
78
|
def self.up
|
74
|
-
create_column_family :users
|
79
|
+
create_column_family :users do |cf|
|
80
|
+
cf.comment = 'Users column family'
|
81
|
+
cf.comparator_type = :string
|
82
|
+
end
|
75
83
|
end
|
76
84
|
|
77
85
|
def self.down
|
@@ -88,13 +96,28 @@ rake ks:migrate
|
|
88
96
|
</pre>
|
89
97
|
|
90
98
|
This will create the column family for your development environment. But you also need it in your test environment.
|
91
|
-
For now, you have to do this like the following. However, soon this will be updated to work more like ActiveRecord
|
92
|
-
migrations.
|
93
99
|
|
94
|
-
7.
|
100
|
+
7. Prepare the test environment keyspace:
|
101
|
+
|
102
|
+
<pre>
|
103
|
+
rake ks:test:prepare
|
104
|
+
</pre>
|
105
|
+
|
106
|
+
And BAM! You have your development and test keyspaces set up correctly.
|
107
|
+
|
108
|
+
### Inside your migrations
|
109
|
+
|
110
|
+
ActiveColumn::Migration, which all migrations extend by default, offers some useful functions. They are documented
|
111
|
+
via rdoc in the code itself.
|
112
|
+
|
113
|
+
### But I'm using Sinatra!
|
95
114
|
|
115
|
+
If you are using Rails, you don't need to do anything beyond including the active\_column gem in your Gemfile.
|
116
|
+
However, if you are using Sinatra (or some other framework), you can get these rake tasks to work merely by adding
|
117
|
+
the following line to your Rakefile:
|
96
118
|
<pre>
|
97
|
-
|
119
|
+
require 'active_column'
|
98
120
|
</pre>
|
99
121
|
|
100
|
-
|
122
|
+
Please note, however, that the Rails generator is only available if you are using Rails. If you are not using Rails,
|
123
|
+
you will have to create your migrations by hand.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails_generator/base'
|
2
|
+
|
3
|
+
class KsMigrationGenerator < Rails::Generator::NamedBase
|
4
|
+
|
5
|
+
def manifest
|
6
|
+
record do |m|
|
7
|
+
m.directory 'ks/migrate'
|
8
|
+
timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
9
|
+
m.template 'migration.rb.erb', "ks/migrate/#{timestamp}_#{file_name.underscore}.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def banner
|
14
|
+
"Usage: ./script/generate ks_migration NAME [options]"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/active_column.rb
CHANGED
@@ -1,28 +1,35 @@
|
|
1
1
|
require 'cassandra/0.7'
|
2
|
-
require '
|
3
|
-
require '
|
2
|
+
require 'benchmark'
|
3
|
+
require 'yaml'
|
4
4
|
|
5
5
|
module ActiveColumn
|
6
6
|
|
7
7
|
autoload :Base, 'active_column/base'
|
8
|
-
autoload :
|
8
|
+
autoload :Configuration, 'active_column/configuration'
|
9
9
|
autoload :KeyConfig, 'active_column/key_config'
|
10
10
|
autoload :Version, 'active_column/version'
|
11
|
+
autoload :Helpers, 'active_column/helpers'
|
11
12
|
|
12
13
|
require 'active_column/errors'
|
14
|
+
require 'active_column/migrator'
|
13
15
|
require 'active_column/migration'
|
14
16
|
|
15
17
|
module Tasks
|
16
18
|
autoload :Keyspace, 'active_column/tasks/keyspace'
|
17
19
|
autoload :ColumnFamily, 'active_column/tasks/column_family'
|
18
|
-
|
19
|
-
require 'active_column/tasks/ks'
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
load 'active_column/tasks/ks.rake'
|
23
|
+
|
24
|
+
|
25
|
+
if defined? ::Rails
|
26
|
+
module Generators
|
27
|
+
if ::Rails::VERSION::MAJOR >= 3
|
28
|
+
require 'active_column/generators/migration_generator'
|
29
|
+
end
|
30
|
+
end
|
24
31
|
end
|
25
32
|
|
26
|
-
extend
|
27
|
-
|
33
|
+
extend Configuration
|
34
|
+
|
28
35
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveColumn
|
2
|
+
|
3
|
+
module Configuration
|
4
|
+
|
5
|
+
def connect(config)
|
6
|
+
default_thrift_options = { :timeout => 3, :retries => 2, :server_retry_period => nil }
|
7
|
+
override_thrift_options = (config['thrift'] || {}).inject({}){|h, (k, v)| h[k.to_sym] = v; h} # symbolize keys
|
8
|
+
thrift_options = default_thrift_options.merge(override_thrift_options)
|
9
|
+
self.connection = Cassandra.new(config['keyspace'], config['servers'], thrift_options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def connected?
|
13
|
+
defined? @@connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection
|
17
|
+
@@connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def connection=(connection)
|
21
|
+
@@connection = connection
|
22
|
+
@@keyspace_tasks = ActiveColumn::Tasks::Keyspace.new
|
23
|
+
@@keyspace = connection.keyspace
|
24
|
+
end
|
25
|
+
|
26
|
+
def keyspace_tasks
|
27
|
+
@@keyspace_tasks
|
28
|
+
end
|
29
|
+
|
30
|
+
def column_family_tasks
|
31
|
+
ActiveColumn::Tasks::ColumnFamily.new(@@keyspace)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveColumn
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
def self.current_env
|
5
|
+
ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
6
|
+
end
|
7
|
+
|
8
|
+
def current_env
|
9
|
+
ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
10
|
+
end
|
11
|
+
|
12
|
+
def testing?
|
13
|
+
self.current_env == 'test'
|
14
|
+
end
|
15
|
+
|
16
|
+
def log(msg, e = nil)
|
17
|
+
puts msg if e || !testing?
|
18
|
+
p e if e
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Object
|
26
|
+
def to_json(*a)
|
27
|
+
result = {
|
28
|
+
JSON.create_id => self.class.name
|
29
|
+
}
|
30
|
+
instance_variables.inject(result) do |r, name|
|
31
|
+
r[name[1..-1]] = instance_variable_get name
|
32
|
+
r
|
33
|
+
end
|
34
|
+
result.to_json(*a)
|
35
|
+
end
|
36
|
+
end
|