nexus_seed 0.2.20 → 0.2.22

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: 73e46e94919f9d390f747f4390ffaccb47fb612627ea3a284db978746e5639b6
4
+ data.tar.gz: 0c93de072aea4dc408fe747c8606d11ec887aa39a239526d6696d6fbdc70093f
5
5
  SHA512:
6
- metadata.gz: bf765a0ee96662b85a0dbdf3d600a7935151cf1cde47adba7138a8b3b41dece0cf6b13284b18a9d39db5766038e6d50090ef3758f8b18c7c2bea61e3d42cc2c5
7
- data.tar.gz: 15025c9157a7342da084057b0699dae0a579c8414c5b674dacd9df6e45cbf26235c3ed945081b9e618709df0b24550e171a441d26fbfdb059b632f3ef6cd667c
6
+ metadata.gz: e615bf54f07064188f85b321d9a998692019bd793ab9181023a83a465f8719297f7185a8f5063254e8e0e077db4afc8e3cec5ac4b7c8f6f47ce5a007fc554244
7
+ data.tar.gz: a088230aa3f24b39460dd5d1168bcc0754a497e9638587ae9f0523456482e558ff1a014a9499badfb60176bf79d812fc20cd46b7f197190de4db90e2170d81c3
@@ -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
+ # Sync the ActiveRecord PK sequence e.g. if you know that records with specific IDs were inserted. Note it is
27
+ # dangerous to call this for all tables when concurrent updates are happening, you must specify the table.
28
+ def self.activerecord_sync_pk_sequence(table_name)
29
+ table_seq = ActiveRecord::Base.connection.pk_and_sequence_for(table_name)
30
+ next unless table_seq
31
+ seq_id = table_seq[1].identifier
32
+ seq_value = ActiveRecord::Base.connection.execute("SELECT last_value from #{seq_id}")[0]['last_value']
33
+ reset_seq_value = ActiveRecord::Base.connection.reset_pk_sequence!(table_name)
34
+ if reset_seq_value != seq_value
35
+ logger.info('Reset sequence value.', value: reset_seq_value, sequence: seq_id, table: table_name)
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.22 in order for CI process to replace with the tagged version.
4
+ VERSION = '0.2.22'
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,11 @@ 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
+ seed
39
+ NexusSeed::Builder.seed_report
40
+
41
+ if ENV['NEXUS_SEED_DESTROY'] == 'true'
42
+ NexusSeed::Builder.destroy_seeds
41
43
  end
42
44
 
43
45
  elsif retries >= retry_limit && retry_limit != 0
metadata CHANGED
@@ -1,14 +1,14 @@
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.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnathon Harris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-16 00:00:00.000000000 Z
11
+ date: 2023-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nexus_semantic_logger
@@ -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