chewy 7.3.2 → 7.3.4

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: 4fce5e949350a7256e302f88e4f085e186b41b947944bfca3278bc6b63d308f7
4
- data.tar.gz: 1454ca0cb5550ce118de31b37bbd05dca8c7c0a07c0cc78cd75552e6fbcead30
3
+ metadata.gz: 2ccc78d2b2639947fa81151db668c7a733a046335332d37bf0d45fd5dbe8d7c6
4
+ data.tar.gz: 7a4daeb15073d05116d154ca5f19d7f8d43a2926f85f2890c47e3fa20cc243de
5
5
  SHA512:
6
- metadata.gz: c4ec988d938d54bcb934007bf43d1f6035c474b425718cc3ad38e092aebc46213da79e911d8bd8861fa3af8fa36200d4e05b351cb01b6f647aac36a172123b39
7
- data.tar.gz: 674648b1ace4d6f72d54a1e4efdc5984e49b270da1a89e52cf42f6b8b4f539a9e55f6ca5e9970ac494208f67b970cc0c280241d560067f79c238ffce5ad680f4
6
+ metadata.gz: f55f69638f9618445b047409a018a284f0cb0ec648e71eede51065b274f1d9b86e70dbf090c8d5efd174e7d74e231f7541b59820ad7cffdb1c829ddf0b6688f6
7
+ data.tar.gz: c23c190126a842f5d0fc87990a7424aed90e1794e5ad0442f017b56f98c84e30e502189364b19da3ad40b2271e491dec04f53828b9e05fe9e82cef34ded63438
data/CHANGELOG.md CHANGED
@@ -8,6 +8,26 @@
8
8
 
9
9
  ### Bugs Fixed
10
10
 
11
+ ## 7.3.4 (2023-08-29)
12
+
13
+ ### New Features
14
+
15
+ * [#888](https://github.com/toptal/chewy/pull/892): Rake task to create missing indexes ([@konalegi](https://github.com/konalegi))
16
+
17
+ ### Changes
18
+
19
+ ### Bugs Fixed
20
+
21
+ ## 7.3.3 (2023-07-07)
22
+
23
+ ### New Features
24
+
25
+ * [#888](https://github.com/toptal/chewy/pull/888/files): Skip journal creation on import ([@konalegi](https://github.com/konalegi))
26
+
27
+ ### Changes
28
+
29
+ ### Bugs Fixed
30
+
11
31
  ## 7.3.2 (2023-04-20)
12
32
 
13
33
  ### New Features
data/README.md CHANGED
@@ -1197,6 +1197,10 @@ Right now the approach is that if some data had been updated, but index definiti
1197
1197
 
1198
1198
  Also, there is always full reset alternative with `rake chewy:reset`.
1199
1199
 
1200
+ #### `chewy:create_missing_indexes`
1201
+
1202
+ This rake task creates newly defined indexes in ElasticSearch and skips existing ones. Useful for production-like environments.
1203
+
1200
1204
  #### Parallelizing rake tasks
1201
1205
 
1202
1206
  Every task described above has its own parallel version. Every parallel rake task takes the number for processes for execution as the first argument and the rest of the arguments are exactly the same as for the non-parallel task version.
@@ -64,7 +64,7 @@ module Chewy
64
64
  # Creates the journal index and the corresponding index if necessary.
65
65
  # @return [Object] whatever
66
66
  def create_indexes!
67
- Chewy::Stash::Journal.create if @options[:journal]
67
+ Chewy::Stash::Journal.create if @options[:journal] && !Chewy.configuration[:skip_journal_creation_on_import]
68
68
  return if Chewy.configuration[:skip_index_creation_on_import]
69
69
 
70
70
  @index.create!(**@bulk_options.slice(:suffix)) unless @index.exists?
@@ -197,6 +197,19 @@ module Chewy
197
197
  end
198
198
  end
199
199
 
200
+ # Creates journal index.
201
+ #
202
+ # @example
203
+ # Chewy::RakeHelper.journal_create # creates journal
204
+ #
205
+ # @param output [IO] output io for logging
206
+ # @return Chewy::Index Returns instance of chewy index
207
+ def journal_create(output: $stdout)
208
+ subscribed_task_stats(output) do
209
+ Chewy::Stash::Journal.create!
210
+ end
211
+ end
212
+
200
213
  # Eager loads and returns all the indexes defined in the application
201
214
  # except Chewy::Stash::Specification and Chewy::Stash::Journal.
202
215
  #
@@ -255,6 +268,24 @@ module Chewy
255
268
  end
256
269
  end
257
270
 
271
+ def create_missing_indexes!(output: $stdout, env: ENV)
272
+ subscribed_task_stats(output) do
273
+ Chewy.eager_load!
274
+ all_indexes = Chewy::Index.descendants
275
+ all_indexes -= [Chewy::Stash::Journal] unless Chewy.configuration[:journal]
276
+ all_indexes.each do |index|
277
+ if index.exists?
278
+ output.puts "#{index.name} already exists, skipping" if env['VERBOSE']
279
+ next
280
+ end
281
+
282
+ index.create!
283
+
284
+ output.puts "#{index.name} index successfully created"
285
+ end
286
+ end
287
+ end
288
+
258
289
  def normalize_indexes(*identifiers)
259
290
  identifiers.flatten(1).map { |identifier| normalize_index(identifier) }
260
291
  end
data/lib/chewy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chewy
2
- VERSION = '7.3.2'.freeze
2
+ VERSION = '7.3.4'.freeze
3
3
  end
data/lib/tasks/chewy.rake CHANGED
@@ -57,6 +57,11 @@ namespace :chewy do
57
57
  Chewy::RakeHelper.update_mapping(name: args[:index_name])
58
58
  end
59
59
 
60
+ desc 'Creates missing indexes'
61
+ task create_missing_indexes: :environment do
62
+ Chewy::RakeHelper.create_missing_indexes!
63
+ end
64
+
60
65
  namespace :parallel do
61
66
  desc 'Parallel version of `rake chewy:reset`'
62
67
  task reset: :environment do |_task, args|
@@ -87,6 +92,11 @@ namespace :chewy do
87
92
  end
88
93
 
89
94
  namespace :journal do
95
+ desc 'Create manually journal, useful when `skip_journal_creation_on_import` is used'
96
+ task create: :environment do |_task, _args|
97
+ Chewy::RakeHelper.journal_create
98
+ end
99
+
90
100
  desc 'Applies changes that were done after the specified time for the specified indexes/types or all of them'
91
101
  task apply: :environment do |_task, args|
92
102
  Chewy::RakeHelper.journal_apply(**parse_journal_args(args.extras))
@@ -60,6 +60,19 @@ describe Chewy::Index::Import do
60
60
  CitiesIndex.import(dummy_city)
61
61
  end
62
62
  end
63
+
64
+ context 'skip journal creation on import' do
65
+ before do
66
+ Chewy::Stash::Journal.create!
67
+ Chewy.config.settings[:skip_journal_creation_on_import] = true
68
+ end
69
+ after { Chewy.config.settings[:skip_journal_creation_on_import] = nil }
70
+
71
+ specify do
72
+ expect(Chewy::Stash::Journal).not_to receive(:create!)
73
+ CitiesIndex.import(dummy_city, journal: true)
74
+ end
75
+ end
63
76
  end
64
77
 
65
78
  shared_examples 'importing' do
@@ -470,6 +470,70 @@ Total: \\d+s\\Z
470
470
  end
471
471
  end
472
472
 
473
+ describe '.create_missing_indexes!' do
474
+ before do
475
+ [CountriesIndex, Chewy::Stash::Specification].map(&:create!)
476
+
477
+ # To avoid flaky issues when previous specs were run
478
+ expect(Chewy::Index).to receive(:descendants).and_return(
479
+ [
480
+ UsersIndex,
481
+ CountriesIndex,
482
+ CitiesIndex,
483
+ Chewy::Stash::Specification,
484
+ Chewy::Stash::Journal
485
+ ]
486
+ )
487
+ end
488
+
489
+ specify do
490
+ output = StringIO.new
491
+ described_class.create_missing_indexes!(output: output)
492
+ expect(CitiesIndex.exists?).to be_truthy
493
+ expect(UsersIndex.exists?).to be_truthy
494
+ expect(Chewy::Stash::Journal.exists?).to be_falsey
495
+ expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
496
+ UsersIndex index successfully created
497
+ CitiesIndex index successfully created
498
+ Total: \\d+s\\Z
499
+ OUTPUT
500
+ end
501
+
502
+ context 'when verbose' do
503
+ specify do
504
+ output = StringIO.new
505
+ described_class.create_missing_indexes!(output: output, env: {'VERBOSE' => '1'})
506
+ expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
507
+ UsersIndex index successfully created
508
+ CountriesIndex already exists, skipping
509
+ CitiesIndex index successfully created
510
+ Chewy::Stash::Specification already exists, skipping
511
+ Total: \\d+s\\Z
512
+ OUTPUT
513
+ end
514
+ end
515
+
516
+ context 'when journaling is enabled' do
517
+ before { Chewy.config.settings[:journal] = true }
518
+ after { Chewy.config.settings.delete(:journal) }
519
+ specify do
520
+ described_class.create_missing_indexes!(output: StringIO.new)
521
+ expect(Chewy::Stash::Journal.exists?).to be_truthy
522
+ end
523
+ end
524
+ end
525
+
526
+ describe '.journal_create' do
527
+ specify do
528
+ output = StringIO.new
529
+ described_class.journal_create(output: output)
530
+ expect(Chewy::Stash::Journal.exists?).to be_truthy
531
+ expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
532
+ Total: \\d+s\\Z
533
+ OUTPUT
534
+ end
535
+ end
536
+
473
537
  describe '.reindex' do
474
538
  before do
475
539
  journal
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chewy
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.2
4
+ version: 7.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toptal, LLC
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-21 00:00:00.000000000 Z
12
+ date: 2023-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: database_cleaner
@@ -482,7 +482,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
482
482
  - !ruby/object:Gem::Version
483
483
  version: '0'
484
484
  requirements: []
485
- rubygems_version: 3.3.26
485
+ rubygems_version: 3.4.10
486
486
  signing_key:
487
487
  specification_version: 4
488
488
  summary: Elasticsearch ODM client wrapper