cassandra_migrations 0.0.1.pre7 → 0.0.1
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.
@@ -15,6 +15,10 @@ module CassandraMigrations
|
|
15
15
|
def self.load_config
|
16
16
|
begin
|
17
17
|
self.config = YAML.load_file(Rails.root.join("config", "cassandra.yml"))[Rails.env]
|
18
|
+
|
19
|
+
if config.nil?
|
20
|
+
raise Errors::MissingConfigurationError, "No configuration for #{Rails.env} environment! Complete your config/cassandra.yml."
|
21
|
+
end
|
18
22
|
rescue Errno::ENOENT
|
19
23
|
raise Errors::MissingConfigurationError
|
20
24
|
end
|
@@ -1,9 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'colorize'
|
4
|
+
|
3
5
|
module CassandraMigrations
|
4
6
|
module Errors
|
5
7
|
|
6
8
|
class CassandraError < StandardError
|
9
|
+
def initialize(msg)
|
10
|
+
# Makes all exception messages red
|
11
|
+
if msg.frozen?
|
12
|
+
super(msg.dup.red)
|
13
|
+
else
|
14
|
+
super(msg.red)
|
15
|
+
end
|
16
|
+
end
|
7
17
|
end
|
8
18
|
|
9
19
|
class ClientNotStartedError < CassandraError
|
@@ -13,8 +23,8 @@ module CassandraMigrations
|
|
13
23
|
end
|
14
24
|
|
15
25
|
class MissingConfigurationError < CassandraError
|
16
|
-
def initialize
|
17
|
-
super("config/cassandra.yml is missing! Run 'prepare_for_cassandra .' in the rails root directory.")
|
26
|
+
def initialize(msg=nil)
|
27
|
+
super(msg || "config/cassandra.yml is missing! Run 'prepare_for_cassandra .' in the rails root directory.")
|
18
28
|
end
|
19
29
|
end
|
20
30
|
|
@@ -3,11 +3,6 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe CassandraMigrations::Cassandra do
|
5
5
|
|
6
|
-
it "should initialize without client or config" do
|
7
|
-
CassandraMigrations::Cassandra.client.should be_nil
|
8
|
-
CassandraMigrations::Cassandra.config.should be_nil
|
9
|
-
end
|
10
|
-
|
11
6
|
before do
|
12
7
|
Rails.stub(:root).and_return Pathname.new("spec/fixtures")
|
13
8
|
Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("development")
|
@@ -17,72 +12,90 @@ describe CassandraMigrations::Cassandra do
|
|
17
12
|
CassandraMigrations::Cassandra.shutdown! if CassandraMigrations::Cassandra.client
|
18
13
|
end
|
19
14
|
|
20
|
-
describe
|
21
|
-
it
|
22
|
-
Rails.stub(:root).and_return Pathname.new("wrong_path")
|
23
|
-
|
24
|
-
expect do
|
25
|
-
CassandraMigrations::Cassandra.start!
|
26
|
-
end.to raise_exception CassandraMigrations::Cassandra::Errors::MissingConfigurationError
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should load config/cassandra.yaml environment specific part in self.config" do
|
30
|
-
begin
|
31
|
-
CassandraMigrations::Cassandra.start!
|
32
|
-
rescue
|
33
|
-
end
|
34
|
-
|
35
|
-
CassandraMigrations::Cassandra.config.should == {
|
36
|
-
'host' => "127.0.0.1",
|
37
|
-
'port' => 9042,
|
38
|
-
'keyspace' => "cassandra_migrations_development",
|
39
|
-
'replication' => {
|
40
|
-
'class' => "SimpleStrategy",
|
41
|
-
'replication_factor' => 1
|
42
|
-
}
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should use host and port configurations to create cassandra client" do
|
15
|
+
describe '.execute' do
|
16
|
+
it 'should connect to cassandra using host and port configured' do
|
47
17
|
cql_client_mock = Cql::Client.new
|
48
|
-
cql_client_mock.should_receive(:connect)
|
49
|
-
cql_client_mock.stub(:use)
|
50
18
|
Cql::Client.should_receive(:new).with(:host => '127.0.0.1', :port => 9042).and_return(cql_client_mock)
|
51
|
-
|
52
|
-
|
19
|
+
cql_client_mock.should_receive(:connect)
|
20
|
+
cql_client_mock.should_receive(:execute).with('anything').and_return(nil)
|
21
|
+
|
22
|
+
CassandraMigrations::Cassandra.execute('anything').should be_nil
|
53
23
|
end
|
54
24
|
|
55
|
-
it
|
25
|
+
it 'raise exception if there is something wrong with the connection' do
|
56
26
|
cql_client_mock = Cql::Client.new
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
expect
|
61
|
-
CassandraMigrations::Cassandra.
|
62
|
-
|
27
|
+
Cql::Client.should_receive(:new).and_return(cql_client_mock)
|
28
|
+
cql_client_mock.should_receive(:connect).and_raise(Cql::Io::ConnectionError)
|
29
|
+
|
30
|
+
expect {
|
31
|
+
CassandraMigrations::Cassandra.execute('anything')
|
32
|
+
}.to raise_exception CassandraMigrations::Errors::ConnectionError
|
63
33
|
end
|
64
34
|
|
65
|
-
it
|
66
|
-
CassandraMigrations::Cassandra.
|
67
|
-
|
35
|
+
it 'should return a QueryResult if the query returns something' do
|
36
|
+
CassandraMigrations::Cassandra.client = Cql::Client.new
|
37
|
+
|
38
|
+
result_mock = mock('result_mock')
|
39
|
+
CassandraMigrations::Cassandra.client.should_receive(:execute).with('anything').and_return(result_mock)
|
40
|
+
|
41
|
+
result = CassandraMigrations::Cassandra.execute('anything')
|
42
|
+
result.should_not be_nil
|
43
|
+
result.should be_a(CassandraMigrations::Cassandra::QueryResult)
|
68
44
|
end
|
69
45
|
end
|
70
46
|
|
71
47
|
describe '.use' do
|
48
|
+
it 'should connect to cassandra using host and port configured' do
|
49
|
+
cql_client_mock = Cql::Client.new
|
50
|
+
Cql::Client.should_receive(:new).with(:host => '127.0.0.1', :port => 9042).and_return(cql_client_mock)
|
51
|
+
cql_client_mock.should_receive(:connect)
|
52
|
+
cql_client_mock.should_receive(:use).with('anything').and_return(nil)
|
53
|
+
|
54
|
+
CassandraMigrations::Cassandra.use('anything').should be_nil
|
55
|
+
end
|
56
|
+
|
72
57
|
it "should raise exception if configured keyspace does not exist" do
|
73
|
-
expect
|
74
|
-
CassandraMigrations::Cassandra.
|
75
|
-
|
58
|
+
expect {
|
59
|
+
CassandraMigrations::Cassandra.use('anything')
|
60
|
+
}.to raise_exception CassandraMigrations::Errors::UnexistingKeyspaceError
|
76
61
|
end
|
77
62
|
end
|
78
63
|
|
79
|
-
describe "
|
80
|
-
it "should
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
64
|
+
# describe ".start!" do
|
65
|
+
# it "should use host and port configurations to create cassandra client" do
|
66
|
+
# cql_client_mock = Cql::Client.new
|
67
|
+
# cql_client_mock.should_receive(:connect)
|
68
|
+
# cql_client_mock.stub(:use)
|
69
|
+
# Cql::Client.should_receive(:new).with(:host => '127.0.0.1', :port => 9042).and_return(cql_client_mock)
|
70
|
+
#
|
71
|
+
# CassandraMigrations::Cassandra.start!
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# it "should raise exception if not able to connect to cassandra host" do
|
75
|
+
# cql_client_mock = Cql::Client.new
|
76
|
+
# cql_client_mock.stub(:connect).and_raise Cql::Io::ConnectionError
|
77
|
+
# Cql::Client.stub(:new).and_return cql_client_mock
|
78
|
+
#
|
79
|
+
# expect do
|
80
|
+
# CassandraMigrations::Cassandra.start!
|
81
|
+
# end.to raise_exception CassandraMigrations::Cassandra::Errors::ConnectionError
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# it "should automatically use configured keyspace" do
|
85
|
+
# CassandraMigrations::Cassandra.should_receive(:use).with('cassandra_migrations_development')
|
86
|
+
# CassandraMigrations::Cassandra.start!
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
#
|
91
|
+
#
|
92
|
+
# describe "query interface" do
|
93
|
+
# it "should respond to query methods" do
|
94
|
+
# CassandraMigrations::Cassandra.should respond_to :select
|
95
|
+
# CassandraMigrations::Cassandra.should respond_to :write
|
96
|
+
# CassandraMigrations::Cassandra.should respond_to :delete
|
97
|
+
# CassandraMigrations::Cassandra.should respond_to :truncate
|
98
|
+
# end
|
99
|
+
# end
|
87
100
|
|
88
101
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe CassandraMigrations::Config do
|
5
|
+
|
6
|
+
before do
|
7
|
+
CassandraMigrations::Config.config = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should fetch values in config for the right environment' do
|
11
|
+
Rails.stub(:root).and_return Pathname.new("spec/fixtures")
|
12
|
+
Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("development")
|
13
|
+
|
14
|
+
CassandraMigrations::Config.keyspace.should == 'cassandra_migrations_development'
|
15
|
+
CassandraMigrations::Config.replication.should == {'class' => "SimpleStrategy", 'replication_factor' => 1 }
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should raise exception if there are no configs for environment' do
|
19
|
+
Rails.stub(:root).and_return Pathname.new("spec/fixtures")
|
20
|
+
Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("fake_environment")
|
21
|
+
|
22
|
+
expect {
|
23
|
+
CassandraMigrations::Config.keyspace
|
24
|
+
}.to raise_exception CassandraMigrations::Errors::MissingConfigurationError
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should raise exception if there are no config file' do
|
28
|
+
Rails.stub(:root).and_return Pathname.new("spec/fake_path")
|
29
|
+
Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("development")
|
30
|
+
|
31
|
+
expect {
|
32
|
+
CassandraMigrations::Config.keyspace
|
33
|
+
}.to raise_exception CassandraMigrations::Errors::MissingConfigurationError
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -6,8 +6,9 @@ describe CassandraMigrations do
|
|
6
6
|
defined?(CassandraMigrations).should be_true
|
7
7
|
defined?(CassandraMigrations::Railtie).should be_true
|
8
8
|
defined?(CassandraMigrations::Cassandra).should be_true
|
9
|
-
defined?(CassandraMigrations::
|
10
|
-
defined?(CassandraMigrations::
|
11
|
-
defined?(CassandraMigrations::
|
9
|
+
defined?(CassandraMigrations::Errors).should be_true
|
10
|
+
defined?(CassandraMigrations::Migration).should be_true
|
11
|
+
defined?(CassandraMigrations::Migrator).should be_true
|
12
|
+
defined?(CassandraMigrations::Config).should be_true
|
12
13
|
end
|
13
14
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassandra_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Henrique Gubert
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cql-rb
|
@@ -115,28 +115,29 @@ executables:
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- lib/cassandra_migrations.rb
|
119
|
-
- lib/cassandra_migrations/config.rb
|
120
|
-
- lib/cassandra_migrations/capistrano.rb
|
118
|
+
- lib/cassandra_migrations/cassandra/keyspace_operations.rb
|
121
119
|
- lib/cassandra_migrations/cassandra/queries.rb
|
122
120
|
- lib/cassandra_migrations/cassandra/query_result.rb
|
123
|
-
- lib/cassandra_migrations/
|
124
|
-
- lib/cassandra_migrations/
|
125
|
-
- lib/cassandra_migrations/
|
126
|
-
- lib/cassandra_migrations/railtie/generators/cassandra_migration/cassandra_migration_generator.rb
|
127
|
-
- lib/cassandra_migrations/railtie/generators/cassandra_migration/templates/empty_migration.rb.erb
|
128
|
-
- lib/cassandra_migrations/railtie/initializer.rb
|
121
|
+
- lib/cassandra_migrations/migration/table_operations.rb
|
122
|
+
- lib/cassandra_migrations/migration/table_definition.rb
|
123
|
+
- lib/cassandra_migrations/migration/column_operations.rb
|
129
124
|
- lib/cassandra_migrations/migration.rb
|
130
|
-
- lib/cassandra_migrations/migrator.rb
|
131
125
|
- lib/cassandra_migrations/errors.rb
|
132
|
-
- lib/cassandra_migrations/migration/column_operations.rb
|
133
|
-
- lib/cassandra_migrations/migration/table_definition.rb
|
134
|
-
- lib/cassandra_migrations/migration/table_operations.rb
|
135
|
-
- lib/cassandra_migrations/cassandra.rb
|
136
126
|
- lib/cassandra_migrations/railtie.rb
|
127
|
+
- lib/cassandra_migrations/config.rb
|
128
|
+
- lib/cassandra_migrations/migrator.rb
|
129
|
+
- lib/cassandra_migrations/cassandra.rb
|
130
|
+
- lib/cassandra_migrations/railtie/generators/cassandra_migration/cassandra_migration_generator.rb
|
131
|
+
- lib/cassandra_migrations/railtie/generators/cassandra_migration/templates/empty_migration.rb.erb
|
132
|
+
- lib/cassandra_migrations/railtie/generators/cassandra_migration/USAGE
|
133
|
+
- lib/cassandra_migrations/railtie/tasks.rake
|
134
|
+
- lib/cassandra_migrations/railtie/initializer.rb
|
135
|
+
- lib/cassandra_migrations/capistrano.rb
|
136
|
+
- lib/cassandra_migrations.rb
|
137
137
|
- template/cassandra.yml
|
138
|
-
- spec/cassandra_migrations/cassandra_spec.rb
|
139
138
|
- spec/cassandra_migrations_spec.rb
|
139
|
+
- spec/cassandra_migrations/config_spec.rb
|
140
|
+
- spec/cassandra_migrations/cassandra_spec.rb
|
140
141
|
- bin/prepare_for_cassandra
|
141
142
|
homepage: https://github.com/hsgubert/cassandra_migrations
|
142
143
|
licenses:
|
@@ -164,5 +165,6 @@ signing_key:
|
|
164
165
|
specification_version: 3
|
165
166
|
summary: Cassandra schema management for a multi-environment developer.
|
166
167
|
test_files:
|
167
|
-
- spec/cassandra_migrations/cassandra_spec.rb
|
168
168
|
- spec/cassandra_migrations_spec.rb
|
169
|
+
- spec/cassandra_migrations/config_spec.rb
|
170
|
+
- spec/cassandra_migrations/cassandra_spec.rb
|