dbagent 3.2.1 → 3.3.0

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: 83e62569d42b3c020a5aadedf966a8508fa32fe657a07adffe0dc712e36344c5
4
- data.tar.gz: 31c24c2bb2b5888846dd8bbeb2f17eddcf40894439df568188335bfd1abc342d
3
+ metadata.gz: eb16765f4f64bec5eff152e6db516bb5b672348a1b909229ce46e024b37132ab
4
+ data.tar.gz: 48b7d28235340c73b316aabba304a20ccf854cdea919eecca1c7f19b1f594487
5
5
  SHA512:
6
- metadata.gz: 74994c047b77abceff18643b9dc5f48fb15a0ebb44afec1c53064396ea11418cc887e2ba7095de676f44c35269a33c33e93b0a041c179d61ed65b1ee6cd50a2f
7
- data.tar.gz: 26c54890973d3553c358c9d848e6abc16b36a52d09bcb3f31d163881a8efee2debe73686331c7fd0c328cac8d0f354faa335db6a638c1234e51f6bec1c99e67b
6
+ metadata.gz: 61ee06b3ca6734ed61889878e2806eaa5774d08cd864b3ca2a1b90acaf22d505d830fbfb01b96c50340e2c1b27462e658efe2a7db54a2e4243873f912ddb3762
7
+ data.tar.gz: 786ada66e5e8ea0e584e8ef61a36f71134df08fca60b50b3da6fd35e06db76c904c2814db1b2f21a3beb921485983840cd8a34b218dd558e23e0ce839f724f47
@@ -18,11 +18,13 @@ module DbAgent
18
18
  pairs[p1].basename <=> pairs[p2].basename
19
19
  }
20
20
 
21
- # Truncate tables then fill them
21
+ # Truncate tables
22
22
  names.reverse.each do |name|
23
23
  LOGGER.info("Emptying table `#{name}`")
24
24
  handler.sequel_db[name.to_sym].delete
25
25
  end
26
+
27
+ # Fill them
26
28
  names.each do |name|
27
29
  LOGGER.info("Filling table `#{name}`")
28
30
  file = pairs[name]
@@ -33,6 +35,29 @@ module DbAgent
33
35
  end
34
36
  end
35
37
 
38
+ def insert_script(from)
39
+ folder = handler.data_folder/from
40
+
41
+ # load files in order
42
+ pairs = merged_data(from)
43
+ names = pairs.keys.sort{|p1,p2|
44
+ pairs[p1].basename <=> pairs[p2].basename
45
+ }
46
+
47
+ # Fill them
48
+ names.each do |name|
49
+ file = pairs[name]
50
+ data = file.load
51
+ next if data.empty?
52
+
53
+ keys = data.first.keys
54
+ values = data.map{|t|
55
+ keys.map{|k| t[k] }
56
+ }
57
+ puts handler.sequel_db[name.to_sym].multi_insert_sql(keys, values)
58
+ end
59
+ end
60
+
36
61
  def flush_empty(to = "empty")
37
62
  target = (handler.data_folder/to).rm_rf.mkdir_p
38
63
  (target/"metadata.json").write <<-JSON.strip
@@ -1,6 +1,6 @@
1
1
  module DbAgent
2
2
 
3
3
  # Current version of DbAgent
4
- VERSION = "3.2.1"
4
+ VERSION = "3.3.0"
5
5
 
6
6
  end
data/tasks/db.rake CHANGED
@@ -81,6 +81,12 @@ namespace :db do
81
81
  end
82
82
  task :seed => :require
83
83
 
84
+ desc "Prints an INSERT script for a particular data set"
85
+ task :insert_script, :from do |t,args|
86
+ Seeder.new(db_handler).insert_script(args[:from] || 'empty')
87
+ end
88
+ task :insert_script => :require
89
+
84
90
  desc "Flushes the database as a particular data set"
85
91
  task :flush, :to do |t,args|
86
92
  Seeder.new(db_handler).flush(args[:to] || Time.now.strftime("%Y%M%d%H%M%S").to_s)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-13 00:00:00.000000000 Z
11
+ date: 2023-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  - !ruby/object:Gem::Version
230
230
  version: '0'
231
231
  requirements: []
232
- rubygems_version: 3.1.4
232
+ rubygems_version: 3.1.6
233
233
  signing_key:
234
234
  specification_version: 4
235
235
  summary: A tool to migrate, spy and seed relational databases.