cassandra_migrations 0.0.1.pre6 → 0.0.1.pre7
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/bin/prepare_for_cassandra +1 -1
- data/lib/cassandra_migrations/cassandra/keyspace_operations.rb +1 -1
- data/lib/cassandra_migrations/cassandra/query_result.rb +33 -0
- data/lib/cassandra_migrations/cassandra.rb +11 -3
- data/lib/cassandra_migrations/errors.rb +2 -10
- data/template/cassandra.yml +23 -0
- metadata +17 -15
data/bin/prepare_for_cassandra
CHANGED
@@ -57,6 +57,6 @@ puts ' 1. configure '.green + 'config/cassandra.yml'.red
|
|
57
57
|
puts ' 2. run '.green + 'rake cassandra:setup'.red + ' and try starting your application'.green
|
58
58
|
puts ' 3. create your first migration with '.green + 'rails g cassandra_migration'.red
|
59
59
|
puts ' 4. apply your migration with '.green + 'rake cassandra:migrate'.red
|
60
|
-
puts ' 5. run '.green + 'rake cassandra:test:prepare'.red + 'and start testing'.green
|
60
|
+
puts ' 5. run '.green + 'rake cassandra:test:prepare'.red + ' and start testing'.green
|
61
61
|
puts ' 6. have lots of fun!'.green.blink
|
62
62
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module CassandraMigrations
|
4
|
+
module Cassandra
|
5
|
+
class QueryResult
|
6
|
+
|
7
|
+
def initialize(cql_query_result)
|
8
|
+
@cql_query_result = cql_query_result
|
9
|
+
end
|
10
|
+
|
11
|
+
# We don't want to flood the console or the log with an inspection of
|
12
|
+
# a lot of loaded data
|
13
|
+
def inspect
|
14
|
+
"#<CassandraMigrations::Cassandra::QueryResult:#{object_id}>"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns {'column_name' => :column_type} hash
|
18
|
+
def metadata
|
19
|
+
hash = {}
|
20
|
+
@cql_query_result.metadata.each do |column_metadata|
|
21
|
+
hash[column_metadata.column_name] = column_metadata.type
|
22
|
+
end
|
23
|
+
hash
|
24
|
+
end
|
25
|
+
|
26
|
+
# Delegates all other method calls to the lower level query result (Cql::Client::QueryResult)
|
27
|
+
def method_missing(name, *args, &block)
|
28
|
+
@cql_query_result.send(name, *args, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'cql'
|
5
5
|
require 'cassandra_migrations/cassandra/queries'
|
6
|
+
require 'cassandra_migrations/cassandra/query_result'
|
6
7
|
require 'cassandra_migrations/cassandra/keyspace_operations'
|
7
8
|
|
8
9
|
module CassandraMigrations
|
@@ -13,8 +14,14 @@ module CassandraMigrations
|
|
13
14
|
mattr_accessor :client
|
14
15
|
|
15
16
|
def self.start!
|
16
|
-
|
17
|
-
|
17
|
+
begin
|
18
|
+
# setup keyspace use
|
19
|
+
use(Config.keyspace)
|
20
|
+
rescue Errors::MissingConfigurationError
|
21
|
+
# It's acceptable to not have a configuration file, that's why we rescue this exception.
|
22
|
+
# On the other hand, if the user try to execute a query this same exception won't be rescued
|
23
|
+
Rails.logger.try(:warn, "There is no config/cassandra.yml. Skipping connection to Cassandra...")
|
24
|
+
end
|
18
25
|
end
|
19
26
|
|
20
27
|
def self.restart!
|
@@ -44,7 +51,8 @@ module CassandraMigrations
|
|
44
51
|
|
45
52
|
def self.execute(cql)
|
46
53
|
connect_to_server unless client
|
47
|
-
client.execute(cql)
|
54
|
+
result = client.execute(cql)
|
55
|
+
QueryResult.new(result) if result
|
48
56
|
end
|
49
57
|
|
50
58
|
private
|
@@ -8,21 +8,13 @@ module CassandraMigrations
|
|
8
8
|
|
9
9
|
class ClientNotStartedError < CassandraError
|
10
10
|
def initialize
|
11
|
-
super("Cassandra.start has not been called yet! Can't execute queries before connecting to server...")
|
11
|
+
super("Cassandra.start! has not been called yet! Can't execute queries before connecting to server...")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
class MissingConfigurationError < CassandraError
|
16
16
|
def initialize
|
17
|
-
super("config/cassandra.yml is missing
|
18
|
-
development: \n\
|
19
|
-
host: '127.0.0.1' \n\
|
20
|
-
port: 9042 \n\
|
21
|
-
keyspace: 'lme_smart_grid_server_development' \n\
|
22
|
-
replication: \n\
|
23
|
-
class: 'SimpleStrategy' \n\
|
24
|
-
replication_factor: 1
|
25
|
-
")
|
17
|
+
super("config/cassandra.yml is missing! Run 'prepare_for_cassandra .' in the rails root directory.")
|
26
18
|
end
|
27
19
|
end
|
28
20
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
development:
|
2
|
+
host: '127.0.0.1'
|
3
|
+
port: 9042
|
4
|
+
keyspace: 'my_keyspace_name'
|
5
|
+
replication:
|
6
|
+
class: 'SimpleStrategy'
|
7
|
+
replication_factor: 1
|
8
|
+
|
9
|
+
test:
|
10
|
+
host: '127.0.0.1'
|
11
|
+
port: 9042
|
12
|
+
keyspace: 'my_keyspace_name_test'
|
13
|
+
replication:
|
14
|
+
class: 'SimpleStrategy'
|
15
|
+
replication_factor: 1
|
16
|
+
|
17
|
+
production:
|
18
|
+
host: '127.0.0.1'
|
19
|
+
port: 9042
|
20
|
+
keyspace: 'my_keyspace_name_production'
|
21
|
+
replication:
|
22
|
+
class: 'SimpleStrategy'
|
23
|
+
replication_factor: 1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassandra_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.pre7
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -116,25 +116,27 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- lib/cassandra_migrations.rb
|
119
|
+
- lib/cassandra_migrations/config.rb
|
119
120
|
- lib/cassandra_migrations/capistrano.rb
|
120
|
-
- lib/cassandra_migrations/migration.rb
|
121
|
-
- lib/cassandra_migrations/migrator.rb
|
122
|
-
- lib/cassandra_migrations/cassandra.rb
|
123
|
-
- lib/cassandra_migrations/railtie.rb
|
124
|
-
- lib/cassandra_migrations/cassandra/keyspace_operations.rb
|
125
121
|
- lib/cassandra_migrations/cassandra/queries.rb
|
126
|
-
- lib/cassandra_migrations/
|
127
|
-
- lib/cassandra_migrations/
|
128
|
-
- lib/cassandra_migrations/
|
129
|
-
- lib/cassandra_migrations/
|
130
|
-
- lib/cassandra_migrations/railtie/initializer.rb
|
122
|
+
- lib/cassandra_migrations/cassandra/query_result.rb
|
123
|
+
- lib/cassandra_migrations/cassandra/keyspace_operations.rb
|
124
|
+
- lib/cassandra_migrations/railtie/tasks.rake
|
125
|
+
- lib/cassandra_migrations/railtie/generators/cassandra_migration/USAGE
|
131
126
|
- lib/cassandra_migrations/railtie/generators/cassandra_migration/cassandra_migration_generator.rb
|
132
127
|
- lib/cassandra_migrations/railtie/generators/cassandra_migration/templates/empty_migration.rb.erb
|
133
|
-
- lib/cassandra_migrations/railtie/
|
134
|
-
- lib/cassandra_migrations/
|
128
|
+
- lib/cassandra_migrations/railtie/initializer.rb
|
129
|
+
- lib/cassandra_migrations/migration.rb
|
130
|
+
- lib/cassandra_migrations/migrator.rb
|
135
131
|
- lib/cassandra_migrations/errors.rb
|
136
|
-
-
|
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
|
+
- lib/cassandra_migrations/railtie.rb
|
137
|
+
- template/cassandra.yml
|
137
138
|
- spec/cassandra_migrations/cassandra_spec.rb
|
139
|
+
- spec/cassandra_migrations_spec.rb
|
138
140
|
- bin/prepare_for_cassandra
|
139
141
|
homepage: https://github.com/hsgubert/cassandra_migrations
|
140
142
|
licenses:
|
@@ -162,5 +164,5 @@ signing_key:
|
|
162
164
|
specification_version: 3
|
163
165
|
summary: Cassandra schema management for a multi-environment developer.
|
164
166
|
test_files:
|
165
|
-
- spec/cassandra_migrations_spec.rb
|
166
167
|
- spec/cassandra_migrations/cassandra_spec.rb
|
168
|
+
- spec/cassandra_migrations_spec.rb
|