nexus_seed 0.2.20 → 0.2.21

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 036bc1fce3d2c07ca3c31e92fdcd20b6905e5ffd5bc29993236b3dcbbded5071
4
- data.tar.gz: aa42cc60f7e2e19e88897a0c5ffc185f7d1c094308039946dedab5f9e88113fe
3
+ metadata.gz: 3fe2b060a2b53d791dca15ad60703e1c27806de473696ee8e8188fbe922ffcc1
4
+ data.tar.gz: 03e128238d5ad9e251e7ba4e1144f01d1c0e03643b0f40796695411258b3194c
5
5
  SHA512:
6
- metadata.gz: bf765a0ee96662b85a0dbdf3d600a7935151cf1cde47adba7138a8b3b41dece0cf6b13284b18a9d39db5766038e6d50090ef3758f8b18c7c2bea61e3d42cc2c5
7
- data.tar.gz: 15025c9157a7342da084057b0699dae0a579c8414c5b674dacd9df6e45cbf26235c3ed945081b9e618709df0b24550e171a441d26fbfdb059b632f3ef6cd667c
6
+ metadata.gz: ce2fbccb73e0ad77c77266ae129be9f7f35b1c484223f83c208e15f7f74ee4d22e8f0e9dca5162df0fbb73b893460c9029e7935a094f7ff11ff99fa1ff6a6ec9
7
+ data.tar.gz: d4dbb7a83c22a14bbfd15f92e33319bd15ae30d19d744b289a8849239f80def07710cd6431739ac30f6691b5541eb688104ce61bbfad12e459a5c25caaa6e65a
@@ -23,6 +23,19 @@ module NexusSeed
23
23
  "NexusSeed::Builders::#{class_name.to_s.camelcase}Builder".constantize.new(options).build(params)
24
24
  end
25
25
 
26
+ def self.activerecord_sync_sequences
27
+ ActiveRecord::Base.connection.tables.each do |table_name|
28
+ table_seq = ActiveRecord::Base.connection.pk_and_sequence_for(table_name)
29
+ next unless table_seq
30
+ seq_id = table_seq[1].identifier
31
+ seq_value = ActiveRecord::Base.connection.execute("SELECT last_value from #{seq_id}")[0]['last_value']
32
+ reset_seq_value = ActiveRecord::Base.connection.reset_pk_sequence!(table_name)
33
+ if reset_seq_value != seq_value
34
+ logger.info('Reset sequence value.', value: reset_seq_value, sequence: seq_id, table: table_name)
35
+ end
36
+ end
37
+ end
38
+
26
39
  def self.seed_report
27
40
  if ENV['NEXUS_SEED_REPORT'] == 'true'
28
41
  total = 0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusSeed
3
- # Leave this as 0.2.20 in order for CI process to replace with the tagged version.
4
- VERSION = '0.2.20'
3
+ # Leave this as 0.2.21 in order for CI process to replace with the tagged version.
4
+ VERSION = '0.2.21'
5
5
  end
data/lib/nexus_seed.rb CHANGED
@@ -3,7 +3,6 @@ require 'nexus_seed'
3
3
  require 'nexus_seed/builder/base'
4
4
  Dir["/app/db/nexus_seed/builders/*.rb"].each { |file| require file }
5
5
  require 'nexus_seed/builder'
6
- require 'nexus_seed/base'
7
6
 
8
7
  module NexusSeed
9
8
  # defaults
@@ -36,8 +35,15 @@ module NexusSeed
36
35
 
37
36
  logger.info("Starting run attempt #{retries + 1}")
38
37
  if _try_requires
39
- NexusSeed::Base.transaction do
40
- seed
38
+ # Sync sequences before and after in case any manual ID changes have been made.
39
+ NexusSeed::Builder.activerecord_sync_sequences
40
+ seed
41
+ NexusSeed::Builder.activerecord_sync_sequences
42
+ NexusSeed::Builder.seed_report
43
+
44
+ if ENV['NEXUS_SEED_DESTROY'] == 'true'
45
+ NexusSeed::Builder.destroy_seeds
46
+ NexusSeed::Builder.activerecord_sync_sequences
41
47
  end
42
48
 
43
49
  elsif retries >= retry_limit && retry_limit != 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_seed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.20
4
+ version: 0.2.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnathon Harris
@@ -37,7 +37,6 @@ files:
37
37
  - README.md
38
38
  - SEED_BUILDER.md
39
39
  - lib/nexus_seed.rb
40
- - lib/nexus_seed/base.rb
41
40
  - lib/nexus_seed/builder.rb
42
41
  - lib/nexus_seed/builder/base.rb
43
42
  - lib/nexus_seed/version.rb
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
- module NexusSeed
3
- class Base < ActiveRecord::Base
4
- def self.transaction(**options, &block)
5
- # Reset table sequences. Apparently rails loses track of a pk sequence if the pk value is inserted manually, e.g
6
- # User.new(id: 1).save. When subsequently running User.create(), ActiveRecord should increment the id value to 2
7
- # by default, but turns out it will try to insert id: 1 again which will result in an error.
8
- #
9
- # @todo This "fix" is not ideal and will require more investigation.
10
- ActiveRecord::Base.connection.tables.each do |t|
11
- ActiveRecord::Base.connection.reset_pk_sequence!(t)
12
- end
13
-
14
- super
15
-
16
- NexusSeed::Builder.seed_report
17
-
18
- if ENV['NEXUS_SEED_DESTROY'] == 'true'
19
- NexusSeed::Builder.destroy_seeds
20
- end
21
- end
22
- end
23
- end