statesman 4.0.0 → 4.1.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
- SHA1:
3
- metadata.gz: 5063951e126e3898569d97511ea5c89149122c3e
4
- data.tar.gz: 888fcdc8b6bfbde03dbc4471fa3d84f58fd0871e
2
+ SHA256:
3
+ metadata.gz: 4fb61c0976e4be7109c74119ce4a04bec415b463295a2a72adddedde288012bc
4
+ data.tar.gz: 895b55c0827be27cccde416b3c71cc375f2e2f0c7fa847ef858f40e58ddfbf4b
5
5
  SHA512:
6
- metadata.gz: c4f1b64670d9b94c53f65ef3ed7182be77388c732536906d7066db8e0970016ad1e0cec26148d62b5cd32719e446a253033da3b1e8dd5c0c5e813834715e032f
7
- data.tar.gz: 8c5ab391235a0f4b073fee60eeea93c4752e9f5a2d71a6b05ba955cebfd5bae61921bf87ac9769a967db05439cd907e5de6be1fe5f8d5a45a80fc4588b722d9a
6
+ metadata.gz: 3a12259539822ebb79e79a76f47275636da60d799b28b8c436cd9ddfdcc1e8d459897867816832fe524263b1f5c536db78e3617609e77054d43d872c6286a652
7
+ data.tar.gz: a1963915c8231d6c8ed037733a652e581f1efcf6d8ce76e535b8f50fa81e8a288a3723bb2974a2178cd11b2b0c6502fe6b49b216b2c9f82e1846cbdfb1cc6ada
@@ -138,6 +138,78 @@ jobs:
138
138
  - POSTGRES_USER=postgres
139
139
  - POSTGRES_DB=statesman_test
140
140
  steps: *steps
141
+ build-ruby262-rails-600-mongo:
142
+ docker:
143
+ - image: circleci/ruby:2.6.2-node
144
+ environment:
145
+ - RAILS_VERSION=6.0.0.beta3
146
+ - DATABASE_DEPENDENCY_PORT=27017
147
+ - image: circleci/mongo:3
148
+ steps: *steps
149
+ build-ruby262-rails-600-mysql:
150
+ docker:
151
+ - image: circleci/ruby:2.6.2-node
152
+ environment:
153
+ - RAILS_VERSION=6.0.0.beta3
154
+ - DATABASE_URL=mysql2://root@127.0.0.1/statesman_test
155
+ - EXCLUDE_MONGOID=true
156
+ - DATABASE_DEPENDENCY_PORT=3306
157
+ - image: circleci/mysql:5.7.18
158
+ environment:
159
+ - MYSQL_ALLOW_EMPTY_PASSWORD=true
160
+ - MYSQL_USER=root
161
+ - MYSQL_PASSWORD=
162
+ - MYSQL_DATABASE=statesman_test
163
+ steps: *steps
164
+ build-ruby262-rails-600-postgres:
165
+ docker:
166
+ - image: circleci/ruby:2.6.2-node
167
+ environment:
168
+ - RAILS_VERSION=6.0.0.beta3
169
+ - DATABASE_URL=postgres://postgres@localhost/statesman_test
170
+ - EXCLUDE_MONGOID=true
171
+ - DATABASE_DEPENDENCY_PORT=5432
172
+ - image: circleci/postgres:9.6
173
+ environment:
174
+ - POSTGRES_USER=postgres
175
+ - POSTGRES_DB=statesman_test
176
+ steps: *steps
177
+ build-ruby241-rails-523-mongo:
178
+ docker:
179
+ - image: circleci/ruby:2.4.1-node
180
+ environment:
181
+ - RAILS_VERSION=5.2.3
182
+ - DATABASE_DEPENDENCY_PORT=27017
183
+ - image: circleci/mongo:3
184
+ steps: *steps
185
+ build-ruby241-rails-523-mysql:
186
+ docker:
187
+ - image: circleci/ruby:2.4.1-node
188
+ environment:
189
+ - RAILS_VERSION=5.2.3
190
+ - DATABASE_URL=mysql2://root@127.0.0.1/statesman_test
191
+ - EXCLUDE_MONGOID=true
192
+ - DATABASE_DEPENDENCY_PORT=3306
193
+ - image: circleci/mysql:5.7.18
194
+ environment:
195
+ - MYSQL_ALLOW_EMPTY_PASSWORD=true
196
+ - MYSQL_USER=root
197
+ - MYSQL_PASSWORD=
198
+ - MYSQL_DATABASE=statesman_test
199
+ steps: *steps
200
+ build-ruby241-rails-523-postgres:
201
+ docker:
202
+ - image: circleci/ruby:2.4.1-node
203
+ environment:
204
+ - RAILS_VERSION=5.2.3
205
+ - DATABASE_URL=postgres://postgres@localhost/statesman_test
206
+ - EXCLUDE_MONGOID=true
207
+ - DATABASE_DEPENDENCY_PORT=5432
208
+ - image: circleci/postgres:9.6
209
+ environment:
210
+ - POSTGRES_USER=postgres
211
+ - POSTGRES_DB=statesman_test
212
+ steps: *steps
141
213
  build-ruby233-rails-429-mongo:
142
214
  docker:
143
215
  - image: circleci/ruby:2.3.3-node
@@ -368,6 +440,12 @@ workflows:
368
440
  - build-ruby241-rails-513-mongo
369
441
  - build-ruby241-rails-513-mysql
370
442
  - build-ruby241-rails-513-postgres
443
+ - build-ruby241-rails-523-mongo
444
+ - build-ruby241-rails-523-mysql
445
+ - build-ruby241-rails-523-postgres
446
+ - build-ruby262-rails-600-mongo
447
+ - build-ruby262-rails-600-mysql
448
+ - build-ruby262-rails-600-postgres
371
449
  - build-ruby233-rails-429-mongo
372
450
  - build-ruby233-rails-429-mysql
373
451
  - build-ruby233-rails-429-postgres
@@ -1,3 +1,7 @@
1
+ ## v4.1.0, 10 April 2019
2
+
3
+ - Add better support for mysql (and others) in `transition_conflict_error?` [@greysteil](https://github.com/greysteil) (https://github.com/gocardless/statesman/pull/342)
4
+
1
5
  ## v4.0.0, 22 February 2019
2
6
 
3
7
  - Forces Statesman to use a new transactions with `requires_new: true` (https://github.com/gocardless/statesman/pull/249)
@@ -93,7 +93,7 @@ module Statesman
93
93
  end
94
94
 
95
95
  def transitions_for_parent
96
- @parent_model.send(@association_name)
96
+ parent_model.send(@association_name)
97
97
  end
98
98
 
99
99
  def unset_old_most_recent
@@ -128,10 +128,44 @@ module Statesman
128
128
  end
129
129
 
130
130
  def transition_conflict_error?(err)
131
- err.message.include?(@transition_class.table_name) &&
131
+ return true if unique_indexes.any? { |i| err.message.include?(i.name) }
132
+
133
+ err.message.include?(transition_class.table_name) &&
132
134
  (err.message.include?("sort_key") || err.message.include?("most_recent"))
133
135
  end
134
136
 
137
+ def unique_indexes
138
+ ::ActiveRecord::Base.connection.
139
+ indexes(transition_class.table_name).
140
+ select do |index|
141
+ next unless index.unique
142
+
143
+ index.columns.sort == [parent_join_foreign_key, "sort_key"] ||
144
+ index.columns.sort == [parent_join_foreign_key, "most_recent"]
145
+ end
146
+ end
147
+
148
+ def parent_join_foreign_key
149
+ association =
150
+ parent_model.class.
151
+ reflect_on_all_associations(:has_many).
152
+ find { |r| r.name.to_s == @association_name.to_s }
153
+
154
+ association_join_primary_key(association)
155
+ end
156
+
157
+ def association_join_primary_key(association)
158
+ if association.respond_to?(:join_primary_key)
159
+ association.join_primary_key
160
+ elsif association.method(:join_keys).arity.zero?
161
+ # Support for Rails 5.1
162
+ association.join_keys.key
163
+ else
164
+ # Support for Rails < 5.1
165
+ association.join_keys(transition_class).key
166
+ end
167
+ end
168
+
135
169
  def with_updated_timestamp(params)
136
170
  # TODO: Once we've set expectations that transition classes should conform to
137
171
  # the interface of Adapters::ActiveRecordTransition as a breaking change in the
@@ -140,8 +174,8 @@ module Statesman
140
174
  #
141
175
  # At the moment, most transition classes will include the module, but not all,
142
176
  # not least because it doesn't work with PostgreSQL JSON columns for metadata.
143
- column = if @transition_class.respond_to?(:updated_timestamp_column)
144
- @transition_class.updated_timestamp_column
177
+ column = if transition_class.respond_to?(:updated_timestamp_column)
178
+ transition_class.updated_timestamp_column
145
179
  else
146
180
  ActiveRecordTransition::DEFAULT_UPDATED_TIMESTAMP_COLUMN
147
181
  end
@@ -1,3 +1,3 @@
1
1
  module Statesman
2
- VERSION = "4.0.0".freeze
2
+ VERSION = "4.1.0".freeze
3
3
  end
@@ -94,14 +94,12 @@ class CreateMyActiveRecordModelTransitionMigration < MIGRATION_CLASS
94
94
  %i[my_active_record_model_id most_recent],
95
95
  unique: true,
96
96
  where: "most_recent",
97
- name: "index_my_active_record_model_transitions_"\
98
- "parent_most_recent"
97
+ name: "index_my_active_record_model_transitions_parent_latest"
99
98
  else
100
99
  add_index :my_active_record_model_transitions,
101
100
  %i[my_active_record_model_id most_recent],
102
101
  unique: true,
103
- name: "index_my_active_record_model_transitions_"\
104
- "parent_most_recent"
102
+ name: "index_my_active_record_model_transitions_parent_latest"
105
103
  end
106
104
  end
107
105
  end
@@ -173,13 +171,13 @@ class CreateOtherActiveRecordModelTransitionMigration < MIGRATION_CLASS
173
171
  unique: true,
174
172
  where: "most_recent",
175
173
  name: "index_other_active_record_model_transitions_"\
176
- "parent_most_recent"
174
+ "parent_latest"
177
175
  else
178
176
  add_index :other_active_record_model_transitions,
179
177
  %i[other_active_record_model_id most_recent],
180
178
  unique: true,
181
179
  name: "index_other_active_record_model_transitions_"\
182
- "parent_most_recent"
180
+ "parent_latest"
183
181
  end
184
182
  end
185
183
  end
@@ -188,8 +186,7 @@ end
188
186
  class DropMostRecentColumn < MIGRATION_CLASS
189
187
  def change
190
188
  remove_index :my_active_record_model_transitions,
191
- name: "index_my_active_record_model_transitions_"\
192
- "parent_most_recent"
189
+ name: "index_my_active_record_model_transitions_parent_latest"
193
190
  remove_column :my_active_record_model_transitions, :most_recent
194
191
  end
195
192
  end
@@ -270,14 +267,12 @@ class CreateNamespacedARModelTransitionMigration < MIGRATION_CLASS
270
267
  %i[my_active_record_model_id most_recent],
271
268
  unique: true,
272
269
  where: "most_recent",
273
- name: "index_namespace_model_transitions_"\
274
- "parent_most_recent"
270
+ name: "index_namespace_model_transitions_parent_latest"
275
271
  else
276
272
  add_index :my_namespace_my_active_record_model_transitions,
277
273
  %i[my_active_record_model_id most_recent],
278
274
  unique: true,
279
- name: "index_namespace_model_transitions_"\
280
- "parent_most_recent"
275
+ name: "index_namespace_model_transitions_parent_latest"
281
276
  end
282
277
  end
283
278
  # rubocop:enable MethodLength
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "ammeter", "~> 1.1"
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "gc_ruboconfig", "~> 2.3.9"
25
- spec.add_development_dependency "mysql2", "~> 0.4.0"
25
+ spec.add_development_dependency "mysql2", ">= 0.4", "< 0.6"
26
26
  spec.add_development_dependency "pg", "~> 0.18"
27
27
  spec.add_development_dependency "pry"
28
28
  spec.add_development_dependency "rails", ">= 3.2"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statesman
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-22 00:00:00.000000000 Z
11
+ date: 2019-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ammeter
@@ -56,16 +56,22 @@ dependencies:
56
56
  name: mysql2
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.4.0
61
+ version: '0.4'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '0.6'
62
65
  type: :development
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
- - - "~>"
69
+ - - ">="
67
70
  - !ruby/object:Gem::Version
68
- version: 0.4.0
71
+ version: '0.4'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.6'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: pg
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -292,8 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
298
  - !ruby/object:Gem::Version
293
299
  version: '0'
294
300
  requirements: []
295
- rubyforge_project:
296
- rubygems_version: 2.6.14
301
+ rubygems_version: 3.0.1
297
302
  signing_key:
298
303
  specification_version: 4
299
304
  summary: A statesman-like state machine library