nexus_seed 0.2.20 → 0.2.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nexus_seed/builder.rb +13 -0
- data/lib/nexus_seed/version.rb +2 -2
- data/lib/nexus_seed.rb +5 -3
- metadata +2 -3
- data/lib/nexus_seed/base.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73e46e94919f9d390f747f4390ffaccb47fb612627ea3a284db978746e5639b6
|
4
|
+
data.tar.gz: 0c93de072aea4dc408fe747c8606d11ec887aa39a239526d6696d6fbdc70093f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e615bf54f07064188f85b321d9a998692019bd793ab9181023a83a465f8719297f7185a8f5063254e8e0e077db4afc8e3cec5ac4b7c8f6f47ce5a007fc554244
|
7
|
+
data.tar.gz: a088230aa3f24b39460dd5d1168bcc0754a497e9638587ae9f0523456482e558ff1a014a9499badfb60176bf79d812fc20cd46b7f197190de4db90e2170d81c3
|
data/lib/nexus_seed/builder.rb
CHANGED
@@ -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
|
data/lib/nexus_seed/version.rb
CHANGED
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
|
-
|
40
|
-
|
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.
|
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-
|
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
|
data/lib/nexus_seed/base.rb
DELETED
@@ -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
|