occams-record 1.1.4 → 1.1.5

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
  SHA256:
3
- metadata.gz: 4c5eba9d662af4ceea78d6d50d9649dc88faebb18ab8f2d9e0704f4fe5367985
4
- data.tar.gz: cd5aa76eeb6a5f89ed65bd10549e468173dc2f8aa896346925b4b3752cf7858e
3
+ metadata.gz: 216f5b9aff38034e5bcaab036d4a5a20add7053062546eb827bd12269d49c766
4
+ data.tar.gz: f481e52c6d3390b7a3f5aa7497ac15d78774ef93f5d295dca472c75f558db9d2
5
5
  SHA512:
6
- metadata.gz: d48d4389624f627302877ca6bcda1e7b1dc19facd4b54b4d255bb11b75d1f79149c1e79aff271b715eca0f43e03819e5aaaebc2897a7b0b29696eb20e0bcc4fc
7
- data.tar.gz: ab8fdfddb10f751aa74274efc6229e5c24d32ec968fe8c88f30fd9af760652d9a75a2cc2bc17c29e3afcdd41b2d6f78e7cda60d485b6844458267beda2839aa2
6
+ metadata.gz: ee45536cbf4ea6a317647e73ac30788416bebfb3b152350fdcb4ab7d6e6e747ef1eb1763ef2aec731e11a9fb5925a8b234787933418c8c74f0724dd3b1ee1b9e
7
+ data.tar.gz: 30ab20cdd8611e0fec40a7a2e1b3d516ac153a5d283a393860650588c2d6f1bc93f02c43f125bb1675824ef019a29e276a05e0900899e311b838eab87a186db4
data/README.md CHANGED
@@ -297,15 +297,25 @@ bundle install
297
297
  bundle exec rake test
298
298
  ```
299
299
 
300
+ **Specify ActiveRecord version**
301
+
300
302
  By default, bundler will install the latest (supported) version of ActiveRecord. To specify a version to test against, run:
301
303
 
302
304
  ```bash
303
305
  AR=5.2 bundle update activerecord
304
- bundle exec rake test
306
+ AR=5.2 bundle exec rake test
305
307
  ```
306
308
 
307
309
  Look inside `Gemfile` to see all testable versions.
308
310
 
311
+ **Run against Postgres**
312
+
313
+ By default the tests run against an in-memory Sqlite3 database. Use the following env var to force running against a Postgres database:
314
+
315
+ ```bash
316
+ TEST_DATABASE_URL=postgres://postgres@localhost:5432/occams_record bundle exec rake test
317
+ ```
318
+
309
319
  # License
310
320
 
311
321
  MIT License. See LICENSE for details.
@@ -7,8 +7,9 @@ module OccamsRecord
7
7
  # Load records in batches of N and yield each record to a block if given. If no block is given,
8
8
  # returns an Enumerator.
9
9
  #
10
- # NOTE Unlike ActiveRecord's find_each, ORDER BY is respected. It will be run inside
11
- # of a transaction to ensure batch integrity.
10
+ # NOTE Unlike ActiveRecord's find_each, ORDER BY is respected. The primary key will be appended
11
+ # to the ORDER BY clause to help ensure consistent batches. Additionally, it will be run inside
12
+ # of a transaction.
12
13
  #
13
14
  # @param batch_size [Integer]
14
15
  # @param use_transaction [Boolean] Ensure it runs inside of a database transaction
@@ -80,10 +81,15 @@ module OccamsRecord
80
81
 
81
82
  offset = scope.offset_value || 0
82
83
  out_of_records, count = false, 0
84
+ pkey_regex = /#{model.primary_key}|\*/ # NOTE imperfect
85
+ order_by_pkey = !!model.primary_key &&
86
+ (scope.select_values.empty? || scope.select_values.any? { |v| v.to_s =~ pkey_regex })
83
87
 
84
88
  until out_of_records
85
89
  l = limit && batch_size > limit - count ? limit - count : batch_size
86
- q = scope.offset(offset).limit(l)
90
+ q = scope
91
+ q = q.order(model.primary_key.to_sym) if order_by_pkey
92
+ q = q.offset(offset).limit(l)
87
93
  results = Query.new(q, use: @use, query_logger: @query_logger, eager_loaders: @eager_loaders).run
88
94
 
89
95
  y.yield results if results.any?
@@ -20,6 +20,7 @@ module OccamsRecord
20
20
  raise MissingColumnError.new(row, e.name)
21
21
  end
22
22
  }.compact.uniq
23
+ ids.sort! if $occams_record_test
23
24
 
24
25
  q = base_scope.where(@ref.association_primary_key => ids)
25
26
  yield q if ids.any?
@@ -20,6 +20,7 @@ module OccamsRecord
20
20
  raise MissingColumnError.new(row, e.name)
21
21
  end
22
22
  }.compact.uniq
23
+ ids.sort! if $occams_record_test
23
24
 
24
25
  q = base_scope.where(@ref.foreign_key => ids)
25
26
  q.where!(@ref.type => rows[0].class&.model_name) if @ref.options[:as]
@@ -55,6 +55,7 @@ module OccamsRecord
55
55
  next if type.nil? or type == ""
56
56
  model = type.constantize
57
57
  ids = rows_of_type.map(&@foreign_key).uniq
58
+ ids.sort! if $occams_record_test
58
59
  q = base_scope(model).where(@ref.active_record_primary_key => ids)
59
60
  yield q if ids.any?
60
61
  end
@@ -3,5 +3,5 @@
3
3
  #
4
4
  module OccamsRecord
5
5
  # Library version
6
- VERSION = "1.1.4".freeze
6
+ VERSION = "1.1.5".freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occams-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-17 00:00:00.000000000 Z
11
+ date: 2020-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -81,8 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.7.6.2
84
+ rubygems_version: 3.0.3
86
85
  signing_key:
87
86
  specification_version: 4
88
87
  summary: The missing high-efficiency query API for ActiveRecord