cassandra-schema 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8952ab5b3596d5370d883b95b1fd0729db5aa1d
4
- data.tar.gz: 89eb6476ec2461fe77b5f531c1c42a7bdbb27e7d
3
+ metadata.gz: 646b6d54404b35f5f4925709947d873dc7bf2880
4
+ data.tar.gz: 5550c316d8f6fa5460f7db981654344e347a5252
5
5
  SHA512:
6
- metadata.gz: 9e7e3df43fa96784a8486aa3b4f1215090d718b92e77590c9b12e5a88f9abfe92ffd7cf0656917e6826436922ccef564e3791908149bd98522fb419870ef89d6
7
- data.tar.gz: 220f759eff1b2c967b559d6850018087e38a6e58bbf13374229dcdbe12de2ea7dfc73f3e11556c5beeefc47c056597bf0c1fd8efb444fefc3ab889a989e790f6
6
+ metadata.gz: c4a88f2462cafff564678761264402e76da9574f9d1b6df02ce008363a51cc96b7af3d06ceb0354e7de61b2e4d90e94d51354b75b9f9a41325463ade1bd5298f
7
+ data.tar.gz: c64a715befaed5b60ff833ad8a61a4ef07ac67e50a842d94fc3595c9f9e5d3ef7c14966f25373b990bc9671f6163668f6ef2e5d7afeae973179520e9f5bbe16f
data/.gems-test CHANGED
@@ -1,2 +1,3 @@
1
1
  cassandra-driver -v 3.2.0
2
2
  lz4-ruby -v 0.3.3
3
+ mocha -v 1.3.0
data/README.md CHANGED
@@ -4,6 +4,11 @@ Simple reversible schema migrations for cassandra.
4
4
 
5
5
  ## Changelog
6
6
 
7
+ ### Version `0.3.0`
8
+
9
+ - Add `query_timeout` option for running migration commands. Default 30 seconds.
10
+ - Log relevant exception message when running migrations
11
+
7
12
  ### Version `0.2.0`
8
13
 
9
14
  - Refactor `schema_information` queries to use LWT and `:quorum` consistency level
@@ -65,6 +70,7 @@ migrator = CassandraSchema::Migrator.new(
65
70
  connection: CONN, # any connection object implementing `execute` method
66
71
  migrations: CassandraSchema.migrations, # list of migrations
67
72
  logger: Logger.new, # any logger object implementing `info` and `error` methods
73
+ options: {}, # additional configuration
68
74
  )
69
75
  ```
70
76
 
@@ -82,6 +88,15 @@ migrator.migrate(2)
82
88
 
83
89
  CassandraSchema tracks which migrations you have already run.
84
90
 
91
+
92
+ ### Options
93
+
94
+ name | default | description
95
+ ---- | ------- | -----------
96
+ lock | true | whether the Migrator must lock the schema before running migrations
97
+ lock_timeout | 30 | number of seconds for auto-unlocking schema
98
+ query_timeout | 30 | number of seconds after which to time out the command if it hasn’t completed
99
+
85
100
  ## Installation
86
101
 
87
102
  You can install it using rubygems.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "cassandra-schema"
5
- s.version = "0.2.0"
5
+ s.version = "0.3.0"
6
6
  s.summary = "Cassandra schema migrations"
7
7
  s.license = "MIT"
8
8
  s.description = "Simple reversible schema migrations for Cassandra."
@@ -5,8 +5,9 @@ module CassandraSchema
5
5
  attr_reader :connection, :current_version, :options
6
6
 
7
7
  DEFAULT_OPTIONS = {
8
- lock: true,
9
- lock_timeout: 30,
8
+ lock: true,
9
+ lock_timeout: 30,
10
+ query_timeout: 30,
10
11
  }
11
12
 
12
13
  def initialize(connection:, migrations:, logger: Logger.new(STDOUT), options: {})
@@ -54,6 +55,7 @@ module CassandraSchema
54
55
  @logger.info "Current version: #{current_version}"
55
56
  @logger.info "Done!"
56
57
  rescue => ex
58
+ @logger.error ex.message if ex.message && !ex.message.empty?
57
59
  @logger.info "Failed migrating all files. Current schema version: #{@current_version}"
58
60
  ensure
59
61
  unlock_schema if @options.fetch(:lock)
@@ -161,7 +163,7 @@ module CassandraSchema
161
163
  index = 0
162
164
 
163
165
  commands.each do |command|
164
- unless execute_command(command)
166
+ unless execute_command(command, timeout: @options.fetch(:query_timeout))
165
167
  message = "Failed migrating to version #{target}."
166
168
 
167
169
  if index > 0
@@ -174,7 +176,9 @@ module CassandraSchema
174
176
  .fetch(direction == :up ? :down : :up)
175
177
  .last(index)
176
178
 
177
- results = recover_commands.map { |cmd| execute_command(cmd) }
179
+ results = recover_commands.map { |cmd|
180
+ execute_command(cmd, timeout: @options.fetch(:query_timeout))
181
+ }
178
182
 
179
183
  message += results.all? ? "Ok." : "Failed."
180
184
  end
@@ -190,9 +194,9 @@ module CassandraSchema
190
194
  update_version(new_version)
191
195
  end
192
196
 
193
- def execute_command(command)
197
+ def execute_command(command, options)
194
198
  begin
195
- @connection.execute command
199
+ @connection.execute command, options
196
200
  true
197
201
  rescue => ex
198
202
  @logger.error ex.message
@@ -1,4 +1,5 @@
1
1
  require "minitest/autorun"
2
+ require "mocha/setup"
2
3
 
3
4
  require_relative "support/connections"
4
5
  require_relative "../lib/cassandra-schema/migrator"
@@ -185,6 +186,25 @@ describe "CassandraSchema::Migrator" do
185
186
 
186
187
  assert_equal "Nothing to migrate.", logger_b.stdout.pop
187
188
  end
189
+
190
+ it "runs commands with custom timeout" do
191
+ migrator = CassandraSchema::Migrator.new(
192
+ connection: CONN,
193
+ migrations: CassandraSchema.migrations,
194
+ logger: @fake_logger,
195
+ options: { query_timeout: 45 },
196
+ )
197
+
198
+ migrator.expects(:execute_command).times(4).with(anything, { timeout: 45 }).returns(true)
199
+
200
+ migrator.expects(:lock_schema).returns(true)
201
+ migrator.expects(:get_current_version).returns(0)
202
+ migrator.expects(:update_version).times(2)
203
+ migrator.expects(:renew_lock).times(2)
204
+ migrator.expects(:unlock_schema)
205
+
206
+ migrator.migrate
207
+ end
188
208
  end
189
209
 
190
210
  describe "migrating down" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassandra-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lautaro Orazi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-28 00:00:00.000000000 Z
11
+ date: 2018-03-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple reversible schema migrations for Cassandra.
14
14
  email: