dbagent 3.2.0 → 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: 55a5d65d0b652b002041aa6dd13f4c628f41e5a0467a5066d24943e8a20992e6
4
- data.tar.gz: f260eddc19e7680a0eb8f8b601002f28a28126e301356af63c90ab5528ce52ef
3
+ metadata.gz: eb16765f4f64bec5eff152e6db516bb5b672348a1b909229ce46e024b37132ab
4
+ data.tar.gz: 48b7d28235340c73b316aabba304a20ccf854cdea919eecca1c7f19b1f594487
5
5
  SHA512:
6
- metadata.gz: 9fa72a760b5632e1d8f14d1b98b0042b17e37085f1e7da1d40d2c8f933b180a758d34aeb3a795823e7468838203e00478283b5e33b778be0b93191b1f976d912
7
- data.tar.gz: f8ee68d78cd1e647a9f6d9df9361d2d4a27522c34c229f6fd434ae042da35ce6f838a051b0ec9d1b61385f134be6916889d2741f7837801eb1e71f454f071a0e
6
+ metadata.gz: 61ee06b3ca6734ed61889878e2806eaa5774d08cd864b3ca2a1b90acaf22d505d830fbfb01b96c50340e2c1b27462e658efe2a7db54a2e4243873f912ddb3762
7
+ data.tar.gz: 786ada66e5e8ea0e584e8ef61a36f71134df08fca60b50b3da6fd35e06db76c904c2814db1b2f21a3beb921485983840cd8a34b218dd558e23e0ce839f724f47
@@ -97,7 +97,7 @@ module DbAgent
97
97
  PostgreSQL.new(options)
98
98
  when 'mssql'
99
99
  MSSQL.new(options)
100
- when 'mysql'
100
+ when /mysql/
101
101
  MySQL.new(options)
102
102
  else
103
103
  PostgreSQL.new(options)
@@ -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.0"
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.0
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-06-17 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.